2013-12-28 01:26:31 +01:00
|
|
|
require 'less'
|
2012-06-05 19:24:00 +02:00
|
|
|
|
|
|
|
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'
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-06-05 19:24:00 +02:00
|
|
|
app.before_configuration do
|
2014-04-29 19:44:24 +02:00
|
|
|
template_extensions less: :css
|
2012-06-05 19:24:00 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-08-10 21:29:15 +02:00
|
|
|
app.after_configuration do
|
2012-10-14 07:37:24 +02:00
|
|
|
::Less.paths << File.join(source_dir, config[:css_dir])
|
2012-08-10 21:29:15 +02:00
|
|
|
end
|
2012-06-05 19:24:00 +02:00
|
|
|
|
|
|
|
# Tell Tilt to use it as well (for inline sass blocks)
|
|
|
|
::Tilt.register 'less', LocalLoadingLessTemplate
|
|
|
|
::Tilt.prefer(LocalLoadingLessTemplate)
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2014-04-29 01:02:18 +02:00
|
|
|
alias_method :included, :registered
|
2012-06-05 19:24:00 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-06-05 19:24:00 +02:00
|
|
|
# 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)])
|
2012-06-05 19:24:00 +02:00
|
|
|
@engine = parser.parse(data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
end
|