mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 09:46:12 +00:00
generate css from less using lessc
This commit is contained in:
parent
c4a8e4e904
commit
1b6b0b245f
12 changed files with 62 additions and 18 deletions
|
@ -16,8 +16,7 @@
|
|||
<script src="/lib/app.js"></script>
|
||||
|
||||
<!-- stylesheet -->
|
||||
<link rel="stylesheet/less" href="/lib/bootstrap.less">
|
||||
<script src="/lib/less.js"></script>
|
||||
{% lesscss bootstrap.less %}
|
||||
|
||||
<!-- fav and touch icons -->
|
||||
<link rel="shortcut icon" href="/favicon.ico">
|
||||
|
|
0
lib/bootstrap.less → _less/bootstrap.less
vendored
0
lib/bootstrap.less → _less/bootstrap.less
vendored
61
_plugins/less.rb
Normal file
61
_plugins/less.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require 'digest/md5'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class LessCSSFile < StaticFile
|
||||
def write(dest)
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
class LessCSS < Liquid::Tag
|
||||
def initialize(tag_name, file, tokens)
|
||||
super
|
||||
@file = file.strip
|
||||
end
|
||||
|
||||
def render(context)
|
||||
site = context.registers[:site]
|
||||
|
||||
less_dir = File.join(site.source, '_less')
|
||||
|
||||
if File.symlink?(less_dir)
|
||||
return "LessCSS directory '#{less_dir}' cannot be a symlink"
|
||||
end
|
||||
|
||||
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
|
||||
return "LessCSS file '#{@file}' contains invalid characters or sequences"
|
||||
end
|
||||
|
||||
Dir.chdir(less_dir) do
|
||||
choices = Dir['**/*'].reject { |x| File.symlink?(x) }
|
||||
if choices.include?(@file)
|
||||
source = File.read(@file)
|
||||
f = IO.popen("lessc", "w+")
|
||||
f.write(source)
|
||||
f.close_write()
|
||||
|
||||
css = f.readlines().join()
|
||||
|
||||
digest = Digest::MD5.hexdigest(css)
|
||||
|
||||
css_file = digest + ".css"
|
||||
css_path = File.join(site.dest, css_file)
|
||||
|
||||
File.open(css_path, "w") do |f|
|
||||
f.write(css)
|
||||
end
|
||||
|
||||
site.static_files << LessCSSFile.new(site, site.source, '', css_file)
|
||||
|
||||
'<link rel="stylesheet" type="text/css" href="/' + css_file + '" />'
|
||||
else
|
||||
return "LessCSS file '#{@file}' not found in '#{less_dir}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('lesscss', Jekyll::LessCSS)
|
16
lib/less.js
16
lib/less.js
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue