less 0.8.13 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/Rakefile +21 -3
- data/VERSION +1 -1
- data/bin/lessc +0 -8
- data/less.gemspec +138 -15
- data/lib/less.rb +67 -11
- data/lib/less/command.rb +24 -25
- data/lib/less/engine.rb +36 -140
- data/lib/less/engine/builder.rb +8 -0
- data/lib/less/engine/less.tt +374 -0
- data/lib/less/engine/nodes.rb +8 -0
- data/lib/less/engine/nodes/element.rb +150 -0
- data/lib/less/engine/nodes/entity.rb +73 -0
- data/lib/less/engine/nodes/function.rb +82 -0
- data/lib/less/engine/nodes/literal.rb +135 -0
- data/lib/less/engine/nodes/property.rb +112 -0
- data/lib/less/engine/nodes/selector.rb +39 -0
- data/lib/less/engine/parser.rb +3860 -0
- data/lib/vendor/treetop/.gitignore +7 -0
- data/lib/vendor/treetop/LICENSE +19 -0
- data/lib/vendor/treetop/README +164 -0
- data/lib/vendor/treetop/Rakefile +19 -0
- data/lib/vendor/treetop/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop/bin/tt +28 -0
- data/lib/vendor/treetop/lib/treetop.rb +8 -0
- data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +3097 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +408 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +23 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +68 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +109 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +90 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +247 -0
- data/lib/vendor/treetop/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +32 -0
- data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +68 -0
- data/lib/vendor/treetop/spec/spec_helper.rb +106 -0
- data/lib/vendor/treetop/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop/treetop.gemspec +17 -0
- data/spec/command_spec.rb +2 -6
- data/spec/css/accessors-1.0.css +18 -0
- data/spec/css/big-1.0.css +3768 -0
- data/spec/css/comments-1.0.css +9 -0
- data/spec/css/css-1.0.css +40 -0
- data/spec/css/functions-1.0.css +6 -0
- data/spec/css/import-1.0.css +11 -0
- data/spec/css/mixins-1.0.css +28 -0
- data/spec/css/operations-1.0.css +28 -0
- data/spec/css/rulesets-1.0.css +17 -0
- data/spec/css/scope-1.0.css +14 -0
- data/spec/css/strings-1.0.css +12 -0
- data/spec/css/variables-1.0.css +6 -0
- data/spec/css/whitespace-1.0.css +9 -0
- data/spec/engine_spec.rb +66 -18
- data/spec/less/accessors-1.0.less +20 -0
- data/spec/less/big-1.0.less +4810 -0
- data/spec/less/colors-1.0.less +0 -0
- data/spec/less/comments-1.0.less +46 -0
- data/spec/less/css-1.0.less +84 -0
- data/spec/less/exceptions/mixed-units-error.less +3 -0
- data/spec/less/exceptions/name-error-1.0.less +3 -0
- data/spec/less/exceptions/syntax-error-1.0.less +3 -0
- data/spec/less/functions-1.0.less +6 -0
- data/spec/less/import-1.0.less +7 -0
- data/spec/less/import/import-test-a.less +2 -0
- data/spec/less/import/import-test-b.less +8 -0
- data/spec/less/import/import-test-c.less +5 -0
- data/spec/less/mixins-1.0.less +43 -0
- data/spec/less/operations-1.0.less +39 -0
- data/spec/less/rulesets-1.0.less +30 -0
- data/spec/less/scope-1.0.less +33 -0
- data/spec/less/strings-1.0.less +14 -0
- data/spec/less/variables-1.0.less +18 -0
- data/spec/less/whitespace-1.0.less +21 -0
- data/spec/spec.css +79 -24
- data/spec/spec.less +2 -3
- data/spec/spec_helper.rb +4 -1
- metadata +136 -13
- data/lib/less/tree.rb +0 -82
- data/spec/css/less-0.8.10.css +0 -30
- data/spec/css/less-0.8.11.css +0 -31
- data/spec/css/less-0.8.12.css +0 -28
- data/spec/css/less-0.8.5.css +0 -24
- data/spec/css/less-0.8.6.css +0 -24
- data/spec/css/less-0.8.7.css +0 -24
- data/spec/css/less-0.8.8.css +0 -25
- data/spec/tree_spec.rb +0 -5
@@ -0,0 +1,150 @@
|
|
1
|
+
module Less
|
2
|
+
module Node
|
3
|
+
#
|
4
|
+
# Element
|
5
|
+
#
|
6
|
+
# div {...}
|
7
|
+
#
|
8
|
+
# TODO: Look into making @rules its own hash-like class
|
9
|
+
# TODO: Look into whether selector should be child by default
|
10
|
+
#
|
11
|
+
class Element < ::String
|
12
|
+
include Enumerable
|
13
|
+
include Entity
|
14
|
+
|
15
|
+
attr_accessor :rules, :selector, :partial, :file
|
16
|
+
|
17
|
+
def initialize name = "", selector = ''
|
18
|
+
super name
|
19
|
+
|
20
|
+
@partial = false
|
21
|
+
@rules = [] # Holds all the nodes under this element's hierarchy
|
22
|
+
@selector = Selector[selector.strip].new # descendant | child | adjacent
|
23
|
+
end
|
24
|
+
|
25
|
+
def class?; self =~ /^\./ end
|
26
|
+
def id?; self =~ /^#/ end
|
27
|
+
def universal?; self == '*' end
|
28
|
+
|
29
|
+
def tag?
|
30
|
+
not id? || class? || universal?
|
31
|
+
end
|
32
|
+
|
33
|
+
# Top-most node?
|
34
|
+
def root?
|
35
|
+
self == '' && parent.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty?
|
39
|
+
@rules.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def leaf?
|
43
|
+
elements.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Accessors for the different nodes in @rules
|
48
|
+
#
|
49
|
+
def identifiers; @rules.select {|r| r.kind_of? Property } end
|
50
|
+
def properties; @rules.select {|r| r.instance_of? Property } end
|
51
|
+
def variables; @rules.select {|r| r.instance_of? Variable } end
|
52
|
+
def elements; @rules.select {|r| r.instance_of? Element } end
|
53
|
+
|
54
|
+
# Select a child element
|
55
|
+
# TODO: Implement full selector syntax & merge with descend()
|
56
|
+
def [] key
|
57
|
+
@rules.find {|i| i.to_s == key }
|
58
|
+
end
|
59
|
+
|
60
|
+
# Same as above, except with a specific selector
|
61
|
+
# TODO: clean this up or implement it differently
|
62
|
+
def descend selector, element
|
63
|
+
if selector.is_a? Child
|
64
|
+
s = self[element].selector
|
65
|
+
self[element] if s.is_a? Child or s.is_a? Descendant
|
66
|
+
elsif selector.is_a? Descendant
|
67
|
+
self[element]
|
68
|
+
else
|
69
|
+
self[element] if self[element].selector.class == selector.class
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Add an arbitrary node to this element
|
75
|
+
#
|
76
|
+
def << obj
|
77
|
+
if obj.kind_of? Node::Entity
|
78
|
+
obj.parent = self
|
79
|
+
@rules << obj
|
80
|
+
else
|
81
|
+
raise ArgumentError, "argument can't be a #{obj.class}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def last; elements.last end
|
86
|
+
def first; elements.first end
|
87
|
+
def to_s; super end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Entry point for the css conversion
|
91
|
+
#
|
92
|
+
def to_css path = []
|
93
|
+
path << @selector.to_css << self unless root?
|
94
|
+
|
95
|
+
content = properties.map do |i|
|
96
|
+
' ' * 2 + i.to_css
|
97
|
+
end.compact.reject(&:empty?) * "\n"
|
98
|
+
|
99
|
+
content = content.include?("\n") ?
|
100
|
+
"\n#{content}\n" : " #{content.strip} "
|
101
|
+
ruleset = !content.strip.empty??
|
102
|
+
"#{path.reject(&:empty?).join.strip} {#{content}}\n" : ""
|
103
|
+
|
104
|
+
css = ruleset + elements.map do |i|
|
105
|
+
i.to_css(path)
|
106
|
+
end.reject(&:empty?).join
|
107
|
+
path.pop; path.pop
|
108
|
+
css
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Find the nearest variable in the hierarchy or raise a NameError
|
113
|
+
#
|
114
|
+
def nearest ident
|
115
|
+
ary = ident =~ /^[.#]/ ? :elements : :variables
|
116
|
+
path.map do |node|
|
117
|
+
node.send(ary).find {|i| i.to_s == ident }
|
118
|
+
end.compact.first.tap do |result|
|
119
|
+
raise VariableNameError, ident unless result
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Traverse the whole tree, returning each leaf (recursive)
|
125
|
+
#
|
126
|
+
def each path = [], &blk
|
127
|
+
elements.each do |element|
|
128
|
+
path << element
|
129
|
+
yield element, path if element.leaf?
|
130
|
+
element.each path, &blk
|
131
|
+
path.pop
|
132
|
+
end
|
133
|
+
self
|
134
|
+
end
|
135
|
+
alias :traverse :each
|
136
|
+
|
137
|
+
def inspect depth = 0
|
138
|
+
indent = lambda {|i| '. ' * i }
|
139
|
+
put = lambda {|ary| ary.map {|i| indent[ depth + 1 ] + i.inspect } * "\n"}
|
140
|
+
|
141
|
+
(root?? "\n" : "") + [
|
142
|
+
indent[ depth ] + (self == '' ? '*' : self.to_s),
|
143
|
+
put[ properties ],
|
144
|
+
put[ variables ],
|
145
|
+
elements.map {|i| i.inspect( depth + 1 ) } * "\n"
|
146
|
+
].reject(&:empty?).join("\n") + "\n" + indent[ depth ]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Less
|
2
|
+
#
|
3
|
+
# Node::Entity
|
4
|
+
#
|
5
|
+
# Everything in the tree is an Entity
|
6
|
+
#
|
7
|
+
# Mixin/Class hierarchy
|
8
|
+
#
|
9
|
+
# - Entity
|
10
|
+
# - Element
|
11
|
+
# - Entity
|
12
|
+
# - Function
|
13
|
+
# - Keyword
|
14
|
+
# - Literal
|
15
|
+
# - Color
|
16
|
+
# - Number
|
17
|
+
# - String
|
18
|
+
# - FontFamily
|
19
|
+
# - Property
|
20
|
+
# - Variable
|
21
|
+
#
|
22
|
+
# TODO: Use delegate class -> @rules
|
23
|
+
#
|
24
|
+
module Node
|
25
|
+
module Entity
|
26
|
+
attr_accessor :parent
|
27
|
+
|
28
|
+
def initialize value, parent = nil
|
29
|
+
super value
|
30
|
+
@parent = parent
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Returns the path from any given node, to the root
|
35
|
+
#
|
36
|
+
# ex: ['color', 'p', '#header', 'body', '*']
|
37
|
+
#
|
38
|
+
def path node = self
|
39
|
+
path = []
|
40
|
+
while node do
|
41
|
+
path << node
|
42
|
+
node = node.parent
|
43
|
+
end
|
44
|
+
path
|
45
|
+
end
|
46
|
+
|
47
|
+
def root
|
48
|
+
path.last
|
49
|
+
end
|
50
|
+
|
51
|
+
def inspect; to_s end
|
52
|
+
def to_css; to_s end
|
53
|
+
def to_s; super end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# An anonymous node, for all the 'other' stuff
|
58
|
+
# which doesn't need any specific functionality.
|
59
|
+
#
|
60
|
+
class Anonymous < ::String
|
61
|
+
include Entity
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# + * - /
|
66
|
+
#
|
67
|
+
class Operator < ::String
|
68
|
+
def to_ruby
|
69
|
+
self
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Less
|
2
|
+
#
|
3
|
+
# Functions useable from within the style-sheet go here
|
4
|
+
#
|
5
|
+
module Functions
|
6
|
+
def rgb *rgb
|
7
|
+
rgba rgb, 1.0
|
8
|
+
end
|
9
|
+
|
10
|
+
def hsl *args
|
11
|
+
hsla args, 1.0
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# RGBA to Node::Color
|
16
|
+
#
|
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
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# HSLA to RGBA
|
29
|
+
#
|
30
|
+
def hsla h, s, l, a = 1.0
|
31
|
+
m2 = ( l <= 0.5 ) ? l * ( s + 1 ) : l + s - l * s
|
32
|
+
m1 = l * 2 - m2;
|
33
|
+
|
34
|
+
hue = lambda do |h|
|
35
|
+
h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h)
|
36
|
+
if h * 6 < 1 then m1 + (m2 - m1) * h * 6
|
37
|
+
elsif h * 2 < 1 then m2
|
38
|
+
elsif h * 3 < 2 then m1 + (m2 - m1) * (2/3 - h) * 6
|
39
|
+
else m1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
rgba hue[ h + 1/3 ], hue[ h ], hue[ h - 1/3 ], a
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Node
|
48
|
+
#
|
49
|
+
# A CSS function, like rgb() or url()
|
50
|
+
#
|
51
|
+
# it calls functions from the Functions module
|
52
|
+
#
|
53
|
+
class Function < ::String
|
54
|
+
include Functions
|
55
|
+
include Entity
|
56
|
+
|
57
|
+
def initialize name, *args
|
58
|
+
@args = args.flatten
|
59
|
+
super name
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_css
|
63
|
+
self.evaluate.to_css
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Call the function
|
68
|
+
#
|
69
|
+
def evaluate
|
70
|
+
send self.to_sym, *@args
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# If the function isn't found, we just print it out,
|
75
|
+
# this is the case for url(), for example,
|
76
|
+
#
|
77
|
+
def method_missing meth, *args
|
78
|
+
Node::Anonymous.new("#{meth}(#{args.map(&:to_css) * ', '})")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Less
|
2
|
+
module Node
|
3
|
+
module Literal
|
4
|
+
include Entity
|
5
|
+
|
6
|
+
def unit
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# rgb(255, 0, 0) #f0f0f0
|
13
|
+
#
|
14
|
+
class Color < DelegateClass(Fixnum)
|
15
|
+
include Literal
|
16
|
+
attr_reader :color
|
17
|
+
|
18
|
+
def initialize color = nil, opacity = 1.0
|
19
|
+
@color = if color.is_a? Array
|
20
|
+
rgba color
|
21
|
+
elsif color.is_a? ::String
|
22
|
+
color.delete! unit
|
23
|
+
(color * ( color.length < 6 ? 6 / color.length : 1 )).to_i 16
|
24
|
+
else
|
25
|
+
color
|
26
|
+
end
|
27
|
+
super @color.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def unit
|
31
|
+
'#'
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_css
|
35
|
+
unit + (self <= 0 ? '0' * 6 : self.to_i.to_s(16))
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_ruby
|
39
|
+
color
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"#{unit}#{super}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect; to_s end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# 6 10px 125%
|
51
|
+
#
|
52
|
+
class Number < DelegateClass(Float)
|
53
|
+
include Literal
|
54
|
+
|
55
|
+
attr_accessor :unit
|
56
|
+
|
57
|
+
def initialize value, unit = nil
|
58
|
+
super value.to_f
|
59
|
+
@unit = (unit.nil? || unit.empty?) ? nil : unit
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
"#{super}#@unit"
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_ruby
|
67
|
+
self.to_f
|
68
|
+
end
|
69
|
+
|
70
|
+
def inspect
|
71
|
+
to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_css
|
75
|
+
"#{(self % 1).zero?? "#{self.to_i}#@unit" : self}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# "hello world"
|
81
|
+
#
|
82
|
+
class String < ::String
|
83
|
+
include Literal
|
84
|
+
|
85
|
+
attr_reader :quotes, :content
|
86
|
+
|
87
|
+
# Strip quotes if necessary, and save them in @quotes
|
88
|
+
def initialize str
|
89
|
+
@quotes, @content = unless str.nil? or str.empty?
|
90
|
+
str.match(/('|")(.*?)(\1)/).captures rescue [nil, str]
|
91
|
+
else
|
92
|
+
[nil, ""]
|
93
|
+
end
|
94
|
+
super @content
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_css
|
98
|
+
"#@quotes#{@content}#@quotes"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Font
|
103
|
+
include Literal
|
104
|
+
end
|
105
|
+
|
106
|
+
class FontFamily < Array
|
107
|
+
include Literal
|
108
|
+
|
109
|
+
def initialize family = []
|
110
|
+
super family
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_css
|
114
|
+
self.map(&:to_css) * ', '
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Any un-quoted word
|
120
|
+
#
|
121
|
+
# ex: red, small, border-collapse
|
122
|
+
#
|
123
|
+
class Keyword < ::String
|
124
|
+
include Entity
|
125
|
+
|
126
|
+
def to_css
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
def inspect
|
131
|
+
"#{self}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|