Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update less.js to 2.4.0 #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/less.rb
Expand Up @@ -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']
Expand All @@ -28,5 +28,5 @@ def self.Parser
def self.tree
self['tree']
end
end

end
2 changes: 1 addition & 1 deletion lib/less/js
Submodule js updated from 7370f7 to 6fd2a5
3 changes: 3 additions & 0 deletions lib/less/loader.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -229,5 +230,7 @@ def on(event, callback)

end

class Promise
end
end
end
61 changes: 24 additions & 37 deletions lib/less/parser.rb
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -52,56 +52,43 @@ 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
# @param [String] less the source to parse
# @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