diff --git a/lib/less.rb b/lib/less.rb index a92754e..6f5f9fa 100644 --- a/lib/less.rb +++ b/lib/less.rb @@ -8,16 +8,16 @@ module Less extend Less::Defaults - - # NOTE: keep the @loader as less-rails depends on + + # NOTE: keep the @loader as less-rails depends on # it as it overrides some less/tree.js functions! @loader = Less::Loader.new - @less = @loader.require('less/index') + @less = @loader.require('less-node') def self.[](name) @less[name] end - + # exposes less.Parser def self.Parser self['Parser'] @@ -28,5 +28,5 @@ def self.Parser def self.tree self['tree'] end - -end \ No newline at end of file + +end diff --git a/lib/less/js b/lib/less/js index 7370f72..6fd2a57 160000 --- a/lib/less/js +++ b/lib/less/js @@ -1 +1 @@ -Subproject commit 7370f72e3228d41db92060cad8eb14ee68f79027 +Subproject commit 6fd2a5751cc8313481913bcb1623bf6c50089df8 diff --git a/lib/less/loader.rb b/lib/less/loader.rb index ae9ad0b..b9b5433 100644 --- a/lib/less/loader.rb +++ b/lib/less/loader.rb @@ -22,6 +22,7 @@ def initialize @environment.native('fs', FS) @environment.native('url', Url) @environment.native('http', Http) + @environment.native('promise', Promise) end def require(module_id) @@ -229,5 +230,7 @@ def on(event, callback) end + class Promise + end end end diff --git a/lib/less/parser.rb b/lib/less/parser.rb index b092f1e..247a95b 100644 --- a/lib/less/parser.rb +++ b/lib/less/parser.rb @@ -16,7 +16,7 @@ class Parser # @option options [String] :dumpLineNumbers one of 'mediaquery', 'comments', or 'all' def initialize(options = {}) # 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 @@ -30,7 +30,7 @@ def initialize(options = {}) # - rootpath string # - entryPath string # - files (internal) - list of files that have been imported, used for import-once - # - currentFileInfo (internal) - information about the current file - + # - currentFileInfo (internal) - information about the current file - # for error reporting and importing and making urls relative etc : # this.currentFileInfo = { # filename: filename, @@ -41,9 +41,9 @@ def initialize(options = {}) # rootFilename: filename # }; # - env = {} + @options = {} Less.defaults.merge(options).each do |key, val| - env[key.to_s] = + @options[key.to_s] = case val when Symbol, Pathname then val.to_s when Array @@ -52,7 +52,6 @@ def initialize(options = {}) else val # true/false/String/Method end end - @parser = Less::JavaScript.exec { Less['Parser'].new(env) } end # Convert `less` source into a abstract syntaxt tree @@ -60,48 +59,36 @@ def initialize(options = {}) # @return [Less::Tree] the parsed tree 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 + Less.less.render(less, @options, 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? + }) Tree.new(tree) if tree end def imports Less::JavaScript.exec { @parser.imports.files.map { |file, _| file } } end + end - private - - # Abstract LessCSS syntax tree Less. Mainly used to emit CSS - class Tree - - # Create a tree from a native javascript object. - # @param [V8::Object] tree the native less.js tree - def initialize(tree) - @tree = tree - end - - # Serialize this tree into CSS. - # By default this will be in pretty-printed form. - # @param [Hash] opts modifications to the output - # @option opts [Boolean] :compress minify output instead of pretty-printing - def to_css(options = {}) - Less::JavaScript.exec { @tree.toCSS(options) } - end + private + class Tree + def initialize(tree) + @tree = tree end + def to_css(options = {}) + Less::JavaScript.exec { @tree.css } + end end end