middleman/middleman-core/lib/middleman-core/renderers/less.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

require 'less'
module Middleman
module Renderers
# Sass renderer
module Less
# Setup extension
class << self
# Once registered
def registered(app)
2012-10-14 04:54:55 +02:00
# Default less options
app.config.define_setting :less, {}, 'LESS compiler options'
app.before_configuration do
2014-04-29 19:44:24 +02:00
template_extensions less: :css
end
2012-08-10 21:29:15 +02:00
app.after_configuration do
::Less.paths << File.join(source_dir, config[:css_dir])
2012-08-10 21:29:15 +02:00
end
# Tell Tilt to use it as well (for inline sass blocks)
::Tilt.register 'less', LocalLoadingLessTemplate
::Tilt.prefer(LocalLoadingLessTemplate)
end
2014-04-29 01:02:18 +02:00
alias_method :included, :registered
end
# A SassTemplate for Tilt which outputs debug messages
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
def prepare
if ::Less.const_defined? :Engine
@engine = ::Less::Engine.new(data)
else
2014-04-29 19:44:24 +02:00
parser = ::Less::Parser.new(options.merge filename: eval_file, line: line, paths: ['.', File.dirname(eval_file)])
@engine = parser.parse(data)
end
end
end
end
end
end