class Jekyll::Assets::Processors::LESS
Public Class Methods
call(input)
click to toggle source
Setup and pull out the context and update the data, shipping it.
# File lib/jekyll/assets/processors/less.rb, line 11 def self.call(input) data = input[:data]; paths = [input[:load_path]] tree = Less.instance_variable_get(:@loader).require("less/tree") context = input[:environment].context_class.new(input) patch_tree(tree, context) paths |= input[:environment].paths paths |= Dir.glob(input[:load_path] + '/*').select(&File.method(:directory?)) parser = Less::Parser.new(:paths => paths) context.metadata.merge({ :data => Less::Parser.new(:paths => paths) .parse(data).to_css }) end
patch_tree(tree, context)
click to toggle source
Add the sprockets helpers into the Less environment so people can use assets from within Less… as they see fit.
We also make sure to disable their quotes so that we can quote ourselves if we need to, otherwise we simply just take the values.
# File lib/jekyll/assets/processors/less.rb, line 35 def self.patch_tree(tree, context) Helpers.instance_methods.each do |m| tree.functions[m.to_s.tr("_", "-")] = tree.functions[m.to_s] = lambda do |*args| args.last.tap do |o| o[:quote] = "" o[:value] = context.send(m, args.last.toCSS().gsub( /^"|"$/, "" )) if m.to_s.end_with?("_path") o[:value] = o[:value].inspect end end end end end