Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/jekyll-less.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<source>/_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
Expand Down