Skip to content

Instantly share code, notes, and snippets.

@ChrisSmith
Forked from jasongraham/less_converter.rb
Last active December 17, 2015 12:19
Show Gist options
  • Save ChrisSmith/5609369 to your computer and use it in GitHub Desktop.
Save ChrisSmith/5609369 to your computer and use it in GitHub Desktop.
module Jekyll
# https://gist.github.com/jasongraham/639920
# Compiled LESS CSS into CSS. You must specify an empty YAML front matter
# at the beginning of the file.
# .less -> .css
class LessConverter < Converter
safe true
priority :low
pygments_prefix "\n"
pygments_suffix "\n"
def setup
return if @setup
require 'less'
@setup = true
rescue LoadError
STDERR.puts 'You are missing a library required for less. Please run:'
STDERR.puts ' $ [sudo] gem install less'
raise FatalException.new("Missing dependency: less")
end
def matches(ext)
ext =~ /less/i
end
def output_ext(ext)
".css"
end
def convert(content)
setup
begin
parser = Less::Parser.new()
return parser.parse(content).to_css
rescue => e
puts "Less Exception: #{e.message}"
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment