Created
May 13, 2012 14:57
-
-
Save nickcharlton/2688813 to your computer and use it in GitHub Desktop.
For Jekyll. Fixed to work with the new Less gem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Less to CSS converter for Jekyll. | |
# In your less file, add two lines of --- at the top. | |
# | |
module Jekyll | |
class LessConverter < Converter | |
safe true | |
priority :high | |
def setup | |
return if @setup | |
require 'less' | |
@setup = true | |
rescue LoadError | |
STDERR.puts 'You are missing the library required for less. Please run:' | |
STDERR.puts ' $ [sudo] gem install less' | |
raise FatalException.new("Missing dependency: less") | |
end | |
def matches(ext) | |
ext =~ /less|lcss/i | |
end | |
def output_ext(ext) | |
".css" | |
end | |
def convert(content) | |
setup | |
begin | |
parser = Less::Parser.new | |
tree = parser.parse(content) | |
tree.to_css(:compress => true) | |
rescue => e | |
puts "Less Exception: #{e.message}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment