Class: Less::Engine

Inherits:
Object show all
Defined in:
lib/less/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, options = {}) ⇒ Engine

Returns a new instance of Engine.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/less/engine.rb', line 17

def initialize obj, options = {}
  @less = if obj.is_a? File
    @path = File.dirname File.expand_path(obj.path)
    obj.read
  elsif obj.is_a? String
    obj.dup
  else
    raise ArgumentError, "argument must be an instance of File or String!"
  end
  
  @options = options
  @parser = StyleSheetParser.new
end

Instance Attribute Details

#cssObject (readonly)

Returns the value of attribute css.



15
16
17
# File 'lib/less/engine.rb', line 15

def css
  @css
end

#lessObject (readonly)

Returns the value of attribute less.



15
16
17
# File 'lib/less/engine.rb', line 15

def less
  @less
end

Instance Method Details

#parse(build = true, env = Node::Element.new) ⇒ Object Also known as: to_tree



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/less/engine.rb', line 31

def parse build = true, env = Node::Element.new
  root = @parser.parse(self.prepare)
  
  return root unless build
  
  if root
    @tree = root.build env.tap {|e| e.file = @path }
  else
    raise SyntaxError, @parser.failure_message(@options[:color])
  end

  @tree
end

#prepareObject



50
51
52
# File 'lib/less/engine.rb', line 50

def prepare
  @less.gsub(/\r\n/, "\n").gsub(/\t/, '  ')
end

#to_cssObject



46
47
48
# File 'lib/less/engine.rb', line 46

def to_css
  @css || @css = self.parse.group.to_css
end