From 1bc4b3157d9bc7099ca1c9b02c0e34f38e269dc2 Mon Sep 17 00:00:00 2001 From: Denzel Morris Date: Mon, 28 Mar 2016 17:16:58 -0400 Subject: [PATCH 1/2] Support less_dir configuration option Jekyll's built-in Sass/SCSS (https://jekyllrb.com/docs/assets/#sassscss) allows the user to configure their import path with sass_dir. People using LESS would probably enjoy the same. So, a 'less_dir' configuration option has been added to the 'less' configuration block. Now users can specify any directory in their source directory for LESS imports to resolve in. --- lib/jekyll-less.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-less.rb b/lib/jekyll-less.rb index 61b3d57..dd9d4c0 100644 --- a/lib/jekyll-less.rb +++ b/lib/jekyll-less.rb @@ -6,6 +6,7 @@ module Less class LessCssFile < Jekyll::StaticFile attr_accessor :compress + attr_writer :import_path # Obtain destination path. # +dest+ is the String path to the destination dir @@ -15,6 +16,10 @@ def destination(dest) File.join(dest, @dir, @name.sub(/less$/, 'css')) end + def import_path + File.expand_path(@import_path, @base) + end + # Convert the less file into a css file. # +dest+ is the String path to the destination dir # @@ -28,7 +33,7 @@ def write(dest) FileUtils.mkdir_p(File.dirname(dest_path)) begin content = File.read(path) - content = ::Less::Parser.new({:paths => [File.dirname(path)]}).parse(content).to_css :compress => compress + content = ::Less::Parser.new({:paths => [import_path]}).parse(content).to_css :compress => compress File.open(dest_path, 'w') do |f| f.write(content) end @@ -46,7 +51,8 @@ class LessCssGenerator < Jekyll::Generator # Initialize options from site config. def initialize(config = {}) - @options = config["less"] ||= {"compress" => true} + @options = defaults + @options.merge!(config["less"]) if config["less"] end # Jekyll will have already added the *.less files as Jekyll::StaticFile @@ -61,10 +67,20 @@ def generate(site) less_file = LessCssFile.new(site, site.source, destination, name) less_file.compress = @options["compress"] + less_file.import_path = @options["less_dir"] site.static_files << less_file end end end + + private + + def defaults + { + "compress" => true, + "less_dir" => "_less" + } + end end end From 5904434486ce71bc0d6379db78c821c2579d8c9c Mon Sep 17 00:00:00 2001 From: Denzel Morris Date: Mon, 28 Mar 2016 17:31:55 -0400 Subject: [PATCH 2/2] Update README with less_dir config description --- readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/readme.md b/readme.md index b5b5efa..fb6688e 100644 --- a/readme.md +++ b/readme.md @@ -39,6 +39,15 @@ of the gems specified in your Gemfile. require "bundler/setup" Bundler.require(:default) +Configuration +------------- +You can customize where Less `@import` statements load files from with `less_dir` (which defaults to `/_less`). + +If you want to load imported files from another directory, add the following to `_config.yml`: + + less: + less_dir: _my_custom_less_dir/ + Credit ------ This gem was originally based on this [gist](https://gist.github.com/760265) by