Class: Less::Parser

Inherits:
Object
  • Object
show all
Includes:
CallJS
Defined in:
lib/less/parser.rb

Overview

Convert lesscss source into an abstract syntax Tree

Instance Method Summary collapse

Methods included from CallJS

#calljs, #lock

Constructor Details

#initialize(options = {}) ⇒ Parser

Construct and configure new Less::Parser

Parameters:

  • opts (Hash)

    configuration options


49
50
51
52
53
54
55
56
57
# File 'lib/less/parser.rb', line 49

def initialize(options = {})
  stringy = {}
  Less.defaults.merge(options).each do |k,v|
    stringy[k.to_s] = v.is_a?(Array) ? v.map(&:to_s) : v.to_s
  end
  lock do
    @parser = Less.Parser.new(stringy)
  end
end

Instance Method Details

#parse(less) ⇒ Less::Tree

Convert `less` source into a abstract syntaxt tree

Parameters:

  • less (String)

    the source to parse

Returns:


62
63
64
65
66
67
68
69
70
# File 'lib/less/parser.rb', line 62

def parse(less)
  calljs do
    error,tree = nil
    @parser.parse(less, lambda {|e, t|
      error = e; tree = t
    })
    Tree.new(tree) if tree
  end
end