Class: ZAssets::Plugins::LESS::Template

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/zassets/plugins/less/template.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/zassets/plugins/less/template.rb', line 10

def self.engine_initialized?
  defined? ::Less
end

Instance Method Details

#depend_on(context, path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/zassets/plugins/less/template.rb', line 35

def depend_on(context, path)
  parser = ::Less::Parser.new({
    :filename => path,
    :paths    => [File.dirname(path)]
  })
  parser.parse(File.read(path))
  parser.imports.each do |i|
    dependency_path = File.join(File.dirname(path), i)
    context.depend_on(dependency_path)
    depend_on(context, dependency_path)
  end
end

#evaluate(context, locals, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zassets/plugins/less/template.rb', line 21

def evaluate(context, locals, &block)
  options = {
    :filename => eval_file,
    :paths => [File.dirname(eval_file)]
  }
  parser = ::Less::Parser.new(options)
  tree = parser.parse(data)
  depend_on(context, eval_file)
  tree.to_css
rescue ::Less::ParseError => e
  context.__LINE__ = e.line
  raise e
end

#initialize_engineObject



14
15
16
# File 'lib/zassets/plugins/less/template.rb', line 14

def initialize_engine
  require_template_library 'less'
end

#prepareObject



18
19
# File 'lib/zassets/plugins/less/template.rb', line 18

def prepare
end