1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
require 'tilt/template'
module Tilt
# Sass template implementation. See:
# http://haml.hamptoncatlin.com/
#
# Sass templates do not support object scopes, locals, or yield.
class SassTemplate < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
defined? ::Sass::Engine
end
def initialize_engine
require_template_library 'sass'
end
def prepare
@engine = ::Sass::Engine.new(data, sass_options)
end
def evaluate(scope, locals, &block)
@output ||= @engine.render
end
def allows_script?
false
end
private
def sass_options
options.merge(:filename => eval_file, :line => line, :syntax => :sass)
end
end
# Sass's new .scss type template implementation.
class ScssTemplate < SassTemplate
self.default_mime_type = 'text/css'
private
def sass_options
options.merge(:filename => eval_file, :line => line, :syntax => :scss)
end
end
# Lessscss template implementation. See:
# http://lesscss.org/
#
# Less templates do not support object scopes, locals, or yield.
class LessTemplate < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
defined? ::Less
end
def initialize_engine
require_template_library 'less'
end
def prepare
if ::Less.const_defined? :Engine
@engine = ::Less::Engine.new(data)
else
parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
@engine = parser.parse(data)
end
end
def evaluate(scope, locals, &block)
@output ||= @engine.to_css(options)
end
def allows_script?
false
end
end
end
|