less 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/less.gemspec +1 -1
- data/lib/less.rb +1 -0
- data/lib/less/parser.rb +52 -12
- data/lib/less/version.rb +1 -1
- metadata +5 -5
data/.gitignore
CHANGED
data/less.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
|
-
s.add_dependency "therubyracer", "~> 0.9.
|
25
|
+
s.add_dependency "therubyracer", "~> 0.9.1"
|
26
26
|
s.add_development_dependency "rake", "~> 0.9.1"
|
27
27
|
s.add_development_dependency "rspec", "~> 2.0"
|
28
28
|
end
|
data/lib/less.rb
CHANGED
data/lib/less/parser.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
|
2
|
-
require 'v8'
|
3
|
-
|
4
2
|
module Less
|
3
|
+
|
4
|
+
# Utility for calling into the JavaScript runtime.
|
5
|
+
module CallJS
|
6
|
+
|
7
|
+
# @private
|
8
|
+
# Wrap JavaScript invocations with uniform error handling
|
9
|
+
#
|
10
|
+
# @yield code to wrap
|
11
|
+
def calljs
|
12
|
+
yield
|
13
|
+
rescue V8::JSError => e
|
14
|
+
raise ParseError.new(e)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convert lesscss source into an abstract syntax Tree
|
5
19
|
class Parser
|
20
|
+
include CallJS
|
6
21
|
|
22
|
+
# Construct and configure new Less::Parser
|
23
|
+
#
|
24
|
+
# @param [Hash] opts configuration options
|
25
|
+
# @option opts [Array] :paths a list of directories to search when handling \@import statements
|
26
|
+
# @option opts [String] :filename to associate with resulting parse trees (useful for generating errors)
|
7
27
|
def initialize(options = {})
|
8
28
|
stringy = {}
|
9
29
|
options.each do |k,v|
|
@@ -12,33 +32,53 @@ module Less
|
|
12
32
|
@parser = Less.Parser.new(stringy)
|
13
33
|
end
|
14
34
|
|
35
|
+
# Convert `less` source into a abstract syntaxt tree
|
36
|
+
# @param [String] less the source to parse
|
37
|
+
# @return [Less::Tree] the parsed tree
|
15
38
|
def parse(less)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
39
|
+
calljs do
|
40
|
+
error,tree = nil
|
41
|
+
@parser.parse(less, lambda {|e, t|
|
42
|
+
error = e; tree = t
|
43
|
+
})
|
44
|
+
Tree.new(tree) if tree
|
45
|
+
end
|
21
46
|
end
|
22
|
-
|
23
47
|
end
|
24
48
|
|
49
|
+
# Abstract LessCSS syntax tree Less. Mainly used to emit CSS
|
25
50
|
class Tree
|
51
|
+
include CallJS
|
52
|
+
# Create a tree from a native javascript object.
|
53
|
+
# @param [V8::Object] tree the native less.js tree
|
26
54
|
def initialize(tree)
|
27
55
|
@tree = tree
|
28
56
|
end
|
29
57
|
|
58
|
+
# Serialize this tree into CSS.
|
59
|
+
# By default this will be in pretty-printed form.
|
60
|
+
# @param [Hash] opts modifications to the output
|
61
|
+
# @option opts [Boolean] :compress minify output instead of pretty-printing
|
30
62
|
def to_css(options = {})
|
31
|
-
|
63
|
+
calljs do
|
64
|
+
@tree.toCSS(options)
|
65
|
+
end
|
32
66
|
end
|
33
67
|
end
|
34
|
-
|
68
|
+
|
69
|
+
# Thrown whenever an error occurs parsing
|
70
|
+
# and/or serializing less source. It is intended
|
71
|
+
# to wrap a native V8::JSError
|
35
72
|
class ParseError < StandardError
|
36
|
-
|
73
|
+
|
74
|
+
# Copies over `error`'s message and backtrace
|
75
|
+
# @param [V8::JSError] error native error
|
37
76
|
def initialize(error)
|
38
77
|
super(error.message)
|
39
78
|
@backtrace = error.backtrace
|
40
79
|
end
|
41
|
-
|
80
|
+
|
81
|
+
# @return [Array] the backtrace frames
|
42
82
|
def backtrace
|
43
83
|
@backtrace
|
44
84
|
end
|
data/lib/less/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: less
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.0.
|
5
|
+
version: 2.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Charles Lowell
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-17 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.1
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
requirements:
|
182
182
|
- - ">="
|
183
183
|
- !ruby/object:Gem::Version
|
184
|
-
hash:
|
184
|
+
hash: -2388107400795165815
|
185
185
|
segments:
|
186
186
|
- 0
|
187
187
|
version: "0"
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
requirements:
|
191
191
|
- - ">="
|
192
192
|
- !ruby/object:Gem::Version
|
193
|
-
hash:
|
193
|
+
hash: -2388107400795165815
|
194
194
|
segments:
|
195
195
|
- 0
|
196
196
|
version: "0"
|