less 1.2.13 → 1.2.14

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  s.description = "LESS is leaner CSS"
10
10
  s.rubyforge_project = 'less'
11
11
  s.add_dependency('treetop', '>= 1.4.2')
12
- s.add_dependency('mutter', '>= 0.3.7')
12
+ s.add_dependency('mutter', '>= 0.4.2')
13
13
  end
14
14
  Jeweler::GemcutterTasks.new
15
15
  Jeweler::RubyforgeTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.13
1
+ 1.2.14
data/bin/lessc CHANGED
@@ -20,6 +20,7 @@ options = {
20
20
  :compress => false,
21
21
  :debug => false,
22
22
  :growl => false,
23
+ :timestamps => false,
23
24
  :color => $stdout.tty?
24
25
  }
25
26
 
@@ -27,12 +28,12 @@ options = {
27
28
  opts = OptionParser.new do |o|
28
29
  o.banner = "usage: lessc source [destination] [--watch]"
29
30
  o.separator ""
30
-
31
+
31
32
  # Watch mode
32
33
  o.on("-w", "--watch", "watch for changes") do
33
34
  options[:watch] = true
34
35
  end
35
-
36
+
36
37
  # Growl
37
38
  o.on("-g", "--growl", "growl notifications") do
38
39
  if Less::GROWL && (Growl.installed? rescue false)
@@ -44,7 +45,12 @@ opts = OptionParser.new do |o|
44
45
  "`sudo gem install visionmedia-growl -s http://gems.github.com`"
45
46
  end
46
47
  end
47
-
48
+
49
+ # Timestamps
50
+ o.on("-t", "--timestamps", "show timestamps in watch mode") do
51
+ options[:timestamps] = true
52
+ end
53
+
48
54
  # No color in output
49
55
  o.on("--no-color", "suppress color in output") do
50
56
  options[:color] = false
@@ -53,13 +59,13 @@ opts = OptionParser.new do |o|
53
59
  o.on('--verbose', 'show success messages when using growl') do
54
60
  options[:verbose] = true
55
61
  end
56
-
62
+
57
63
  # Compression needs a proper algorithm
58
64
  #
59
65
  # o.on("-x", "--compress", "compress css file") do
60
66
  # options[:compress] = true
61
67
  # end
62
-
68
+
63
69
  o.separator ""
64
70
 
65
71
  # Help
@@ -67,7 +73,7 @@ opts = OptionParser.new do |o|
67
73
  puts opts
68
74
  exit
69
75
  end
70
-
76
+
71
77
  o.on_tail("-d", "--debug", "show full error messages") do
72
78
  options[:debug] = true
73
79
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{less}
8
- s.version = "1.2.13"
8
+ s.version = "1.2.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["cloudhead"]
12
- s.date = %q{2009-11-19}
12
+ s.date = %q{2009-11-20}
13
13
  s.default_executable = %q{lessc}
14
14
  s.description = %q{LESS is leaner CSS}
15
15
  s.email = %q{self@cloudhead.net}
@@ -112,14 +112,14 @@ Gem::Specification.new do |s|
112
112
 
113
113
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
114
114
  s.add_runtime_dependency(%q<treetop>, [">= 1.4.2"])
115
- s.add_runtime_dependency(%q<mutter>, [">= 0.3.7"])
115
+ s.add_runtime_dependency(%q<mutter>, [">= 0.4.2"])
116
116
  else
117
117
  s.add_dependency(%q<treetop>, [">= 1.4.2"])
118
- s.add_dependency(%q<mutter>, [">= 0.3.7"])
118
+ s.add_dependency(%q<mutter>, [">= 0.4.2"])
119
119
  end
120
120
  else
121
121
  s.add_dependency(%q<treetop>, [">= 1.4.2"])
122
- s.add_dependency(%q<mutter>, [">= 0.3.7"])
122
+ s.add_dependency(%q<mutter>, [">= 0.4.2"])
123
123
  end
124
124
  end
125
125
 
@@ -13,20 +13,21 @@ require 'ext'
13
13
  require 'less/command'
14
14
  require 'less/engine'
15
15
 
16
- module Less
16
+ module Less
17
17
  MixedUnitsError = Class.new(RuntimeError)
18
18
  PathError = Class.new(RuntimeError)
19
19
  VariableNameError = Class.new(NameError)
20
20
  MixinNameError = Class.new(NameError)
21
21
  SyntaxError = Class.new(RuntimeError)
22
22
  ImportError = Class.new(RuntimeError)
23
-
23
+ CompileError = Class.new(RuntimeError)
24
+
24
25
  $verbose = false
25
26
 
26
27
  def self.version
27
28
  File.read( File.join( File.dirname(__FILE__), '..', 'VERSION') ).strip
28
29
  end
29
-
30
+
30
31
  def self.parse less
31
32
  Engine.new(less).to_css
32
33
  end
@@ -37,6 +37,7 @@ module Less
37
37
 
38
38
  # File has changed
39
39
  if File.stat( @source ).mtime > File.stat( @destination ).mtime
40
+ print Time.now.strftime("%H:%M:%S -- ") if @options[:timestamps]
40
41
  print "Change detected... "
41
42
 
42
43
  # Loop until error is fixed
@@ -68,6 +69,8 @@ module Less
68
69
  abort "#{e}"
69
70
  rescue SyntaxError => e
70
71
  err "#{e}\n", "Syntax"
72
+ rescue CompileError => e
73
+ err "#{e}\n", "Compile"
71
74
  rescue MixedUnitsError => e
72
75
  err "`#{e}` you're mixing units together! What do you expect?\n", "Mixed Units"
73
76
  rescue PathError => e
@@ -97,9 +100,9 @@ module Less
97
100
  false
98
101
  end
99
102
  end
100
-
101
- private
102
-
103
+
104
+ private
105
+
103
106
  def o ex, *styles
104
107
  @mutter.process(ex.to_s, *(@options[:color] ? styles : []))
105
108
  end
@@ -41,7 +41,7 @@ module Less
41
41
  rule mixin
42
42
  name:('.' [-a-zA-Z0-9_]+) args:(arguments) s ';' ws {
43
43
  def build env
44
- definition = env.nearest(name.text_value, :mixin) or raise MixinNameError, name.text_value
44
+ definition = env.nearest(name.text_value, :mixin) or raise MixinNameError, "#{name.text_value}() in #{env}"
45
45
  params = args.build.map {|i| Node::Expression.new i } unless args.empty?
46
46
  env << Node::Mixin::Call.new(definition, params || [], env)
47
47
  end
@@ -49,7 +49,7 @@ module Less
49
49
  def build env
50
50
  selectors.build(env, :mixin).each do |path|
51
51
  rules = path.inject(env.root) do |current, node|
52
- current.descend(node.selector, node) or raise MixinNameError, selectors.text_value
52
+ current.descend(node.selector, node) or raise MixinNameError, "#{selectors.text_value} in #{env}"
53
53
  end.rules
54
54
  env.rules += rules
55
55
  end
@@ -121,12 +121,6 @@ module Less
121
121
  end
122
122
  end
123
123
 
124
- def mix arr = []
125
- @rules += arr.map do |r|
126
- r.copy.tap {|i| i.parent = self }
127
- end
128
- end
129
-
130
124
  #
131
125
  # Add an arbitrary node to this element
132
126
  #
@@ -182,7 +176,7 @@ module Less
182
176
  path.map do |node|
183
177
  node.send(ary).find {|i| i.to_s == ident }
184
178
  end.compact.first.tap do |result|
185
- raise VariableNameError, ("#{ident} in #{self.to_s}") unless result
179
+ raise VariableNameError, ("#{ident} in #{self.to_s}") if result.nil? && type != :mixin
186
180
  end
187
181
  end
188
182
 
@@ -248,6 +242,10 @@ module Less
248
242
  end
249
243
 
250
244
  def call args = []
245
+ if e = @rules.find {|r| r.is_a? Element }
246
+ raise CompileError, "#{e} in #{self.inspect}: can't nest selectors inside a dynamic mixin."
247
+ end
248
+
251
249
  env = Element.new
252
250
 
253
251
  @params.zip(args).each do |param, val|
@@ -270,6 +268,10 @@ module Less
270
268
  '.' + name
271
269
  end
272
270
 
271
+ def inspect
272
+ ".#{name}()"
273
+ end
274
+
273
275
  def to_css path, env
274
276
  super(path, env)
275
277
  end
@@ -2,9 +2,9 @@ module Less
2
2
  module Node
3
3
  class Property < String
4
4
  include Entity
5
-
5
+
6
6
  attr_accessor :value
7
-
7
+
8
8
  def initialize key, value = nil, parent = nil
9
9
  super key, parent
10
10
  value = if value.is_a? Array
@@ -21,44 +21,44 @@ module Less
21
21
  # puts "new property #{to_s}: #{value} => #{@value}, contains: #{@value[0].class}"
22
22
  # puts
23
23
  end
24
-
24
+
25
25
  def parent= obj
26
26
  @parent = obj
27
27
  value.parent = self
28
28
  end
29
-
29
+
30
30
  def copy
31
31
  clone.tap {|c| c.value = value.copy }
32
32
  end
33
-
34
- def << token
33
+
34
+ def << token
35
35
  token = Node::Anonymous.new(*token) unless token.is_a? Entity or token.respond_to? :to_ruby
36
36
  token.parent = self if token.respond_to? :parent
37
37
  @value << token
38
38
  end
39
-
39
+
40
40
  def empty?; !@value || @value.empty? end
41
41
 
42
42
  def inspect
43
43
  self + (empty?? "" : ": `#{value.map {|i| i.to_s } * ' | '}`")
44
44
  end
45
-
45
+
46
46
  def == other
47
47
  self.to_s == other.to_s
48
48
  end
49
-
49
+
50
50
  def eql? other
51
51
  self == other and value.eql? other.value
52
52
  end
53
-
53
+
54
54
  def to_s
55
55
  super
56
56
  end
57
-
57
+
58
58
  def nearest node
59
59
  parent.nearest node
60
60
  end
61
-
61
+
62
62
  def evaluate env = nil
63
63
  # puts "evaluating property `#{to_s}`: #{value.inspect}"
64
64
  if value.is_a?(Expression) #Value
@@ -68,10 +68,10 @@ module Less
68
68
  # puts "value is a #{value.class}"
69
69
  [value.evaluate(env)]
70
70
  end
71
-
72
-
71
+
72
+
73
73
  end
74
-
74
+
75
75
  def to_css env = nil
76
76
  # puts "property.to_css `#{to_s}` env:#{env ? env.variables : "nil"}"
77
77
  val = evaluate(env)
@@ -87,20 +87,20 @@ module Less
87
87
 
88
88
  class Variable < Property
89
89
  attr_reader :declaration
90
-
91
- def initialize key, value = nil, parent = nil
92
- @declaration = value ? true : false
90
+
91
+ def initialize key, value = nil, parent = nil
92
+ @declaration = value ? true : false
93
93
  super key.delete('@'), value, parent
94
94
  end
95
-
95
+
96
96
  def inspect
97
97
  "@#{super}"
98
98
  end
99
-
99
+
100
100
  def to_s
101
101
  "@#{super}"
102
102
  end
103
-
103
+
104
104
  def evaluate env = nil
105
105
  if declaration
106
106
  # puts "evaluating DEC"
@@ -115,11 +115,11 @@ module Less
115
115
  var.evaluate
116
116
  end
117
117
  end
118
-
118
+
119
119
  def to_ruby
120
120
  evaluate.to_ruby
121
121
  end
122
-
122
+
123
123
  def to_css env = nil
124
124
  val = evaluate env
125
125
  if val.respond_to? :to_css
@@ -132,68 +132,68 @@ module Less
132
132
 
133
133
  class Expression < Array
134
134
  attr_accessor :parent, :delimiter
135
-
135
+
136
136
  def initialize ary, parent = nil, delimiter = ' '
137
137
  self.parent = parent
138
138
  self.delimiter = delimiter
139
139
  # puts "new expression #{ary} |#{delimiter}|"
140
140
  super(ary.is_a?(Array) ? ary : [ary].flatten)
141
141
  end
142
-
142
+
143
143
  def expressions; select {|i| i.kind_of? Expression } end
144
144
  def variables; select {|i| i.kind_of? Variable } end
145
145
  def operators; select {|i| i.is_a? Operator } end
146
146
  def entities; select {|i| i.kind_of? Entity } end
147
147
  def literals; select {|i| i.kind_of? Literal } end
148
-
148
+
149
149
  def parent= obj
150
150
  @parent = obj
151
151
  each {|e| e.parent = obj if e.respond_to? :parent }
152
152
  end
153
-
153
+
154
154
  def inspect
155
155
  '[' + map {|i| i.inspect }.join(', ') + ']'
156
156
  end
157
-
157
+
158
158
  def delimiter= d
159
159
  @delimiter = d.strip + ' '
160
160
  end
161
-
161
+
162
162
  def flatten
163
163
  self
164
164
  end
165
-
165
+
166
166
  def terminal?
167
167
  expressions.empty? #&& variables.empty?
168
168
  end
169
-
169
+
170
170
  def to_css env = nil
171
171
  # puts "TOCSS, delim: |#{@delimiter}|"
172
- map do |i|
172
+ map do |i|
173
173
  i.respond_to?(:to_css) ? i.to_css() : i.to_s
174
174
  end * @delimiter
175
175
  end
176
-
176
+
177
177
  def to_ruby
178
178
  map do |i|
179
179
  i.respond_to?(:to_ruby) ? i.to_ruby : i.to_s
180
180
  end
181
181
  end
182
-
182
+
183
183
  #
184
184
  # Evaluates the expression and instantiates a new Literal with the result
185
185
  # ex: [#111, +, #111] will evaluate to a Color node, with value #222
186
- #
186
+ #
187
187
  def evaluate env = nil
188
188
  # puts "expression #{self.inspect} env: #{env ? env.variables : "nil"}"
189
189
  if size > 2 or !terminal?
190
190
  # puts " SIZE > 2 or !terminal"
191
-
191
+
192
192
  # puts "--- sub evaluation ---"
193
193
 
194
194
  # Replace self with an evaluated sub-expression
195
195
  evaled = self.class.new(map {|e| e.respond_to?(:evaluate) ? e.evaluate(env) : e }, parent, delimiter) #5
196
-
196
+
197
197
  # puts "======================"
198
198
  # puts "evaled => #{evaled.inspect}"
199
199
 
@@ -202,7 +202,7 @@ module Less
202
202
  end.compact.uniq.tap do |ary|
203
203
  raise MixedUnitsError, evaled * ' ' if ary.size > 1 && !evaled.operators.empty?
204
204
  end.join
205
-
205
+
206
206
  entity = evaled.literals.find {|e| e.unit == unit } || evaled.literals.first || evaled.entities.first
207
207
  result = evaled.operators.empty?? evaled : eval(evaled.to_ruby.join)
208
208
 
@@ -226,4 +226,4 @@ module Less
226
226
  end
227
227
  end
228
228
  end
229
- end
229
+ end
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.2.13
4
+ version: 1.2.14
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-11-19 00:00:00 -05:00
12
+ date: 2009-11-20 00:00:00 -05:00
13
13
  default_executable: lessc
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.7
33
+ version: 0.4.2
34
34
  version:
35
35
  description: LESS is leaner CSS
36
36
  email: self@cloudhead.net