Class: Less::Parser
- Inherits:
-
Object
- Object
- Less::Parser
- Defined in:
- lib/less/parser.rb
Overview
Convert lesscss source into an abstract syntax Tree
Defined Under Namespace
Classes: Tree
Instance Method Summary collapse
- #imports ⇒ Object
-
#initialize(options = {}) ⇒ Parser
constructor
Construct and configure new Less::Parser.
-
#parse(less) ⇒ Less::Tree
Convert ‘less` source into a abstract syntaxt tree.
Constructor Details
#initialize(options = {}) ⇒ Parser
Construct and configure new Less::Parser
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/less/parser.rb', line 17 def initialize( = {}) # LeSS supported _env_ options : # # - paths (unmodified) - paths to search for imports on # - optimization - optimization level (for the chunker) # - mime (browser only) mime type for sheet import # - contents (browser only) # - strictImports # - dumpLineNumbers - whether to dump line numbers # - compress - whether to compress # - processImports - whether to process imports. if false then imports will not be imported # - relativeUrls (true/false) whether to adjust URL's to be relative # - errback (error callback function) # - rootpath string # - entryPath string # - files (internal) - list of files that have been imported, used for import-once # - currentFileInfo (internal) - information about the current file - # for error reporting and importing and making urls relative etc : # this.currentFileInfo = { # filename: filename, # relativeUrls: this.relativeUrls, # rootpath: options.rootpath || "", # currentDirectory: entryPath, # entryPath: entryPath, # rootFilename: filename # }; # env = {} Less.defaults.merge().each do |key, val| env[key.to_s] = case val when Symbol, Pathname then val.to_s when Array val.map!(&:to_s) if key.to_sym == :paths # might contain Pathname-s val # keep the original passed Array else val # true/false/String/Method end end @parser = Less::JavaScript.exec { Less['Parser'].new(env) } end |
Instance Method Details
#imports ⇒ Object
80 81 82 |
# File 'lib/less/parser.rb', line 80 def imports Less::JavaScript.exec { @parser.imports.files.map { |file, _| file } } end |
#parse(less) ⇒ Less::Tree
Convert ‘less` source into a abstract syntaxt tree
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/less/parser.rb', line 61 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. # might get invoked as callback(error) error = args.last else error, tree = *args end fail error. unless error.nil? }) end Tree.new(tree) if tree end |