less 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /*.css
2
+ *.tmproj
3
+ *.gem
4
+ pkg/
data/LICENSE ADDED
@@ -0,0 +1,179 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright (c) 2009 Alexis Sellier
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ LESS
2
+ ====
3
+ It's time CSS was done right – LESS is _leaner_ css.
4
+
5
+ Explained
6
+ ---------
7
+ LESS allows you to write CSS the way (I think) it was meant to, that is: with *variables*, *nested rules* and *mixins*!
8
+
9
+ ### Here's some example LESS code:
10
+
11
+ @dark: #110011;
12
+ .outline { border: 1px solid black }
13
+
14
+ .article {
15
+ a { text-decoration: none }
16
+ p { color: @dark }
17
+ .outline;
18
+ }
19
+
20
+ ### And the CSS output it produces:
21
+
22
+ .outline { border: 1px solid black }
23
+ .article > a { text-decoration: none }
24
+ .article > p { color: #110011 }
25
+ .article { border: 1px solid black }
26
+
27
+ If you have CSS nightmares, just
28
+ $ lessc style.less
29
+
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |s|
4
+ s.name = "less"
5
+ s.authors = ["cloudhead"]
6
+ s.email = "alexis@cloudhead.net"
7
+ s.summary = "LESS compiler"
8
+ s.homepage = "http://www.lesscss.org"
9
+ s.description = "LESS is leaner CSS"
10
+ s.rubyforge_project = 'less'
11
+ end
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
+ end
15
+
16
+ # rubyforge
17
+ begin
18
+ require 'rake/contrib/sshpublisher'
19
+ namespace :rubyforge do
20
+
21
+ desc "Release gem and RDoc documentation to RubyForge"
22
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
23
+
24
+ namespace :release do
25
+ desc "Publish RDoc to RubyForge."
26
+ task :docs => [:rdoc] do
27
+ config = YAML.load(
28
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
29
+ )
30
+
31
+ host = "#{config['username']}@rubyforge.org"
32
+ remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
33
+ local_dir = 'rdoc'
34
+
35
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
36
+ end
37
+ end
38
+ end
39
+ rescue LoadError
40
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0
data/bin/lessc ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + "/../lib"
4
+
5
+ require 'optparse'
6
+ require 'less'
7
+
8
+ CSS = '.css'
9
+
10
+ # Argument defaults
11
+ options = {
12
+ :watch => false,
13
+ :compress => false
14
+ }
15
+
16
+ # Get arguments
17
+ opts = OptionParser.new do |o|
18
+ o.banner = "usage: lessc source [destination] [--watch]"
19
+ o.separator ""
20
+
21
+ # Watch mode
22
+ o.on("-w", "--watch", "watch for changes") do
23
+ options[:watch] = true
24
+ end
25
+
26
+ # Compress
27
+ o.on("-c", "--compress", "compress css file") do
28
+ options[:compress] = true
29
+ end
30
+
31
+ o.separator ""
32
+
33
+ # Help
34
+ o.on_tail("-h", "--help", "show this message") do
35
+ puts opts
36
+ exit
37
+ end
38
+
39
+ # Version
40
+ o.on_tail("-v", "--version", "show version") do
41
+ puts "Less Compiler " + Less::VERSION
42
+ exit
43
+ end
44
+ end
45
+
46
+ opts.parse! # Parse arguments into `options` hash
47
+
48
+ # Get source and destintation from command line
49
+ case ARGV.size
50
+ when 1
51
+ options[:source] = ARGV[ 0 ]
52
+ when 2
53
+ options[:source] = ARGV[ 0 ]
54
+ options[:destination] = ARGV[ 1 ]
55
+ else
56
+ puts opts
57
+ exit
58
+ end
59
+ options[:destination] = (options[:destination] || options[:source]).gsub /\.(less|lss)/, CSS
60
+
61
+ Less::Command.new( options ).run!
data/less.gemspec ADDED
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{less}
5
+ s.version = "0.7.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["cloudhead"]
9
+ s.date = %q{2009-05-20}
10
+ s.default_executable = %q{lessc}
11
+ s.description = %q{LESS is leaner CSS}
12
+ s.email = %q{alexis@cloudhead.net}
13
+ s.executables = ["lessc"]
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/lessc",
25
+ "less.gemspec",
26
+ "lib/less.rb",
27
+ "lib/less/command.rb",
28
+ "lib/less/engine.rb",
29
+ "lib/less/tree.rb",
30
+ "spec/spec.less"
31
+ ]
32
+ s.has_rdoc = true
33
+ s.homepage = %q{http://www.lesscss.org}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubyforge_project = %q{less}
37
+ s.rubygems_version = %q{1.3.1}
38
+ s.summary = %q{LESS compiler}
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 2
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
data/lib/less.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'less/command'
2
+ require 'less/engine'
3
+ require 'less/tree'
4
+
5
+ module Less
6
+ VERSION = '0.5.2'
7
+ class MixedUnitsError < Exception
8
+ end
9
+ end
10
+
11
+ class Hash
12
+ # Convert a hash into a Tree
13
+ def to_tree
14
+ Less::Tree.new self
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ module Less
2
+ class Command
3
+ def initialize options
4
+ @source, @destination = options[:source], options[:destination]
5
+ @options = options
6
+ end
7
+ def watch?() @options[:watch] end
8
+ def compress?() @options[:compress] end
9
+
10
+ # little function which allows us to Ctrl-C exit inside the passed block
11
+ def watch &block
12
+ begin
13
+ block.call
14
+ rescue Interrupt
15
+ puts
16
+ exit 0
17
+ end
18
+ end
19
+
20
+ def run!
21
+ if watch?
22
+ log "Watching for changes in #@source ...Ctrl-C to abort.\n"
23
+ #
24
+ # Main watch loop
25
+ #
26
+ loop do
27
+ watch { sleep 1 }
28
+
29
+ # File has changed
30
+ if File.stat( @source ).mtime > File.stat( @destination ).mtime
31
+ log "Change detected... "
32
+ #
33
+ # Error loop
34
+ #
35
+ loop do
36
+ unless compile
37
+ log "Press [enter] to continue..."
38
+ watch { $stdin.gets }
39
+ next # continue within the error loop, until the error is fixed
40
+ end
41
+ break # break to main loop, as no errors were encountered
42
+ end
43
+ end # if
44
+ end # loop
45
+ else
46
+ compile
47
+ end
48
+ end
49
+
50
+ def compile
51
+ begin
52
+ # Create a new Less object with the contents of a file
53
+ css = Less::Engine.new( File.read( @source ) ).to_css
54
+ css = css.delete " \n" if compress?
55
+
56
+ File.open( @destination, "w" ) do |file|
57
+ file.write css
58
+ end
59
+ puts "#{@destination.split('/').last} was updated!" if watch?
60
+ rescue Errno::ENOENT => e
61
+ abort "#{e}"
62
+ rescue SyntaxError
63
+ error = $!.message.split("\n")[1..-1].collect {|e| e.gsub(/\(eval\)\:\d+\:\s/, '') } * "\n"
64
+ log " !! errors were found in the .less file! \n#{error}\n"
65
+ rescue MixedUnitsError
66
+ log "!! You're mixing units together! what do you expect?\n"
67
+ else
68
+ true
69
+ end
70
+ end
71
+
72
+ # Just a logging function to avoid typing '}'
73
+ def log s = ''
74
+ print '} ' + s.to_s
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,132 @@
1
+ module Less
2
+ class Engine < String
3
+ REGEXP = {
4
+ :path => /([#.][->#.\w]+)?( ?> ?)?@([\w\-]+)/, # #header > .title > @var
5
+ :selector => /[-\w #.>*_:]/, # .cow .milk > a
6
+ :values => /[-\w \(\)@>\/*+#%.,'"]/, # 10px solid #fff
7
+ :variable => /^@([\w\-]+)/ # @milk-white
8
+ }
9
+
10
+ def initialize s
11
+ super
12
+ @tree = Tree.new self.hashify
13
+ end
14
+
15
+ def compile
16
+ #
17
+ # Parse the variables and mixins
18
+ #
19
+ # We use symbolic keys, such as :mixins, to store LESS-only data,
20
+ # each branch has its own :mixins => [], and :variables => {}
21
+ # Once a declaration has been recognised as LESS-specific, it is copied
22
+ # in the appropriate data structure in that branch. The declaration itself
23
+ # can then be deleted.
24
+ #
25
+ @tree = @tree.traverse :leaf do |key, value, path, node|
26
+ matched = if match = key.match( REGEXP[:variable] )
27
+ node[:variables] ||= {}
28
+ node[:variables][ match.captures.first ] = value
29
+ elsif value == :mixin
30
+ node[:mixins] ||= []
31
+ node[:mixins] << key
32
+ end
33
+ node.delete key if matched # Delete the property if it's LESS-specific
34
+ end
35
+
36
+ #
37
+ # Evaluate mixins
38
+ #
39
+ @tree = @tree.traverse :branch do |path, node|
40
+ if node.include? :mixins
41
+ node[:mixins].each do |m|
42
+ @tree.find( :mixin, m.delete(' ').split('>') ).each {|k, v| node[ k ] = v }
43
+ end
44
+ end
45
+ end
46
+
47
+ #
48
+ # Evaluate variables
49
+ #
50
+ @tree = @tree.traverse :leaf do |key, value, path, node|
51
+ convert = lambda do |key, value, node| # We declare this as a lambda, for re-use
52
+ if value.is_a?(String) && value.include?('@') # There's a var to evaluate
53
+
54
+ # Find its value
55
+ var = value.delete(' ').match( REGEXP[:path] ).captures.join
56
+ var = unless var.include? '>'
57
+ node.var( var ) || @tree.var( var ) # Try local first, then global
58
+ else
59
+ @tree.find :var, var.split('>') # Try finding it in a specific namespace
60
+ end
61
+
62
+ if var
63
+ node[ key ] = value.gsub REGEXP[:path], var # Substitute variable with value
64
+ else
65
+ node.delete key # Discard the declaration if the variable wasn't found
66
+ end
67
+ end
68
+ end
69
+
70
+ # Call `convert` on css properties, such as 'font-size: @big'
71
+ convert.call key, value, node
72
+
73
+ # Call `convert` on variables, such as '@dark: @light / 2'
74
+ if node.vars?
75
+ node.vars.each do |key, value|
76
+ convert.call key, value, node
77
+ end
78
+ end
79
+ end
80
+
81
+ #
82
+ # Evaluate operations (2+2)
83
+ #
84
+ # Units are: 1px, 1em, 1%, #111
85
+ @tree = @tree.traverse :leaf do |key, value, path, node|
86
+ if value.match /[-+\/*]/
87
+ if (unit = value.scan(/(%)|\d+(px)|\d+(em)|(#)/i).flatten.compact.uniq).size <= 1
88
+ unit = unit.join
89
+ value = if unit == '#'
90
+ value.gsub(/#([a-z0-9]+)/i) do
91
+ hex = $1 * ( $1.size == 3 ? 2 : 1 )
92
+ hex.to_i(16)
93
+ end.delete unit
94
+ evaluate = lambda {|v| unit + eval( v ).to_s(16) }
95
+ else
96
+ value.gsub(/px|em|%/, '')
97
+ evaluate = lambda {|v| eval( v ).to_s + unit }
98
+ end.to_s
99
+ next if value.match /[a-z]/i
100
+ node[ key ] = evaluate.call value
101
+ else
102
+ raise MixedUnitsError
103
+ end
104
+ end
105
+ end
106
+
107
+ end
108
+ alias render compile
109
+
110
+ def to_css
111
+ self.compile.to_css
112
+ end
113
+
114
+ def hashify
115
+ #
116
+ # Parse the LESS structure into a hash
117
+ #
118
+ ###
119
+ # less: color: black;
120
+ # hashify: "color" => "black"
121
+ #
122
+ hash = self.gsub(/"/, "'"). # ""
123
+ gsub(/([@a-z\-]+):[ \t]*(#{ REGEXP[:values] }+);/, '"\\1" => "\\2",'). # Properties
124
+ gsub(/\}/, "},"). # Closing }
125
+ gsub(/([ \t]*)(#{ REGEXP[:selector] }+?)[ \t\n]*\{/m, '\\1"\\2" => {'). # Selectors
126
+ gsub(/([.#][->\w .#]+);/, '"\\1" => :mixin,'). # Mixins
127
+ gsub("\n\n", "\n"). # New-lines
128
+ gsub(/\/\/.*\n/, '') # Comments
129
+ eval "{" + hash + "}" # Return {hash}
130
+ end
131
+ end
132
+ end
data/lib/less/tree.rb ADDED
@@ -0,0 +1,67 @@
1
+ module Less
2
+ class Tree < Hash
3
+ def initialize init = {}
4
+ self.replace init
5
+ end
6
+
7
+ def var k
8
+ self[:variables] ? self[:variables][ k ] : nil
9
+ end
10
+
11
+ def vars?
12
+ self.include? :variables
13
+ end
14
+
15
+ def vars
16
+ self[:variables] ? self[:variables] : nil
17
+ end
18
+
19
+ def find what = :var, path = []
20
+ path.inject(self) do |branch, k|
21
+ if what == :var && k == path.last
22
+ branch[:variables][ k ]
23
+ else
24
+ branch = branch[ k ]
25
+ end
26
+ end
27
+ end
28
+
29
+ def traverse by = :leaf, path = [], &blk
30
+ #
31
+ # Traverse the whole tree, returning each leaf or branch (recursive)
32
+ #
33
+ ###
34
+ # Aside from the key & value,
35
+ # we yield the full path of the leaf, aswell as
36
+ # the branch which contains it (self).
37
+ #
38
+ self.each do |key, value| # `self` is the current node, starting with the trunk
39
+ if value.is_a? Hash and key != :variables # If the node is a branch, we can go deeper
40
+ path << key # Add the current branch to the path
41
+ 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
47
+ elsif by == :leaf and key.is_a? String
48
+ yield key, value, path, self # The node is a leaf, yield it to the block
49
+ path.pop
50
+ else
51
+ next
52
+ end
53
+ end
54
+ self
55
+ end
56
+
57
+ def to_css css = []
58
+ self.traverse :branch do |path, node|
59
+ properties = node.inject("") do |s, (k, v)|
60
+ v.is_a?(String) ? (s + "#{k}: #{v}; ") : s # Add the property to the list
61
+ end
62
+ css << path * ' > ' + " { " + properties + "}" # Add the rule-set to the CSS
63
+ end
64
+ css.join "\n"
65
+ end
66
+ end
67
+ end
data/spec/spec.less ADDED
@@ -0,0 +1,57 @@
1
+ // LESS
2
+ // the main color
3
+ @base-color: #fff;
4
+ @darker-color: @base-color / 2;
5
+
6
+ .dookoo a {
7
+ color: black;
8
+ }
9
+ .dookoo a {
10
+ font-family: "Verdana", 'Baka', serif;
11
+ }
12
+ .dookoo {
13
+ @fa: grey;
14
+ color: @fa;
15
+ line-height: 1999px;
16
+ }
17
+ .alt {
18
+ @base-color: green;
19
+ @darker-color: @base-color / 2;
20
+ @another-color: * > @base-color;
21
+ }
22
+ .altfoo { color: .alt > @base-color; }
23
+ .foo { border: 1px solid black; color: @base-color; }
24
+ .foo2 {
25
+ width: 10px * 2;
26
+ }
27
+ #content {
28
+ font-size: 12px;
29
+ @some-color: blue;
30
+ #header {
31
+ .foo;
32
+ font-size: #222 / 2;
33
+ }
34
+ #main-page {
35
+ #content > .small;
36
+ }
37
+ .small {
38
+ color: @base-color;
39
+ font-size: 12 / 2;
40
+ .hover_controls {
41
+ line-height: 16px;
42
+ display: none;
43
+ color: #content > @some-color;
44
+ border: 1px solid #fff;
45
+ }
46
+ }
47
+ .small:hover {
48
+ background-color: #eee + #content > @some-color;
49
+ .hover_controls {
50
+ .dookoo;
51
+ display: inline-block;
52
+ }
53
+ }
54
+ }
55
+ .sidebar {
56
+ #content > .small;
57
+ }
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: less
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - cloudhead
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-20 00:00:00 -04:00
13
+ default_executable: lessc
14
+ dependencies: []
15
+
16
+ description: LESS is leaner CSS
17
+ email: alexis@cloudhead.net
18
+ executables:
19
+ - lessc
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.md
25
+ files:
26
+ - .gitignore
27
+ - LICENSE
28
+ - README.md
29
+ - Rakefile
30
+ - VERSION
31
+ - bin/lessc
32
+ - less.gemspec
33
+ - lib/less.rb
34
+ - lib/less/command.rb
35
+ - lib/less/engine.rb
36
+ - lib/less/tree.rb
37
+ - spec/spec.less
38
+ has_rdoc: true
39
+ homepage: http://www.lesscss.org
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: less
60
+ rubygems_version: 1.3.1
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: LESS compiler
64
+ test_files: []
65
+