Convert lesscss source into an abstract syntax Tree
Construct and configure new Less::Parser
@param [Hash] opts configuration options @option opts [Array] :paths a list of directories to search when handling import statements @option opts [String] :filename to associate with resulting parse trees (useful for generating errors)
# File lib/less/parser.rb, line 11 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 @parser = Less::JavaScript.exec { Less['Parser'].new(stringy) } end
# File lib/less/parser.rb, line 41 def imports Less::JavaScript.exec { @parser.imports.files.map{|file, _| file} } end
Convert `less` source into a abstract syntaxt tree @param [String] less the source to parse @return [Less::Tree] the parsed tree
# File lib/less/parser.rb, line 22 def parse(less) error, tree = nil, nil Less::JavaScript.exec do @parser.parse(less, lambda { |*args| # (error, tree) # v8 >= 0.10 passes this as first arg : if args.size > 2 error, tree = args[-2], args[-1] elsif args.last.respond_to?(:message) && args.last.message # might get invoked as callback(error) error = args.last else error, tree = *args end fail error.message unless error.nil? }) end Tree.new(tree) if tree end