Class: Less::Engine

Inherits:
Object
  • 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.



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

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.



13
14
15
# File 'lib/less/engine.rb', line 13

def css
  @css
end

#lessObject (readonly)

Returns the value of attribute less.



13
14
15
# File 'lib/less/engine.rb', line 13

def less
  @less
end

Instance Method Details

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



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

def parse build = true, env = Node::Element.new
  root = @parser.parse(self.prepare)

  return root unless build

  if root
    env.file = @path
    @tree = root.build env
  else
    raise SyntaxError, @parser.failure_message(@options[:color])
  end

  @tree
end

#prepareObject



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

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

#to_cssObject



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

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