cloudhead-less 0.8.3 → 0.8.4
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 +10 -10
- data/lib/less/tree.rb +26 -11
- data/spec/spec.less +3 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.4
|
data/less.gemspec
CHANGED
data/lib/less/engine.rb
CHANGED
@@ -52,13 +52,13 @@ module Less
|
|
52
52
|
# Call `evaluate` on variables, such as '@dark: @light / 2'
|
53
53
|
@tree = @tree.traverse :branch do |path, node|
|
54
54
|
node.vars.each do |key, value|
|
55
|
-
evaluate key, value, node.vars
|
55
|
+
evaluate key, value, path, node.vars
|
56
56
|
end if node.vars?
|
57
57
|
end
|
58
58
|
|
59
59
|
# Call `evaluate` on css properties, such as 'font-size: @big'
|
60
60
|
@tree = @tree.traverse :leaf do |key, value, path, node|
|
61
|
-
evaluate key, value, node
|
61
|
+
evaluate key, value, path, node
|
62
62
|
end
|
63
63
|
|
64
64
|
#
|
@@ -95,14 +95,14 @@ module Less
|
|
95
95
|
#
|
96
96
|
# Evaluate variables
|
97
97
|
#
|
98
|
-
def evaluate key, value, node
|
99
|
-
if value.is_a? String and value.include? '@'
|
100
|
-
value.scan REGEX[:path] do |
|
101
|
-
|
102
|
-
var = if
|
103
|
-
@tree.find :var,
|
104
|
-
else
|
105
|
-
|
98
|
+
def evaluate key, value, path, node
|
99
|
+
if value.is_a? String and value.include? '@' # There's a var to evaluate
|
100
|
+
value.scan REGEX[:path] do |var|
|
101
|
+
var = var.join.delete ' '
|
102
|
+
var = if var.include? '>'
|
103
|
+
@tree.find :var, var.split('>') # Try finding it in a specific namespace
|
104
|
+
else
|
105
|
+
node.var( var ) or @tree.nearest var, path # Try local first, then nearest scope
|
106
106
|
end
|
107
107
|
|
108
108
|
if var
|
data/lib/less/tree.rb
CHANGED
@@ -16,6 +16,9 @@ module Less
|
|
16
16
|
self[:variables] ? self[:variables] : nil
|
17
17
|
end
|
18
18
|
|
19
|
+
#
|
20
|
+
# Find a variable or mixin from a specific path
|
21
|
+
#
|
19
22
|
def find what = :var, path = []
|
20
23
|
path.inject(self) do |branch, k|
|
21
24
|
if what == :var && k == path.last
|
@@ -26,40 +29,52 @@ module Less
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
32
|
+
#
|
33
|
+
# Find the nearest variable in the hierarchy
|
34
|
+
#
|
35
|
+
def nearest var, path
|
36
|
+
values = []
|
37
|
+
path.inject(self) do |branch, k|
|
38
|
+
values << branch.var( var )
|
39
|
+
branch[ k ]
|
40
|
+
end
|
41
|
+
values.compact.last
|
42
|
+
end
|
43
|
+
|
29
44
|
def traverse by = :leaf, path = [], &blk
|
30
45
|
#
|
31
46
|
# Traverse the whole tree, returning each leaf or branch (recursive)
|
32
47
|
#
|
33
48
|
###
|
34
|
-
# Aside from the key & value,
|
35
|
-
#
|
36
|
-
#
|
49
|
+
# Aside from the key & value, we yield the full path of the leaf,
|
50
|
+
# aswell as the branch which contains it (self).
|
51
|
+
# Note that in :branch mode, we only return 'twigs', branches which contain leaves.
|
37
52
|
#
|
38
53
|
self.each do |key, value| # `self` is the current node, starting with the trunk
|
39
54
|
if value.is_a? Hash and key != :variables # If the node is a branch, we can go deeper
|
40
55
|
path << key # Add the current branch to the path
|
41
56
|
self[ key ] = value.to_tree. # Make sure any change is saved to the main tree
|
42
|
-
traverse by, path, &blk # Recurse, with the current node becoming `self`
|
43
|
-
if by == :branch
|
44
|
-
|
45
|
-
path.pop
|
46
|
-
end
|
57
|
+
traverse by, path, &blk # Recurse, with the current node becoming `self`
|
58
|
+
yield path, self[ key ] if by == :branch # The node is a branch, yield it to the block
|
59
|
+
path.pop # We're returning from a branch, pop the last element
|
47
60
|
elsif by == :leaf and key.is_a? String
|
48
61
|
yield key, value, path, self # The node is a leaf, yield it to the block
|
49
|
-
path.pop
|
50
62
|
else
|
51
63
|
next
|
52
64
|
end
|
53
65
|
end
|
54
66
|
self
|
55
67
|
end
|
56
|
-
|
68
|
+
|
69
|
+
#
|
70
|
+
# Convert the tree to css, using full paths
|
71
|
+
#
|
57
72
|
def to_css css = []
|
58
73
|
self.traverse :branch do |path, node|
|
59
74
|
properties = node.inject("") do |s, (k, v)|
|
60
75
|
v.is_a?(String) ? (s + "#{k}: #{CGI.unescape(v)}; ") : s # Add the property to the list
|
61
76
|
end
|
62
|
-
css << path * ' > ' + " { " + properties + "}"
|
77
|
+
css << path * ' > ' + " { " + properties + "}" # Add the rule-set to the CSS
|
63
78
|
end
|
64
79
|
css.join "\n"
|
65
80
|
end
|
data/spec/spec.less
CHANGED