Skip to content

Instantly share code, notes, and snippets.

@tech4him1
Forked from andyfowler/lessjs.rb
Last active December 29, 2016 01:24
Show Gist options
  • Save tech4him1/b855c4ce1e33f70b1fdbe0c01c078280 to your computer and use it in GitHub Desktop.
Save tech4him1/b855c4ce1e33f70b1fdbe0c01c078280 to your computer and use it in GitHub Desktop.
Jekyll plugin to render LESS CSS
# encoding: utf-8
require 'jekyll/utils'
require 'open3'
# The official Node.JS `lessc` binary needs to be availible in the shell.
# `less_dir` defaults to `_less` but can be changed in `_config.yml`.
module Jekyll
class LessConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /less|lcss/i
end
def output_ext(ext)
".css"
end
def convert(content)
include_path = @config["less_dir"] || "_less"
begin
converted, status = Open3.capture2('lessc',
"--include-path=#{include_path}",
'-', # Use STDIN
:stdin_data=>content)
raise "LESS compilation error" if status.to_i != 0
return converted
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment