less 1.0.8 → 1.0.9

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.8
1
+ 1.0.9
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{less}
5
- s.version = "1.0.8"
5
+ s.version = "1.0.9"
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-15}
9
+ s.date = %q{2009-07-16}
10
10
  s.default_executable = %q{lessc}
11
11
  s.description = %q{LESS is leaner CSS}
12
12
  s.email = %q{self@cloudhead.net}
@@ -165,7 +165,7 @@ grammar Less
165
165
  # div / .class / #id / input[type="text"] / lang(fr)
166
166
  #
167
167
  rule element
168
- (class_id / tag / ident) attribute* ('(' ident ')')? / attribute+ / '@media' / '@font-face'
168
+ (class_id / tag / ident) attribute* ('(' ident? attribute* ')')? / attribute+ / '@media' / '@font-face'
169
169
  end
170
170
 
171
171
  rule class_id
@@ -176,7 +176,7 @@ grammar Less
176
176
  # [type="text"]
177
177
  #
178
178
  rule attribute
179
- '[' tag ([|~]? '=') (tag / string) ']' / '[' (tag / string) ']'
179
+ '[' tag ([|~*]? '=') (tag / string) ']' / '[' (tag / string) ']'
180
180
  end
181
181
 
182
182
  rule class
@@ -290,9 +290,9 @@ grammar Less
290
290
  # Color
291
291
  #
292
292
  rule color
293
- '#' hex {
293
+ '#' rgb {
294
294
  def build env
295
- env.identifiers.last << Node::Color.new(hex.text_value)
295
+ env.identifiers.last << Node::Color.new(*rgb.build)
296
296
  end
297
297
  } / fn:(('hsl'/'rgb') 'a'?) '(' arguments ')' {
298
298
  def build env
@@ -302,10 +302,25 @@ grammar Less
302
302
  }
303
303
  end
304
304
 
305
- rule hex
306
- [a-fA-F0-9] [a-fA-F0-9] [a-fA-F0-9]+
305
+ #
306
+ # 00ffdd / 0fd
307
+ #
308
+ rule rgb
309
+ r:(hex hex) g:(hex hex) b:(hex hex) {
310
+ def build
311
+ [r.text_value, g.text_value, b.text_value]
312
+ end
313
+ } / r:hex g:hex b:hex {
314
+ def build
315
+ [r.text_value, g.text_value, b.text_value].map {|c| c * 2 }
316
+ end
317
+ }
307
318
  end
308
319
 
320
+ rule hex
321
+ [a-fA-F0-9]
322
+ end
323
+
309
324
  #
310
325
  # Functions and arguments
311
326
  #
@@ -1,8 +1,8 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'engine/nodes/entity'
4
+ require 'engine/nodes/function'
4
5
  require 'engine/nodes/element'
5
6
  require 'engine/nodes/property'
6
7
  require 'engine/nodes/literal'
7
- require 'engine/nodes/function'
8
8
  require 'engine/nodes/selector'
@@ -15,13 +15,7 @@ module Less
15
15
  # RGBA to Node::Color
16
16
  #
17
17
  def rgba *rgba
18
- r, g, b, a = rgba.flatten
19
- hex = [r, g, b].inject("") do |str, c|
20
- c = c.to_i.to_s(16)
21
- c = '0' + c if c.length < 2
22
- str + c
23
- end
24
- Node::Color.new hex, a
18
+ Node::Color.new *rgba
25
19
  end
26
20
 
27
21
  #
@@ -11,56 +11,79 @@ module Less
11
11
  #
12
12
  # rgb(255, 0, 0) #f0f0f0
13
13
  #
14
- class Color < DelegateClass(Fixnum)
14
+ class Color
15
15
  include Literal
16
- attr_reader :color, :opacity
17
-
18
- def initialize color = nil, opacity = 1.0
19
- @opacity = opacity
20
- @color = if color.is_a? Array
21
- rgba color
22
- elsif color.is_a? ::String
23
- color.delete! unit
24
- if color.length == 3
25
- color.split(//).map {|v| v + v }.join('').to_i 16
26
- elsif color.length == 6
27
- color.to_i 16
28
- else
29
- color
30
- end
16
+ attr_reader :r, :g, :b, :a
17
+
18
+ def initialize(r, g, b, a = 1.0)
19
+ r, g, b = [r, g, b].map {|c| c.is_a?(::String) ? c.to_i(16) : c }
20
+ @r, @g, @b, @a = normalize(r), normalize(g), normalize(b), normalize(a, 1.0)
21
+ end
22
+
23
+ def alpha(v)
24
+ self.class.new(r,g,b,v)
25
+ end
26
+
27
+ def rgb
28
+ [r, g, b]
29
+ end
30
+
31
+ def operate op, other
32
+ if other.is_a? Numeric
33
+ self.class.new *self.rgb.map {|c| c.send(op, other) }, @a
31
34
  else
32
- color
35
+ self.class.new *self.rgb.zip(other.rgb).map {|a, b| a.send(op, b) }, @a
33
36
  end
34
- super @color.to_i
35
37
  end
36
-
37
- def unit
38
- '#'
38
+
39
+ def + other
40
+ operate :+, other
39
41
  end
40
-
41
- def hex
42
- v = [[to_i, 0].max, 256 ** 3].min
43
- "%06x" % [v]
42
+
43
+ def - other
44
+ operate :-, other
44
45
  end
45
-
46
- def to_css
47
- if opacity and opacity < 1.0
48
- colors = hex.scan(/../).map {|v| v.to_i(16) }.join(", ")
49
- "rgba(#{colors}, #{opacity})"
46
+
47
+ def * other
48
+ operate :*, other
49
+ end
50
+
51
+ def / other
52
+ operate :/, other
53
+ end
54
+
55
+ def coerce other
56
+ return self, other
57
+ end
58
+
59
+ def to_s
60
+ if a < 1.0
61
+ "rgba(#{r.to_i}, #{g.to_i}, #{b.to_i}, #{a})"
50
62
  else
51
- unit + hex
63
+ "#%02x%02x%02x" % [r,g,b]
52
64
  end
53
65
  end
54
-
55
- def to_ruby
56
- color
66
+
67
+ def inspect
68
+ if a < 1.0
69
+ "rgba(#{r}, #{g}, #{b}, #{a})"
70
+ else
71
+ "rgb(#{r}, #{g}, #{b})"
72
+ end
57
73
  end
58
-
59
- def to_s
60
- "#{unit}#{super}"
74
+
75
+ def to_css
76
+ to_s
61
77
  end
62
78
 
63
- def inspect; to_s end
79
+ def to_ruby
80
+ "Color.new(#{r},#{g},#{b},#{a})"
81
+ end
82
+
83
+ protected
84
+ def normalize(v, max = 255, min = 0)
85
+ [[min, v].max, max].min
86
+ end
64
87
  end
65
88
 
66
89
  #
@@ -94,7 +94,12 @@ module Less
94
94
 
95
95
  unless ruby.include? nil
96
96
  if entity
97
- entity.class.new(eval(ruby.join), *(unit if entity.class == Node::Number))
97
+ result = eval(ruby.join)
98
+ if result.is_a? Entity
99
+ result
100
+ else
101
+ entity.class.new(*result, *(unit if entity.class == Node::Number))
102
+ end
98
103
  else
99
104
  first
100
105
  end
@@ -1660,10 +1660,6 @@ module Less
1660
1660
  end
1661
1661
 
1662
1662
  module Element0
1663
- def ident
1664
- elements[1]
1665
- end
1666
-
1667
1663
  end
1668
1664
 
1669
1665
  module Element1
@@ -1721,17 +1717,35 @@ module Less
1721
1717
  end
1722
1718
  s9 << r10
1723
1719
  if r10
1724
- r11 = _nt_ident
1720
+ r12 = _nt_ident
1721
+ if r12
1722
+ r11 = r12
1723
+ else
1724
+ r11 = instantiate_node(SyntaxNode,input, index...index)
1725
+ end
1725
1726
  s9 << r11
1726
1727
  if r11
1727
- if has_terminal?(')', false, index)
1728
- r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
1729
- @index += 1
1730
- else
1731
- terminal_parse_failure(')')
1732
- r12 = nil
1728
+ s13, i13 = [], index
1729
+ loop do
1730
+ r14 = _nt_attribute
1731
+ if r14
1732
+ s13 << r14
1733
+ else
1734
+ break
1735
+ end
1736
+ end
1737
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1738
+ s9 << r13
1739
+ if r13
1740
+ if has_terminal?(')', false, index)
1741
+ r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
1742
+ @index += 1
1743
+ else
1744
+ terminal_parse_failure(')')
1745
+ r15 = nil
1746
+ end
1747
+ s9 << r15
1733
1748
  end
1734
- s9 << r12
1735
1749
  end
1736
1750
  end
1737
1751
  if s9.last
@@ -1759,43 +1773,43 @@ module Less
1759
1773
  if r1
1760
1774
  r0 = r1
1761
1775
  else
1762
- s13, i13 = [], index
1776
+ s16, i16 = [], index
1763
1777
  loop do
1764
- r14 = _nt_attribute
1765
- if r14
1766
- s13 << r14
1778
+ r17 = _nt_attribute
1779
+ if r17
1780
+ s16 << r17
1767
1781
  else
1768
1782
  break
1769
1783
  end
1770
1784
  end
1771
- if s13.empty?
1772
- @index = i13
1773
- r13 = nil
1785
+ if s16.empty?
1786
+ @index = i16
1787
+ r16 = nil
1774
1788
  else
1775
- r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1789
+ r16 = instantiate_node(SyntaxNode,input, i16...index, s16)
1776
1790
  end
1777
- if r13
1778
- r0 = r13
1791
+ if r16
1792
+ r0 = r16
1779
1793
  else
1780
1794
  if has_terminal?('@media', false, index)
1781
- r15 = instantiate_node(SyntaxNode,input, index...(index + 6))
1795
+ r18 = instantiate_node(SyntaxNode,input, index...(index + 6))
1782
1796
  @index += 6
1783
1797
  else
1784
1798
  terminal_parse_failure('@media')
1785
- r15 = nil
1799
+ r18 = nil
1786
1800
  end
1787
- if r15
1788
- r0 = r15
1801
+ if r18
1802
+ r0 = r18
1789
1803
  else
1790
1804
  if has_terminal?('@font-face', false, index)
1791
- r16 = instantiate_node(SyntaxNode,input, index...(index + 10))
1805
+ r19 = instantiate_node(SyntaxNode,input, index...(index + 10))
1792
1806
  @index += 10
1793
1807
  else
1794
1808
  terminal_parse_failure('@font-face')
1795
- r16 = nil
1809
+ r19 = nil
1796
1810
  end
1797
- if r16
1798
- r0 = r16
1811
+ if r19
1812
+ r0 = r19
1799
1813
  else
1800
1814
  @index = i0
1801
1815
  r0 = nil
@@ -1907,7 +1921,7 @@ module Less
1907
1921
  s1 << r3
1908
1922
  if r3
1909
1923
  i4, s4 = index, []
1910
- if has_terminal?('[|~]', true, index)
1924
+ if has_terminal?('[|~*]', true, index)
1911
1925
  r6 = true
1912
1926
  @index += 1
1913
1927
  else
@@ -3211,14 +3225,14 @@ module Less
3211
3225
  end
3212
3226
 
3213
3227
  module Color0
3214
- def hex
3228
+ def rgb
3215
3229
  elements[1]
3216
3230
  end
3217
3231
  end
3218
3232
 
3219
3233
  module Color1
3220
3234
  def build env
3221
- env.identifiers.last << Node::Color.new(hex.text_value)
3235
+ env.identifiers.last << Node::Color.new(*rgb.build)
3222
3236
  end
3223
3237
  end
3224
3238
 
@@ -3262,7 +3276,7 @@ module Less
3262
3276
  end
3263
3277
  s1 << r2
3264
3278
  if r2
3265
- r3 = _nt_hex
3279
+ r3 = _nt_rgb
3266
3280
  s1 << r3
3267
3281
  end
3268
3282
  if s1.last
@@ -3372,62 +3386,190 @@ module Less
3372
3386
  r0
3373
3387
  end
3374
3388
 
3375
- module Hex0
3389
+ module Rgb0
3390
+ def hex
3391
+ elements[0]
3392
+ end
3393
+
3394
+ def hex
3395
+ elements[1]
3396
+ end
3376
3397
  end
3377
3398
 
3378
- def _nt_hex
3399
+ module Rgb1
3400
+ def hex
3401
+ elements[0]
3402
+ end
3403
+
3404
+ def hex
3405
+ elements[1]
3406
+ end
3407
+ end
3408
+
3409
+ module Rgb2
3410
+ def hex
3411
+ elements[0]
3412
+ end
3413
+
3414
+ def hex
3415
+ elements[1]
3416
+ end
3417
+ end
3418
+
3419
+ module Rgb3
3420
+ def r
3421
+ elements[0]
3422
+ end
3423
+
3424
+ def g
3425
+ elements[1]
3426
+ end
3427
+
3428
+ def b
3429
+ elements[2]
3430
+ end
3431
+ end
3432
+
3433
+ module Rgb4
3434
+ def build
3435
+ [r.text_value, g.text_value, b.text_value]
3436
+ end
3437
+ end
3438
+
3439
+ module Rgb5
3440
+ def r
3441
+ elements[0]
3442
+ end
3443
+
3444
+ def g
3445
+ elements[1]
3446
+ end
3447
+
3448
+ def b
3449
+ elements[2]
3450
+ end
3451
+ end
3452
+
3453
+ module Rgb6
3454
+ def build
3455
+ [r.text_value, g.text_value, b.text_value].map {|c| c * 2 }
3456
+ end
3457
+ end
3458
+
3459
+ def _nt_rgb
3379
3460
  start_index = index
3380
- if node_cache[:hex].has_key?(index)
3381
- cached = node_cache[:hex][index]
3461
+ if node_cache[:rgb].has_key?(index)
3462
+ cached = node_cache[:rgb][index]
3382
3463
  @index = cached.interval.end if cached
3383
3464
  return cached
3384
3465
  end
3385
3466
 
3386
- i0, s0 = index, []
3387
- if has_terminal?('[a-fA-F0-9]', true, index)
3388
- r1 = true
3389
- @index += 1
3467
+ i0 = index
3468
+ i1, s1 = index, []
3469
+ i2, s2 = index, []
3470
+ r3 = _nt_hex
3471
+ s2 << r3
3472
+ if r3
3473
+ r4 = _nt_hex
3474
+ s2 << r4
3475
+ end
3476
+ if s2.last
3477
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
3478
+ r2.extend(Rgb0)
3390
3479
  else
3391
- r1 = nil
3480
+ @index = i2
3481
+ r2 = nil
3392
3482
  end
3393
- s0 << r1
3394
- if r1
3395
- if has_terminal?('[a-fA-F0-9]', true, index)
3396
- r2 = true
3397
- @index += 1
3483
+ s1 << r2
3484
+ if r2
3485
+ i5, s5 = index, []
3486
+ r6 = _nt_hex
3487
+ s5 << r6
3488
+ if r6
3489
+ r7 = _nt_hex
3490
+ s5 << r7
3491
+ end
3492
+ if s5.last
3493
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
3494
+ r5.extend(Rgb1)
3398
3495
  else
3399
- r2 = nil
3496
+ @index = i5
3497
+ r5 = nil
3400
3498
  end
3401
- s0 << r2
3402
- if r2
3403
- s3, i3 = [], index
3404
- loop do
3405
- if has_terminal?('[a-fA-F0-9]', true, index)
3406
- r4 = true
3407
- @index += 1
3408
- else
3409
- r4 = nil
3410
- end
3411
- if r4
3412
- s3 << r4
3413
- else
3414
- break
3415
- end
3499
+ s1 << r5
3500
+ if r5
3501
+ i8, s8 = index, []
3502
+ r9 = _nt_hex
3503
+ s8 << r9
3504
+ if r9
3505
+ r10 = _nt_hex
3506
+ s8 << r10
3416
3507
  end
3417
- if s3.empty?
3418
- @index = i3
3419
- r3 = nil
3508
+ if s8.last
3509
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
3510
+ r8.extend(Rgb2)
3420
3511
  else
3421
- r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
3512
+ @index = i8
3513
+ r8 = nil
3422
3514
  end
3423
- s0 << r3
3515
+ s1 << r8
3424
3516
  end
3425
3517
  end
3426
- if s0.last
3427
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3428
- r0.extend(Hex0)
3518
+ if s1.last
3519
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
3520
+ r1.extend(Rgb3)
3521
+ r1.extend(Rgb4)
3522
+ else
3523
+ @index = i1
3524
+ r1 = nil
3525
+ end
3526
+ if r1
3527
+ r0 = r1
3528
+ else
3529
+ i11, s11 = index, []
3530
+ r12 = _nt_hex
3531
+ s11 << r12
3532
+ if r12
3533
+ r13 = _nt_hex
3534
+ s11 << r13
3535
+ if r13
3536
+ r14 = _nt_hex
3537
+ s11 << r14
3538
+ end
3539
+ end
3540
+ if s11.last
3541
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
3542
+ r11.extend(Rgb5)
3543
+ r11.extend(Rgb6)
3544
+ else
3545
+ @index = i11
3546
+ r11 = nil
3547
+ end
3548
+ if r11
3549
+ r0 = r11
3550
+ else
3551
+ @index = i0
3552
+ r0 = nil
3553
+ end
3554
+ end
3555
+
3556
+ node_cache[:rgb][start_index] = r0
3557
+
3558
+ r0
3559
+ end
3560
+
3561
+ def _nt_hex
3562
+ start_index = index
3563
+ if node_cache[:hex].has_key?(index)
3564
+ cached = node_cache[:hex][index]
3565
+ @index = cached.interval.end if cached
3566
+ return cached
3567
+ end
3568
+
3569
+ if has_terminal?('[a-fA-F0-9]', true, index)
3570
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
3571
+ @index += 1
3429
3572
  else
3430
- @index = i0
3431
3573
  r0 = nil
3432
3574
  end
3433
3575
 
@@ -4,3 +4,7 @@
4
4
  #blue #short { color: #0000ff; }
5
5
  #blue #long { color: #0000ff; }
6
6
  #blue #rgba { color: rgba(0, 0, 255, 0.1); }
7
+ #overflow .a { color: #000000; }
8
+ #overflow .b { color: #ffffff; }
9
+ #overflow .c { color: #ffffff; }
10
+ #overflow .d { color: #00ff00; }
@@ -23,6 +23,7 @@ p + h1 { font-size: 2.2em; }
23
23
  input[type="text"] { font-weight: normal; }
24
24
  h2[title] { font-size: 100%; }
25
25
  [disabled] { color: transparent; }
26
+ p:not([class*="lead"]) { color: black; }
26
27
  #shorthands {
27
28
  border: 1px solid #000000;
28
29
  font: 12px/16px Arial;
@@ -65,7 +65,7 @@ describe Less::Engine do
65
65
  it "should handle custom functions" do
66
66
  module Less::Functions
67
67
  def color arg
68
- Less::Node::Color.new("#999999") if arg == "evil red"
68
+ Less::Node::Color.new("99", "99", "99") if arg == "evil red"
69
69
  end
70
70
 
71
71
  def increment a
@@ -2,11 +2,9 @@
2
2
  #short {
3
3
  color: #fea;
4
4
  }
5
-
6
5
  #long {
7
6
  color: #ffeeaa;
8
7
  }
9
-
10
8
  #rgba {
11
9
  color: rgba(255, 238, 170, 0.1);
12
10
  }
@@ -16,12 +14,17 @@
16
14
  #short {
17
15
  color: #00f;
18
16
  }
19
-
20
17
  #long {
21
18
  color: #0000ff;
22
19
  }
23
-
24
20
  #rgba {
25
21
  color: rgba(0, 0, 255, 0.1);
26
22
  }
23
+ }
24
+
25
+ #overflow {
26
+ .a { color: #111111 - #444444; } // #000000
27
+ .b { color: #eee + #fff; } // #ffffff
28
+ .c { color: #aaa * 3; } // #ffffff
29
+ .d { color: #00ee00 + #009900; } // #00ff00
27
30
  }
@@ -72,6 +72,10 @@ h2[title] {
72
72
  color: transparent;
73
73
  }
74
74
 
75
+ p:not([class*="lead"]) {
76
+ color: black;
77
+ }
78
+
75
79
  #shorthands {
76
80
  border: 1px solid #000;
77
81
  font: 12px/16px Arial;
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.0.8
4
+ version: 1.0.9
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-15 00:00:00 -04:00
12
+ date: 2009-07-16 00:00:00 -04:00
13
13
  default_executable: lessc
14
14
  dependencies: []
15
15