less 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/less.gemspec +1 -1
- data/lib/less/engine.rb +40 -38
- data/spec/spec.less +5 -4
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.1
|
data/less.gemspec
CHANGED
data/lib/less/engine.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Less
|
2
2
|
class Engine < String
|
3
3
|
REGEXP = {
|
4
|
-
:path => /(
|
4
|
+
:path => /([#.][->#.\w ]+)?( ?> ?)?@([-\w]+)/, # #header > .title > @var
|
5
5
|
:selector => /[-\w #.>*:]/, # .cow .milk > a
|
6
|
-
:variable =>
|
6
|
+
:variable => /@([-\w]+)/, # @milk-white
|
7
7
|
:property => /@[-\w]+|[-a-z]+/ # font-size
|
8
8
|
}
|
9
9
|
|
@@ -23,8 +23,8 @@ module Less
|
|
23
23
|
# can then be deleted.
|
24
24
|
#
|
25
25
|
@tree = @tree.traverse :leaf do |key, value, path, node|
|
26
|
-
matched = if match = key.match( REGEXP[:variable] )
|
27
|
-
node[:variables] ||=
|
26
|
+
matched = if match = key.match( REGEXP[:variable] )
|
27
|
+
node[:variables] ||= Tree.new
|
28
28
|
node[:variables][ match.captures.first ] = value
|
29
29
|
elsif value == :mixin
|
30
30
|
node[:mixins] ||= []
|
@@ -44,38 +44,16 @@ module Less
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
#
|
48
|
-
|
49
|
-
|
47
|
+
# Call `evaluate` on variables, such as '@dark: @light / 2'
|
48
|
+
@tree = @tree.traverse :branch do |path, node|
|
49
|
+
node.vars.each do |key, value|
|
50
|
+
evaluate key, value, node.vars
|
51
|
+
end if node.vars?
|
52
|
+
end
|
53
|
+
|
54
|
+
# Call `evaluate` on css properties, such as 'font-size: @big'
|
50
55
|
@tree = @tree.traverse :leaf do |key, value, path, node|
|
51
|
-
|
52
|
-
if value.is_a?(String) && value.include?('@') # There's a var to evaluate
|
53
|
-
|
54
|
-
# Find its value
|
55
|
-
var = value.delete(' ').match( REGEXP[:path] ).captures.join
|
56
|
-
var = unless var.include? '>'
|
57
|
-
node.var( var ) || @tree.var( var ) # Try local first, then global
|
58
|
-
else
|
59
|
-
@tree.find :var, var.split('>') # Try finding it in a specific namespace
|
60
|
-
end
|
61
|
-
|
62
|
-
if var
|
63
|
-
node[ key ] = value.gsub REGEXP[:path], var # Substitute variable with value
|
64
|
-
else
|
65
|
-
node.delete key # Discard the declaration if the variable wasn't found
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Call `convert` on css properties, such as 'font-size: @big'
|
71
|
-
convert.call key, value, node
|
72
|
-
|
73
|
-
# Call `convert` on variables, such as '@dark: @light / 2'
|
74
|
-
if node.vars?
|
75
|
-
node.vars.each do |key, value|
|
76
|
-
convert.call key, value, node
|
77
|
-
end
|
78
|
-
end
|
56
|
+
evaluate key, value, node
|
79
57
|
end
|
80
58
|
|
81
59
|
#
|
@@ -87,9 +65,12 @@ module Less
|
|
87
65
|
if (unit = value.scan(/(%)|\d+(px)|\d+(em)|(#)/i).flatten.compact.uniq).size <= 1
|
88
66
|
unit = unit.join
|
89
67
|
value = if unit == '#'
|
90
|
-
evaluate = lambda
|
68
|
+
evaluate = lambda do |v|
|
69
|
+
result = eval v
|
70
|
+
unit + ( result.zero?? '000' : result.to_s(16) )
|
71
|
+
end
|
91
72
|
value.gsub(/#([a-z0-9]+)/i) do
|
92
|
-
hex = $1 * ( $1.size
|
73
|
+
hex = $1 * ( $1.size < 6 ? 6 / $1.size : 1 )
|
93
74
|
hex.to_i(16)
|
94
75
|
end.delete unit
|
95
76
|
else
|
@@ -103,10 +84,31 @@ module Less
|
|
103
84
|
end
|
104
85
|
end
|
105
86
|
end
|
106
|
-
|
107
87
|
end
|
108
88
|
alias render compile
|
109
89
|
|
90
|
+
#
|
91
|
+
# Evaluate variables
|
92
|
+
#
|
93
|
+
def evaluate key, value, node
|
94
|
+
if value.is_a? String and value.include? '@' # There's a var to evaluate
|
95
|
+
value.scan REGEXP[:path] do |p|
|
96
|
+
p = p.join.delete ' '
|
97
|
+
var = if p.include? '>'
|
98
|
+
@tree.find :var, p.split('>') # Try finding it in a specific namespace
|
99
|
+
else
|
100
|
+
node.var( p ) || @tree.var( p ) # Try local first, then global
|
101
|
+
end
|
102
|
+
|
103
|
+
if var
|
104
|
+
node[ key ] = value.gsub REGEXP[:path], var # Substitute variable with value
|
105
|
+
else
|
106
|
+
node.delete key # Discard the declaration if the variable wasn't found
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
110
112
|
def to_css
|
111
113
|
self.compile.to_css
|
112
114
|
end
|
data/spec/spec.less
CHANGED
@@ -14,8 +14,9 @@ lala
|
|
14
14
|
font-family: "Verdana", 'Baka', serif;
|
15
15
|
}
|
16
16
|
.dookoo {
|
17
|
+
@fi: @fa;
|
17
18
|
@fa: grey;
|
18
|
-
color: @
|
19
|
+
color: .alt > @base-color - .alt > @base-color;
|
19
20
|
line-height: 1999px;
|
20
21
|
.blah {
|
21
22
|
.bloop {
|
@@ -24,9 +25,9 @@ lala
|
|
24
25
|
}
|
25
26
|
}
|
26
27
|
.alt {
|
27
|
-
@base-color:
|
28
|
-
@darker-color: @base-color
|
29
|
-
@another-color:
|
28
|
+
@base-color: #876956 - #111;
|
29
|
+
@darker-color: @base-color - @base-color;
|
30
|
+
@another-color: @base-color;
|
30
31
|
}
|
31
32
|
#kelkoo {
|
32
33
|
color: .dookoo > .blah > .bloop > @supernested;
|