less 0.8.4 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.4
1
+ 0.8.6
data/bin/lessc CHANGED
@@ -11,7 +11,8 @@ CSS = '.css'
11
11
  options = {
12
12
  :watch => false,
13
13
  :compress => false,
14
- :debug => false
14
+ :debug => false,
15
+ :inheritance => :desc
15
16
  }
16
17
 
17
18
  # Get arguments
@@ -24,9 +25,14 @@ opts = OptionParser.new do |o|
24
25
  options[:watch] = true
25
26
  end
26
27
 
28
+ # Child-type inheritance
29
+ o.on("-c", "--child", "nesting uses child-type inheritance") do
30
+ options[:chain] = :child
31
+ end
32
+
27
33
  # Compression needs a proper algorithm
28
34
  #
29
- # o.on("-c", "--compress", "compress css file") do
35
+ # o.on("-x", "--compress", "compress css file") do
30
36
  # options[:compress] = true
31
37
  # end
32
38
 
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 = "0.8.4"
5
+ s.version = "0.8.6"
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-05-25}
9
+ s.date = %q{2009-06-04}
10
10
  s.default_executable = %q{lessc}
11
11
  s.description = %q{LESS is leaner CSS}
12
12
  s.email = %q{alexis@cloudhead.net}
data/lib/less.rb CHANGED
@@ -4,7 +4,7 @@ require 'less/command'
4
4
  require 'less/engine'
5
5
  require 'less/tree'
6
6
 
7
- module Less
7
+ module Less
8
8
  class MixedUnitsError < Exception
9
9
  end
10
10
 
data/lib/less/command.rb CHANGED
@@ -47,7 +47,7 @@ module Less
47
47
  def compile
48
48
  begin
49
49
  # Create a new Less object with the contents of a file
50
- css = Less::Engine.new( File.read( @source ) ).to_css
50
+ css = Less::Engine.new( File.read( @source ) ).to_css @options[:inheritance]
51
51
  css = css.delete " \n" if compress?
52
52
 
53
53
  File.open( @destination, "w" ) do |file|
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? '@' # There's a var to evaluate
100
- value.scan REGEX[:path] do |p|
101
- p = p.join.delete ' '
102
- var = if p.include? '>'
103
- @tree.find :var, p.split('>') # Try finding it in a specific namespace
104
- else
105
- node.var( p ) || @tree.var( p ) # Try local first, then global
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
@@ -114,8 +114,8 @@ module Less
114
114
  end
115
115
  end
116
116
 
117
- def to_css
118
- self.compile.to_css
117
+ def to_css chain
118
+ self.compile.to_css chain
119
119
  end
120
120
 
121
121
  def hashify
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
- # we yield the full path of the leaf, aswell as
36
- # the branch which contains it (self).
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
- yield path, self[ key ] # The node is a branch, yield it to the block
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 path 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
-
57
- def to_css css = []
68
+
69
+ #
70
+ # Convert the tree to css, using full paths
71
+ #
72
+ def to_css chain = :desc, css = []
58
73
  self.traverse :branch do |path, node|
59
74
  properties = node.inject("") do |s, (k, v)|
60
- v.is_a?(String) ? (s + "#{k}: #{CGI.unescape(v)}; ") : s # Add the property to the list
75
+ v.is_a?(String) ? (s + "#{k}: #{CGI.unescape(v)}; ") : s # Add the property to the list
61
76
  end
62
- css << path * ' > ' + " { " + properties + "}" # Add the rule-set to the CSS
77
+ css << path * ( chain == :desc ? ' ' : ' > ') + " { " + properties + "}" # Add the rule-set to the CSS
63
78
  end
64
79
  css.join "\n"
65
80
  end
data/spec/spec.less CHANGED
@@ -46,7 +46,9 @@
46
46
  .second {
47
47
  @color: blue;
48
48
  .third {
49
- color: @main-color; // #444
49
+ background-color: @color; // blue
50
+ font-size: @size; // 8px
51
+ color: @main-color; // red
50
52
  border-color: .root > .first > .second > @color; // 'blue'
51
53
  }
52
54
  }
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: 0.8.4
4
+ version: 0.8.6
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-05-25 00:00:00 -04:00
12
+ date: 2009-06-04 00:00:00 -04:00
13
13
  default_executable: lessc
14
14
  dependencies: []
15
15