less 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/lessc +6 -5
- data/less.gemspec +1 -1
- data/lib/less.rb +7 -2
- data/lib/less/command.rb +13 -17
- data/lib/less/engine.rb +16 -15
- data/lib/less/tree.rb +1 -1
- data/spec/spec.less +13 -1
- metadata +1 -1
data/Rakefile
CHANGED
@@ -27,7 +27,7 @@ begin
|
|
27
27
|
config = YAML.load(
|
28
28
|
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
29
29
|
)
|
30
|
-
|
30
|
+
options << '--line-numbers' << '--inline-source'
|
31
31
|
host = "#{config['username']}@rubyforge.org"
|
32
32
|
remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
|
33
33
|
local_dir = 'rdoc'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/bin/lessc
CHANGED
@@ -23,10 +23,11 @@ opts = OptionParser.new do |o|
|
|
23
23
|
options[:watch] = true
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# Compression needs a proper algorithm
|
27
|
+
#
|
28
|
+
# o.on("-c", "--compress", "compress css file") do
|
29
|
+
# options[:compress] = true
|
30
|
+
# end
|
30
31
|
|
31
32
|
o.separator ""
|
32
33
|
|
@@ -38,7 +39,7 @@ opts = OptionParser.new do |o|
|
|
38
39
|
|
39
40
|
# Version
|
40
41
|
o.on_tail("-v", "--version", "show version") do
|
41
|
-
puts "
|
42
|
+
puts "lessc " + Less.version
|
42
43
|
exit
|
43
44
|
end
|
44
45
|
end
|
data/less.gemspec
CHANGED
data/lib/less.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
require 'less/command'
|
2
4
|
require 'less/engine'
|
3
5
|
require 'less/tree'
|
4
6
|
|
5
7
|
module Less
|
6
|
-
|
7
|
-
|
8
|
+
class MixedUnitsError < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.version
|
12
|
+
File.read( File.join( File.dirname(__FILE__), '..', 'VERSION') )
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
data/lib/less/command.rb
CHANGED
@@ -4,10 +4,12 @@ module Less
|
|
4
4
|
@source, @destination = options[:source], options[:destination]
|
5
5
|
@options = options
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
|
+
def watch?() @options[:watch] end
|
8
9
|
def compress?() @options[:compress] end
|
9
10
|
|
10
|
-
# little function which allows us to
|
11
|
+
# little function which allows us to
|
12
|
+
# Ctrl-C exit inside the passed block
|
11
13
|
def watch &block
|
12
14
|
begin
|
13
15
|
block.call
|
@@ -20,28 +22,22 @@ module Less
|
|
20
22
|
def run!
|
21
23
|
if watch?
|
22
24
|
log "Watching for changes in #@source ...Ctrl-C to abort.\n"
|
23
|
-
|
25
|
+
|
24
26
|
# Main watch loop
|
25
|
-
#
|
26
27
|
loop do
|
27
28
|
watch { sleep 1 }
|
28
29
|
|
29
30
|
# File has changed
|
30
31
|
if File.stat( @source ).mtime > File.stat( @destination ).mtime
|
31
32
|
log "Change detected... "
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
33
|
+
|
34
|
+
# Loop until error is fixed
|
35
|
+
while not compile
|
36
|
+
log "Press [enter] to continue..."
|
37
|
+
watch { $stdin.gets }
|
42
38
|
end
|
43
|
-
end
|
44
|
-
end
|
39
|
+
end
|
40
|
+
end
|
45
41
|
else
|
46
42
|
compile
|
47
43
|
end
|
@@ -56,7 +52,7 @@ module Less
|
|
56
52
|
File.open( @destination, "w" ) do |file|
|
57
53
|
file.write css
|
58
54
|
end
|
59
|
-
puts "#{@destination.split('/').last}
|
55
|
+
puts " [Updated] #{@destination.split('/').last}" if watch?
|
60
56
|
rescue Errno::ENOENT => e
|
61
57
|
abort "#{e}"
|
62
58
|
rescue SyntaxError
|
data/lib/less/engine.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Less
|
2
2
|
class Engine < String
|
3
3
|
REGEXP = {
|
4
|
-
:path
|
5
|
-
:selector => /[-\w
|
6
|
-
:
|
7
|
-
:
|
4
|
+
:path => /(?>[#.][->#.\w ]+)?(?> ?> ?)?@([-\w]+)/, # #header > .title > @var
|
5
|
+
:selector => /[-\w #.>*:]/, # .cow .milk > a
|
6
|
+
:variable => /^@([-\w]+)/, # @milk-white
|
7
|
+
:property => /@[-\w]+|[-a-z]+/ # font-size
|
8
8
|
}
|
9
9
|
|
10
10
|
def initialize s
|
@@ -85,18 +85,18 @@ module Less
|
|
85
85
|
@tree = @tree.traverse :leaf do |key, value, path, node|
|
86
86
|
if value.match /[-+\/*]/
|
87
87
|
if (unit = value.scan(/(%)|\d+(px)|\d+(em)|(#)/i).flatten.compact.uniq).size <= 1
|
88
|
-
unit = unit.join
|
88
|
+
unit = unit.join
|
89
89
|
value = if unit == '#'
|
90
|
+
evaluate = lambda {|v| unit + eval( v ).to_s(16) }
|
90
91
|
value.gsub(/#([a-z0-9]+)/i) do
|
91
92
|
hex = $1 * ( $1.size == 3 ? 2 : 1 )
|
92
93
|
hex.to_i(16)
|
93
94
|
end.delete unit
|
94
|
-
evaluate = lambda {|v| unit + eval( v ).to_s(16) }
|
95
95
|
else
|
96
|
-
value.gsub(/px|em|%/, '')
|
97
96
|
evaluate = lambda {|v| eval( v ).to_s + unit }
|
98
|
-
|
99
|
-
|
97
|
+
value.gsub(/px|em|%/, '')
|
98
|
+
end.to_s
|
99
|
+
next if value.match /[a-z]/i
|
100
100
|
node[ key ] = evaluate.call value
|
101
101
|
else
|
102
102
|
raise MixedUnitsError
|
@@ -119,13 +119,14 @@ module Less
|
|
119
119
|
# less: color: black;
|
120
120
|
# hashify: "color" => "black"
|
121
121
|
#
|
122
|
-
hash = self.gsub(
|
123
|
-
gsub(
|
122
|
+
hash = self.gsub(/\/\/.*\n/, ''). # Comments //
|
123
|
+
gsub(/\/\*.*?\//m, ''). # Comments /*
|
124
|
+
gsub(/"/, "'"). # " => '
|
125
|
+
gsub(/("|')(.+?)(\1)/) { $1 + CGI.escape( $2 ) + $1 }. # Escape string values
|
126
|
+
gsub(/(#{REGEXP[:property]}):[ \t]*(.+?);/, '"\\1" => "\\2",'). # Declarations
|
124
127
|
gsub(/\}/, "},"). # Closing }
|
125
|
-
gsub(/([ \t]*)(#{
|
126
|
-
gsub(/([.#][->\w .#]+);/, '"\\1" => :mixin,')
|
127
|
-
gsub("\n\n", "\n"). # New-lines
|
128
|
-
gsub(/\/\/.*\n/, '') # Comments
|
128
|
+
gsub(/([ \t]*)(#{REGEXP[:selector]}+?)[ \t\n]*\{/m, '\\1"\\2" => {'). # Selectors
|
129
|
+
gsub(/([.#][->\w .#]+);/, '"\\1" => :mixin,') # Mixins
|
129
130
|
eval "{" + hash + "}" # Return {hash}
|
130
131
|
end
|
131
132
|
end
|
data/lib/less/tree.rb
CHANGED
@@ -57,7 +57,7 @@ module Less
|
|
57
57
|
def to_css css = []
|
58
58
|
self.traverse :branch do |path, node|
|
59
59
|
properties = node.inject("") do |s, (k, v)|
|
60
|
-
v.is_a?(String) ? (s + "#{k}: #{v}; ") : s # Add the property to the list
|
60
|
+
v.is_a?(String) ? (s + "#{k}: #{CGI.unescape(v)}; ") : s # Add the property to the list
|
61
61
|
end
|
62
62
|
css << path * ' > ' + " { " + properties + "}" # Add the rule-set to the CSS
|
63
63
|
end
|
data/spec/spec.less
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
// the main color
|
3
3
|
@base-color: #fff;
|
4
4
|
@darker-color: @base-color / 2;
|
5
|
+
/*
|
5
6
|
|
7
|
+
lala
|
8
|
+
|
9
|
+
*/
|
6
10
|
.dookoo a {
|
7
11
|
color: black;
|
8
12
|
}
|
@@ -13,19 +17,27 @@
|
|
13
17
|
@fa: grey;
|
14
18
|
color: @fa;
|
15
19
|
line-height: 1999px;
|
20
|
+
.blah {
|
21
|
+
.bloop {
|
22
|
+
@supernested: iceberg;
|
23
|
+
}
|
24
|
+
}
|
16
25
|
}
|
17
26
|
.alt {
|
18
27
|
@base-color: green;
|
19
28
|
@darker-color: @base-color / 2;
|
20
29
|
@another-color: * > @base-color;
|
21
30
|
}
|
31
|
+
#kelkoo {
|
32
|
+
color: .dookoo > .blah > .bloop > @supernested;
|
33
|
+
}
|
22
34
|
.altfoo { color: .alt > @base-color; }
|
23
35
|
.foo { border: 1px solid black; color: @base-color; }
|
24
36
|
.foo2 {
|
25
37
|
width: 10px * 2;
|
26
38
|
}
|
27
39
|
#content {
|
28
|
-
font-size:
|
40
|
+
font-size: "};(*#)";
|
29
41
|
@some-color: blue;
|
30
42
|
#header {
|
31
43
|
.foo;
|