less 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.9
1
+ 1.1.10
data/less.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{less}
5
- s.version = "1.1.9"
5
+ s.version = "1.1.10"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["cloudhead"]
9
- s.date = %q{2009-07-30}
9
+ s.date = %q{2009-07-31}
10
10
  s.default_executable = %q{lessc}
11
11
  s.description = %q{LESS is leaner CSS}
12
12
  s.email = %q{self@cloudhead.net}
@@ -8,41 +8,41 @@ module Less
8
8
  # TODO: Look into making @rules its own hash-like class
9
9
  # TODO: Look into whether selector should be child by default
10
10
  #
11
- class Element < ::String
11
+ class Element
12
12
  include Enumerable
13
13
  include Entity
14
-
15
- attr_accessor :rules, :selector, :partial, :file, :set
16
-
14
+
15
+ attr_accessor :rules, :selector, :file,
16
+ :set, :name
17
+
17
18
  def initialize name = "", selector = ''
18
- super name
19
-
19
+ @name = name
20
20
  @set = []
21
21
  @rules = [] # Holds all the nodes under this element's hierarchy
22
22
  @selector = Selector[selector.strip].new # descendant | child | adjacent
23
23
  end
24
-
25
- def class?; self =~ /^\./ end
26
- def id?; self =~ /^#/ end
27
- def universal?; self == '*' end
28
-
29
- def tag?
24
+
25
+ def class?; name =~ /^\./ end
26
+ def id?; name =~ /^#/ end
27
+ def universal?; name == '*' end
28
+
29
+ def tag?
30
30
  not id? || class? || universal?
31
31
  end
32
-
32
+
33
33
  # Top-most node?
34
34
  def root?
35
35
  parent.nil?
36
36
  end
37
-
37
+
38
38
  def empty?
39
39
  @rules.empty?
40
40
  end
41
-
41
+
42
42
  def leaf?
43
43
  elements.empty?
44
44
  end
45
-
45
+
46
46
  # Group similar rulesets together
47
47
  # This is horrible, horrible code,
48
48
  # but it'll have to do until I find
@@ -51,24 +51,14 @@ module Less
51
51
  matched = false
52
52
  stack, result = elements.dup, []
53
53
  return self unless elements.size > 1
54
-
54
+
55
55
  elements.each do
56
56
  e = stack.first
57
57
  result << e unless matched
58
-
58
+
59
59
  matched = stack[1..-1].each do |ee|
60
- if e.rules.size == ee.rules.size and
61
- e.elements.size == 0 and
62
- !e.rules.zip(ee.rules).map {|a, b|
63
- a.to_css == b.to_css
64
- }.include?(false)
65
-
66
- # Add to set unless it's a duplicate
67
- if e == ee
68
- # Do something with dups
69
- else
70
- self[e].set << ee
71
- end
60
+ if e.equiv? ee and e.elements.size == 0
61
+ self[e].set << ee
72
62
  stack.shift
73
63
  else
74
64
  stack.shift
@@ -79,7 +69,7 @@ module Less
79
69
  @rules -= (elements - result)
80
70
  self
81
71
  end
82
-
72
+
83
73
  #
84
74
  # Accessors for the different nodes in @rules
85
75
  #
@@ -87,26 +77,47 @@ module Less
87
77
  def properties; @rules.select {|r| r.instance_of? Property } end
88
78
  def variables; @rules.select {|r| r.instance_of? Variable } end
89
79
  def elements; @rules.select {|r| r.instance_of? Element } end
90
-
80
+
91
81
  # Select a child element
92
82
  # TODO: Implement full selector syntax & merge with descend()
93
83
  def [] key
94
- @rules.find {|i| i.to_s == key }
84
+ case key
85
+ when Entity
86
+ @rules.find {|i| i.eql? key }
87
+ when ::String
88
+ @rules.find {|i| i.to_s == key }
89
+ else raise ArgumentError
90
+ end
91
+ end
92
+
93
+ def == other
94
+ name == other.name
95
+ end
96
+
97
+ def eql? other
98
+ super and self.equiv? other
95
99
  end
96
-
100
+
101
+ def equiv? other
102
+ rules.size == other.rules.size and
103
+ !rules.zip(other.rules).map do |a, b|
104
+ a.to_css == b.to_css
105
+ end.include?(false)
106
+ end
107
+
97
108
  # Same as above, except with a specific selector
98
109
  # TODO: clean this up or implement it differently
99
110
  def descend selector, element
100
111
  if selector.is_a? Child
101
- s = self[element].selector
102
- self[element] if s.is_a? Child or s.is_a? Descendant
112
+ s = self[element.name].selector
113
+ self[element.name] if s.is_a? Child or s.is_a? Descendant
103
114
  elsif selector.is_a? Descendant
104
- self[element]
115
+ self[element.name]
105
116
  else
106
- self[element] if self[element].selector.class == selector.class
117
+ self[element.name] if self[element.name].selector.class == selector.class
107
118
  end
108
119
  end
109
-
120
+
110
121
  #
111
122
  # Add an arbitrary node to this element
112
123
  #
@@ -118,33 +129,34 @@ module Less
118
129
  raise ArgumentError, "argument can't be a #{obj.class}"
119
130
  end
120
131
  end
121
-
132
+
122
133
  def last; elements.last end
123
134
  def first; elements.first end
124
- def to_s; root?? '*' : super end
125
-
135
+ def to_s; root?? '*' : name end
136
+
126
137
  #
127
138
  # Entry point for the css conversion
128
139
  #
129
140
  def to_css path = []
130
- path << @selector.to_css << self unless root?
141
+ path << @selector.to_css << name unless root?
131
142
 
132
143
  content = properties.map do |i|
133
144
  ' ' * 2 + i.to_css
134
145
  end.compact.reject(&:empty?) * "\n"
135
-
136
- content = content.include?("\n") ?
146
+
147
+ content = content.include?("\n") ?
137
148
  "\n#{content}\n" : " #{content.strip} "
138
- ruleset = !content.strip.empty??
139
- "#{[path.reject(&:empty?).join.strip, *@set] * ', '} {#{content}}\n" : ""
140
-
149
+ ruleset = !content.strip.empty??
150
+ "#{[path.reject(&:empty?).join.strip,
151
+ *@set.map(&:name)].uniq * ', '} {#{content}}\n" : ""
152
+
141
153
  css = ruleset + elements.map do |i|
142
154
  i.to_css(path)
143
- end.reject(&:empty?).join
155
+ end.reject(&:empty?).join
144
156
  path.pop; path.pop
145
157
  css
146
158
  end
147
-
159
+
148
160
  #
149
161
  # Find the nearest variable in the hierarchy or raise a NameError
150
162
  #
@@ -156,26 +168,26 @@ module Less
156
168
  raise VariableNameError, ident unless result
157
169
  end
158
170
  end
159
-
171
+
160
172
  #
161
173
  # Traverse the whole tree, returning each leaf (recursive)
162
174
  #
163
175
  def each path = [], &blk
164
- elements.each do |element|
165
- path << element
166
- yield element, path if element.leaf?
167
- element.each path, &blk
168
- path.pop
176
+ elements.each do |element|
177
+ path << element
178
+ yield element, path if element.leaf?
179
+ element.each path, &blk
180
+ path.pop
169
181
  end
170
182
  self
171
183
  end
172
-
184
+
173
185
  def inspect depth = 0
174
186
  indent = lambda {|i| '. ' * i }
175
187
  put = lambda {|ary| ary.map {|i| indent[ depth + 1 ] + i.inspect } * "\n"}
176
188
 
177
189
  (root?? "\n" : "") + [
178
- indent[ depth ] + (self == '' ? '*' : self.to_s),
190
+ indent[ depth ] + self.to_s,
179
191
  put[ properties ],
180
192
  put[ variables ],
181
193
  elements.map {|i| i.inspect( depth + 1 ) } * "\n"
@@ -32,6 +32,14 @@ module Less
32
32
  def inspect
33
33
  self + (empty?? "" : ": `#{value.map {|i| i.to_s } * ' | '}`")
34
34
  end
35
+
36
+ def == other
37
+ self.to_s == other.to_s
38
+ end
39
+
40
+ def eql? other
41
+ self == other and value.eql? other.value
42
+ end
35
43
 
36
44
  def to_s
37
45
  super
@@ -6,3 +6,8 @@ h3 a:hover { color: red; }
6
6
  h3 p:hover { color: red; }
7
7
  #all, #the, #same { color: blue; }
8
8
  ul, li, div, q, blockquote, textarea { margin: 0; }
9
+ td {
10
+ margin: 0;
11
+ padding: 0;
12
+ }
13
+ td, input { line-height: 1em; }
@@ -1,9 +1,4 @@
1
1
  .whitespace, .white, .space, .mania, .no-semi-column { color: white; }
2
- .whitespace { color: white; }
3
- .whitespace { color: white; }
4
- .whitespace { color: white; }
5
- .whitespace { color: white; }
6
- .no-semi-column { color: white; }
7
2
  .no-semi-column {
8
3
  color: white;
9
4
  white-space: pre;
@@ -13,3 +13,12 @@ h1, h2, h3 {
13
13
  ul, li, div, q, blockquote, textarea {
14
14
  margin: 0;
15
15
  }
16
+
17
+ td {
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+
22
+ td, input {
23
+ line-height: 1em;
24
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: less
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudhead
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-30 00:00:00 -04:00
12
+ date: 2009-07-31 00:00:00 -04:00
13
13
  default_executable: lessc
14
14
  dependencies: []
15
15