public
Last active

A Jekyll plugin to convert a .less file to .css

  • Download Gist
less_converter.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
module Jekyll
# 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
Less::Engine.new(content).to_css
rescue => e
puts "Less Exception: #{e.message}"
end
end
end
end

Thanks for this gist. I am running into an issue where the converted files are all blank and im getting this "Less Exception: uninitialized constant Less::Engine" Any idea what's causing that? Is there anything else I need to do aside from including this plugin in the plugin directory and putting empty yaml fron matter in my less files?

Looks like Less::Engine doesn't exist with the Less gem.

I modified this gist to use Less::Parser.new and .parse

https://gist.github.com/KBalderson/5689220

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.