-
-
Save tech4him1/b855c4ce1e33f70b1fdbe0c01c078280 to your computer and use it in GitHub Desktop.
Jekyll plugin to render LESS CSS
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
# 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