sass 3.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +11 -0
- data/CONTRIBUTING +3 -0
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/REVISION +1 -0
- data/Rakefile +353 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/css2sass +13 -0
- data/bin/sass +8 -0
- data/bin/sass-convert +7 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass.rb +71 -0
- data/lib/sass/cache_store.rb +208 -0
- data/lib/sass/callbacks.rb +66 -0
- data/lib/sass/css.rb +294 -0
- data/lib/sass/engine.rb +792 -0
- data/lib/sass/environment.rb +143 -0
- data/lib/sass/error.rb +201 -0
- data/lib/sass/exec.rb +619 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/importers/base.rb +138 -0
- data/lib/sass/importers/filesystem.rb +121 -0
- data/lib/sass/less.rb +363 -0
- data/lib/sass/plugin.rb +126 -0
- data/lib/sass/plugin/compiler.rb +346 -0
- data/lib/sass/plugin/configuration.rb +123 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +47 -0
- data/lib/sass/plugin/rails.rb +41 -0
- data/lib/sass/plugin/staleness_checker.rb +145 -0
- data/lib/sass/railtie.rb +8 -0
- data/lib/sass/repl.rb +58 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script.rb +63 -0
- data/lib/sass/script/bool.rb +18 -0
- data/lib/sass/script/color.rb +490 -0
- data/lib/sass/script/css_lexer.rb +29 -0
- data/lib/sass/script/css_parser.rb +31 -0
- data/lib/sass/script/funcall.rb +78 -0
- data/lib/sass/script/functions.rb +852 -0
- data/lib/sass/script/interpolation.rb +70 -0
- data/lib/sass/script/lexer.rb +337 -0
- data/lib/sass/script/literal.rb +236 -0
- data/lib/sass/script/node.rb +101 -0
- data/lib/sass/script/number.rb +420 -0
- data/lib/sass/script/operation.rb +92 -0
- data/lib/sass/script/parser.rb +392 -0
- data/lib/sass/script/string.rb +67 -0
- data/lib/sass/script/string_interpolation.rb +93 -0
- data/lib/sass/script/unary_operation.rb +57 -0
- data/lib/sass/script/variable.rb +48 -0
- data/lib/sass/scss.rb +17 -0
- data/lib/sass/scss/css_parser.rb +51 -0
- data/lib/sass/scss/parser.rb +838 -0
- data/lib/sass/scss/rx.rb +126 -0
- data/lib/sass/scss/sass_parser.rb +11 -0
- data/lib/sass/scss/script_lexer.rb +15 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/scss/static_parser.rb +40 -0
- data/lib/sass/selector.rb +361 -0
- data/lib/sass/selector/abstract_sequence.rb +62 -0
- data/lib/sass/selector/comma_sequence.rb +82 -0
- data/lib/sass/selector/sequence.rb +236 -0
- data/lib/sass/selector/simple.rb +113 -0
- data/lib/sass/selector/simple_sequence.rb +135 -0
- data/lib/sass/shared.rb +78 -0
- data/lib/sass/tree/comment_node.rb +128 -0
- data/lib/sass/tree/debug_node.rb +36 -0
- data/lib/sass/tree/directive_node.rb +75 -0
- data/lib/sass/tree/extend_node.rb +65 -0
- data/lib/sass/tree/for_node.rb +67 -0
- data/lib/sass/tree/if_node.rb +81 -0
- data/lib/sass/tree/import_node.rb +124 -0
- data/lib/sass/tree/mixin_def_node.rb +60 -0
- data/lib/sass/tree/mixin_node.rb +123 -0
- data/lib/sass/tree/node.rb +490 -0
- data/lib/sass/tree/prop_node.rb +220 -0
- data/lib/sass/tree/root_node.rb +125 -0
- data/lib/sass/tree/rule_node.rb +273 -0
- data/lib/sass/tree/variable_node.rb +39 -0
- data/lib/sass/tree/warn_node.rb +42 -0
- data/lib/sass/tree/while_node.rb +48 -0
- data/lib/sass/util.rb +687 -0
- data/lib/sass/util/subset_map.rb +101 -0
- data/lib/sass/version.rb +109 -0
- data/rails/init.rb +1 -0
- data/test/sass/cache_test.rb +74 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/conversion_test.rb +1210 -0
- data/test/sass/css2sass_test.rb +364 -0
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/engine_test.rb +2273 -0
- data/test/sass/extend_test.rb +1348 -0
- data/test/sass/functions_test.rb +565 -0
- data/test/sass/importer_test.rb +104 -0
- data/test/sass/less_conversion_test.rb +632 -0
- data/test/sass/mock_importer.rb +49 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +430 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +86 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +31 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/scss_import.css +31 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +254 -0
- data/test/sass/script_test.rb +459 -0
- data/test/sass/scss/css_test.rb +897 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +1088 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +305 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +12 -0
- data/test/sass/templates/importee.less +2 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/scss_import.scss +11 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/sass/templates/warn.sass +3 -0
- data/test/sass/templates/warn_imported.sass +4 -0
- data/test/sass/test_helper.rb +8 -0
- data/test/sass/util/subset_map_test.rb +91 -0
- data/test/sass/util_test.rb +275 -0
- data/test/test_helper.rb +64 -0
- data/vendor/fssm/LICENSE +20 -0
- data/vendor/fssm/README.markdown +55 -0
- data/vendor/fssm/Rakefile +59 -0
- data/vendor/fssm/VERSION.yml +5 -0
- data/vendor/fssm/example.rb +9 -0
- data/vendor/fssm/fssm.gemspec +77 -0
- data/vendor/fssm/lib/fssm.rb +33 -0
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
- data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
- data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
- data/vendor/fssm/lib/fssm/monitor.rb +26 -0
- data/vendor/fssm/lib/fssm/path.rb +91 -0
- data/vendor/fssm/lib/fssm/pathname.rb +502 -0
- data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
- data/vendor/fssm/lib/fssm/state/file.rb +24 -0
- data/vendor/fssm/lib/fssm/support.rb +63 -0
- data/vendor/fssm/lib/fssm/tree.rb +176 -0
- data/vendor/fssm/profile/prof-cache.rb +40 -0
- data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
- data/vendor/fssm/profile/prof-pathname.rb +68 -0
- data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
- data/vendor/fssm/profile/prof.html +2379 -0
- data/vendor/fssm/spec/path_spec.rb +75 -0
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +14 -0
- metadata +297 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
module Sass::Tree
|
2
|
+
# A static node reprenting a CSS property.
|
3
|
+
#
|
4
|
+
# @see Sass::Tree
|
5
|
+
class PropNode < Node
|
6
|
+
# The name of the property,
|
7
|
+
# interspersed with {Sass::Script::Node}s
|
8
|
+
# representing `#{}`-interpolation.
|
9
|
+
# Any adjacent strings will be merged together.
|
10
|
+
#
|
11
|
+
# @return [Array<String, Sass::Script::Node>]
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
# The name of the property
|
15
|
+
# after any interpolated SassScript has been resolved.
|
16
|
+
# Only set once \{Tree::Node#perform} has been called.
|
17
|
+
#
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :resolved_name
|
20
|
+
|
21
|
+
# The value of the property.
|
22
|
+
#
|
23
|
+
# @return [Sass::Script::Node]
|
24
|
+
attr_accessor :value
|
25
|
+
|
26
|
+
# The value of the property
|
27
|
+
# after any interpolated SassScript has been resolved.
|
28
|
+
# Only set once \{Tree::Node#perform} has been called.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
attr_accessor :resolved_value
|
32
|
+
|
33
|
+
# How deep this property is indented
|
34
|
+
# relative to a normal property.
|
35
|
+
# This is only greater than 0 in the case that:
|
36
|
+
#
|
37
|
+
# * This node is in a CSS tree
|
38
|
+
# * The style is :nested
|
39
|
+
# * This is a child property of another property
|
40
|
+
# * The parent property has a value, and thus will be rendered
|
41
|
+
#
|
42
|
+
# @return [Fixnum]
|
43
|
+
attr_accessor :tabs
|
44
|
+
|
45
|
+
# @param name [Array<String, Sass::Script::Node>] See \{#name}
|
46
|
+
# @param value [Sass::Script::Node] See \{#value}
|
47
|
+
# @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
|
48
|
+
# `:old` if it uses `:a b`-style syntax
|
49
|
+
def initialize(name, value, prop_syntax)
|
50
|
+
@name = Sass::Util.strip_string_array(
|
51
|
+
Sass::Util.merge_adjacent_strings(name))
|
52
|
+
@value = value
|
53
|
+
@tabs = 0
|
54
|
+
@prop_syntax = prop_syntax
|
55
|
+
super()
|
56
|
+
end
|
57
|
+
|
58
|
+
# Compares the names and values of two properties.
|
59
|
+
#
|
60
|
+
# @param other [Object] The object to compare with
|
61
|
+
# @return [Boolean] Whether or not this node and the other object
|
62
|
+
# are the same
|
63
|
+
def ==(other)
|
64
|
+
self.class == other.class && name == other.name && value == other.value && super
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a appropriate message indicating how to escape pseudo-class selectors.
|
68
|
+
# This only applies for old-style properties with no value,
|
69
|
+
# so returns the empty string if this is new-style.
|
70
|
+
#
|
71
|
+
# @return [String] The message
|
72
|
+
def pseudo_class_selector_message
|
73
|
+
return "" if @prop_syntax == :new || !value.is_a?(Sass::Script::String) || !value.value.empty?
|
74
|
+
"\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
# @see Node#to_src
|
80
|
+
def to_src(tabs, opts, fmt)
|
81
|
+
res = declaration(tabs, opts, fmt)
|
82
|
+
return res + "#{semi fmt}\n" if children.empty?
|
83
|
+
res + children_to_src(tabs, opts, fmt).rstrip + semi(fmt) + "\n"
|
84
|
+
end
|
85
|
+
|
86
|
+
# Computes the CSS for the property.
|
87
|
+
#
|
88
|
+
# @param tabs [Fixnum] The level of indentation for the CSS
|
89
|
+
# @return [String] The resulting CSS
|
90
|
+
def _to_s(tabs)
|
91
|
+
to_return = ' ' * (tabs - 1 + self.tabs) + resolved_name + ":" +
|
92
|
+
(style == :compressed ? '' : ' ') + resolved_value + (style == :compressed ? "" : ";")
|
93
|
+
end
|
94
|
+
|
95
|
+
# Converts nested properties into flat properties.
|
96
|
+
#
|
97
|
+
# @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
|
98
|
+
# The extensions defined for this tree
|
99
|
+
# @param parent [PropNode, nil] The parent node of this node,
|
100
|
+
# or nil if the parent isn't a {PropNode}
|
101
|
+
# @raise [Sass::SyntaxError] if the property uses invalid syntax
|
102
|
+
def _cssize(extends, parent)
|
103
|
+
node = super
|
104
|
+
result = node.children.dup
|
105
|
+
if !node.resolved_value.empty? || node.children.empty?
|
106
|
+
node.send(:check!)
|
107
|
+
result.unshift(node)
|
108
|
+
end
|
109
|
+
result
|
110
|
+
end
|
111
|
+
|
112
|
+
# Updates the name and indentation of this node based on the parent name
|
113
|
+
# and nesting level.
|
114
|
+
#
|
115
|
+
# @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
|
116
|
+
# The extensions defined for this tree
|
117
|
+
# @param parent [PropNode, nil] The parent node of this node,
|
118
|
+
# or nil if the parent isn't a {PropNode}
|
119
|
+
def cssize!(extends, parent)
|
120
|
+
self.resolved_name = "#{parent.resolved_name}-#{resolved_name}" if parent
|
121
|
+
self.tabs = parent.tabs + (parent.resolved_value.empty? ? 0 : 1) if parent && style == :nested
|
122
|
+
super
|
123
|
+
end
|
124
|
+
|
125
|
+
# Runs any SassScript that may be embedded in the property,
|
126
|
+
# and invludes the parent property, if any.
|
127
|
+
#
|
128
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
129
|
+
# variable and mixin values
|
130
|
+
def perform!(environment)
|
131
|
+
@resolved_name = run_interp(@name, environment)
|
132
|
+
val = @value.perform(environment)
|
133
|
+
@resolved_value =
|
134
|
+
if @value.context == :equals && val.is_a?(Sass::Script::String)
|
135
|
+
val.value
|
136
|
+
else
|
137
|
+
val.to_s
|
138
|
+
end
|
139
|
+
super
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns an error message if the given child node is invalid,
|
143
|
+
# and false otherwise.
|
144
|
+
#
|
145
|
+
# {PropNode} only allows other {PropNode}s and {CommentNode}s as children.
|
146
|
+
# @param child [Tree::Node] A potential child node
|
147
|
+
# @return [String] An error message if the child is invalid, or nil otherwise
|
148
|
+
def invalid_child?(child)
|
149
|
+
if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
|
150
|
+
"Illegal nesting: Only properties may be nested beneath properties."
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def check!
|
157
|
+
if @options[:property_syntax] == :old && @prop_syntax == :new
|
158
|
+
raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
|
159
|
+
elsif @options[:property_syntax] == :new && @prop_syntax == :old
|
160
|
+
raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
|
161
|
+
elsif resolved_value.empty?
|
162
|
+
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
|
163
|
+
pseudo_class_selector_message)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def declaration(tabs = 0, opts = {:old => @prop_syntax == :old}, fmt = :sass)
|
168
|
+
name = self.name.map {|n| n.is_a?(String) ? n : "\#{#{n.to_sass(opts)}}"}.join
|
169
|
+
if name[0] == ?:
|
170
|
+
raise Sass::SyntaxError.new("The \"#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
|
171
|
+
end
|
172
|
+
|
173
|
+
old = opts[:old] && fmt == :sass
|
174
|
+
initial = old ? ':' : ''
|
175
|
+
mid = old ? '' : ':'
|
176
|
+
"#{' ' * tabs}#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
|
177
|
+
end
|
178
|
+
|
179
|
+
class << self
|
180
|
+
# @private
|
181
|
+
def val_to_sass(value, opts)
|
182
|
+
val_to_sass_comma(value, opts).to_sass(opts)
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def val_to_sass_comma(node, opts)
|
188
|
+
return node unless node.is_a?(Sass::Script::Operation)
|
189
|
+
return val_to_sass_concat(node, opts) unless node.operator == :comma
|
190
|
+
|
191
|
+
Sass::Script::Operation.new(
|
192
|
+
val_to_sass_concat(node.operand1, opts),
|
193
|
+
val_to_sass_comma(node.operand2, opts),
|
194
|
+
node.operator)
|
195
|
+
end
|
196
|
+
|
197
|
+
def val_to_sass_concat(node, opts)
|
198
|
+
return node unless node.is_a?(Sass::Script::Operation)
|
199
|
+
return val_to_sass_div(node, opts) unless node.operator == :concat
|
200
|
+
|
201
|
+
Sass::Script::Operation.new(
|
202
|
+
val_to_sass_div(node.operand1, opts),
|
203
|
+
val_to_sass_concat(node.operand2, opts),
|
204
|
+
node.operator)
|
205
|
+
end
|
206
|
+
|
207
|
+
def val_to_sass_div(node, opts)
|
208
|
+
unless node.is_a?(Sass::Script::Operation) && node.operator == :div &&
|
209
|
+
node.operand1.is_a?(Sass::Script::Number) &&
|
210
|
+
node.operand2.is_a?(Sass::Script::Number) &&
|
211
|
+
(node.context == :equals || !node.operand1.original || !node.operand2.original)
|
212
|
+
return node
|
213
|
+
end
|
214
|
+
|
215
|
+
Sass::Script::String.new("(#{node.to_sass(opts)})")
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Sass
|
2
|
+
module Tree
|
3
|
+
# A static node that is the root node of the Sass document.
|
4
|
+
class RootNode < Node
|
5
|
+
# The Sass template from which this node was created
|
6
|
+
#
|
7
|
+
# @param template [String]
|
8
|
+
attr_reader :template
|
9
|
+
|
10
|
+
# @param template [String] The Sass template from which this node was created
|
11
|
+
def initialize(template)
|
12
|
+
super()
|
13
|
+
@template = template
|
14
|
+
end
|
15
|
+
|
16
|
+
# @see Node#to_s
|
17
|
+
def to_s(*args)
|
18
|
+
super
|
19
|
+
rescue Sass::SyntaxError => e
|
20
|
+
e.sass_template = @template
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
|
24
|
+
# Runs the dynamic Sass code *and* computes the CSS for the tree.
|
25
|
+
#
|
26
|
+
# @see #perform
|
27
|
+
# @see #to_s
|
28
|
+
def render
|
29
|
+
result, extends = perform(Environment.new).cssize
|
30
|
+
result = result.do_extend(extends) unless extends.empty?
|
31
|
+
result.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# @see Node#perform
|
35
|
+
def perform(environment)
|
36
|
+
environment.options = @options if environment.options.nil? || environment.options.empty?
|
37
|
+
super
|
38
|
+
rescue Sass::SyntaxError => e
|
39
|
+
e.sass_template = @template
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
|
43
|
+
# Like {Node#cssize}, except that this method
|
44
|
+
# will create its own `extends` map if necessary,
|
45
|
+
# and it returns that map along with the cssized tree.
|
46
|
+
#
|
47
|
+
# @return [(Tree::Node, Sass::Util::SubsetMap)] The resulting tree of static nodes
|
48
|
+
# *and* the extensions defined for this tree
|
49
|
+
def cssize(extends = Sass::Util::SubsetMap.new, parent = nil)
|
50
|
+
return super(extends), extends
|
51
|
+
rescue Sass::SyntaxError => e
|
52
|
+
e.sass_template = @template
|
53
|
+
raise e
|
54
|
+
end
|
55
|
+
|
56
|
+
# @see \{Node#perform!}
|
57
|
+
def perform!(environment)
|
58
|
+
environment.options = @options if environment.options.nil? || environment.options.empty?
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
# Converts a node to Sass code that will generate it.
|
63
|
+
#
|
64
|
+
# @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
|
65
|
+
# @return [String] The Sass code corresponding to the node
|
66
|
+
def to_sass(opts = {})
|
67
|
+
to_src(opts, :sass)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Converts a node to SCSS code that will generate it.
|
71
|
+
#
|
72
|
+
# @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
|
73
|
+
# @return [String] The SCSS code corresponding to the node
|
74
|
+
def to_scss(opts = {})
|
75
|
+
to_src(opts, :scss)
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
# @see Node#to_src
|
81
|
+
def to_src(opts, fmt)
|
82
|
+
Sass::Util.enum_cons(children + [nil], 2).map do |child, nxt|
|
83
|
+
child.send("to_#{fmt}", 0, opts) +
|
84
|
+
if nxt &&
|
85
|
+
(child.is_a?(CommentNode) && child.line + child.value.count("\n") + 1 == nxt.line) ||
|
86
|
+
(child.is_a?(ImportNode) && nxt.is_a?(ImportNode) && child.line + 1 == nxt.line) ||
|
87
|
+
(child.is_a?(VariableNode) && nxt.is_a?(VariableNode) && child.line + 1 == nxt.line)
|
88
|
+
""
|
89
|
+
else
|
90
|
+
"\n"
|
91
|
+
end
|
92
|
+
end.join.rstrip + "\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
# Computes the CSS corresponding to this Sass tree.
|
96
|
+
#
|
97
|
+
# @param args [Array] ignored
|
98
|
+
# @return [String] The resulting CSS
|
99
|
+
# @see Sass::Tree
|
100
|
+
def _to_s(*args)
|
101
|
+
result = String.new
|
102
|
+
children.each do |child|
|
103
|
+
next if child.invisible?
|
104
|
+
child_str = child.to_s(1)
|
105
|
+
result << child_str + (style == :compressed ? '' : "\n")
|
106
|
+
end
|
107
|
+
result.rstrip!
|
108
|
+
return "" if result.empty?
|
109
|
+
return result + "\n"
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns an error message if the given child node is invalid,
|
113
|
+
# and false otherwise.
|
114
|
+
#
|
115
|
+
# Only property nodes are invalid at root level.
|
116
|
+
#
|
117
|
+
# @see Node#invalid_child?
|
118
|
+
def invalid_child?(child)
|
119
|
+
return unless child.is_a?(Tree::PropNode)
|
120
|
+
"Properties aren't allowed at the root of a document." +
|
121
|
+
child.pseudo_class_selector_message
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Sass::Tree
|
5
|
+
# A static node reprenting a CSS rule.
|
6
|
+
#
|
7
|
+
# @see Sass::Tree
|
8
|
+
class RuleNode < Node
|
9
|
+
# The character used to include the parent selector
|
10
|
+
PARENT = '&'
|
11
|
+
|
12
|
+
# The CSS selector for this rule,
|
13
|
+
# interspersed with {Sass::Script::Node}s
|
14
|
+
# representing `#{}`-interpolation.
|
15
|
+
# Any adjacent strings will be merged together.
|
16
|
+
#
|
17
|
+
# @return [Array<String, Sass::Script::Node>]
|
18
|
+
attr_accessor :rule
|
19
|
+
|
20
|
+
# The CSS selector for this rule,
|
21
|
+
# without any unresolved interpolation
|
22
|
+
# but with parent references still intact.
|
23
|
+
# It's only set once {Tree::Node#perform} has been called.
|
24
|
+
#
|
25
|
+
# @return [Selector::CommaSequence]
|
26
|
+
attr_accessor :parsed_rules
|
27
|
+
|
28
|
+
# The CSS selector for this rule,
|
29
|
+
# without any unresolved interpolation or parent references.
|
30
|
+
# It's only set once {Tree::Node#cssize} has been called.
|
31
|
+
#
|
32
|
+
# @return [Selector::CommaSequence]
|
33
|
+
attr_accessor :resolved_rules
|
34
|
+
|
35
|
+
# How deep this rule is indented
|
36
|
+
# relative to a base-level rule.
|
37
|
+
# This is only greater than 0 in the case that:
|
38
|
+
#
|
39
|
+
# * This node is in a CSS tree
|
40
|
+
# * The style is :nested
|
41
|
+
# * This is a child rule of another rule
|
42
|
+
# * The parent rule has properties, and thus will be rendered
|
43
|
+
#
|
44
|
+
# @return [Fixnum]
|
45
|
+
attr_accessor :tabs
|
46
|
+
|
47
|
+
# Whether or not this rule is the last rule in a nested group.
|
48
|
+
# This is only set in a CSS tree.
|
49
|
+
#
|
50
|
+
# @return [Boolean]
|
51
|
+
attr_accessor :group_end
|
52
|
+
|
53
|
+
# @param rule [Array<String, Sass::Script::Node>]
|
54
|
+
# The CSS rule. See \{#rule}
|
55
|
+
def initialize(rule)
|
56
|
+
#p rule
|
57
|
+
merged = Sass::Util.merge_adjacent_strings(rule)
|
58
|
+
#p merged
|
59
|
+
@rule = Sass::Util.strip_string_array(merged)
|
60
|
+
#p @rule
|
61
|
+
@tabs = 0
|
62
|
+
super()
|
63
|
+
end
|
64
|
+
|
65
|
+
# Compares the contents of two rules.
|
66
|
+
#
|
67
|
+
# @param other [Object] The object to compare with
|
68
|
+
# @return [Boolean] Whether or not this node and the other object
|
69
|
+
# are the same
|
70
|
+
def ==(other)
|
71
|
+
self.class == other.class && rule == other.rule && super
|
72
|
+
end
|
73
|
+
|
74
|
+
# Adds another {RuleNode}'s rules to this one's.
|
75
|
+
#
|
76
|
+
# @param node [RuleNode] The other node
|
77
|
+
def add_rules(node)
|
78
|
+
@rule = Sass::Util.strip_string_array(
|
79
|
+
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Boolean] Whether or not this rule is continued on the next line
|
83
|
+
def continued?
|
84
|
+
last = @rule.last
|
85
|
+
last.is_a?(String) && last[-1] == ?,
|
86
|
+
end
|
87
|
+
|
88
|
+
# @see Node#to_sass
|
89
|
+
def to_sass(tabs, opts = {})
|
90
|
+
name = selector_to_sass(rule, opts)
|
91
|
+
name = "\\" + name if name[0] == ?:
|
92
|
+
name.gsub(/^/, ' ' * tabs) + children_to_src(tabs, opts, :sass)
|
93
|
+
end
|
94
|
+
|
95
|
+
# @see Node#to_scss
|
96
|
+
def to_scss(tabs, opts = {})
|
97
|
+
name = selector_to_scss(rule, tabs, opts)
|
98
|
+
res = name + children_to_src(tabs, opts, :scss)
|
99
|
+
|
100
|
+
if children.last.is_a?(CommentNode) && children.last.silent
|
101
|
+
res.slice!(-3..-1)
|
102
|
+
res << "\n" << (' ' * tabs) << "}\n"
|
103
|
+
end
|
104
|
+
|
105
|
+
res
|
106
|
+
end
|
107
|
+
|
108
|
+
# Extends this Rule's selector with the given `extends`.
|
109
|
+
#
|
110
|
+
# @see Node#do_extend
|
111
|
+
def do_extend(extends)
|
112
|
+
node = dup
|
113
|
+
node.resolved_rules = resolved_rules.do_extend(extends)
|
114
|
+
node
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
# Computes the CSS for the rule.
|
120
|
+
#
|
121
|
+
# @param tabs [Fixnum] The level of indentation for the CSS
|
122
|
+
# @return [String] The resulting CSS
|
123
|
+
def _to_s(tabs)
|
124
|
+
tabs = tabs + self.tabs
|
125
|
+
|
126
|
+
rule_separator = style == :compressed ? ',' : ', '
|
127
|
+
line_separator =
|
128
|
+
case style
|
129
|
+
when :nested, :expanded; "\n"
|
130
|
+
when :compressed; ""
|
131
|
+
else; " "
|
132
|
+
end
|
133
|
+
rule_indent = ' ' * (tabs - 1)
|
134
|
+
per_rule_indent, total_indent = [:nested, :expanded].include?(style) ? [rule_indent, ''] : ['', rule_indent]
|
135
|
+
|
136
|
+
total_rule = total_indent + resolved_rules.members.
|
137
|
+
map {|seq| seq.to_a.join.gsub("\n", style == :compressed ? " " : "\n")}.
|
138
|
+
join(rule_separator).split("\n").map do |line|
|
139
|
+
per_rule_indent + line.strip
|
140
|
+
end.join(line_separator)
|
141
|
+
|
142
|
+
to_return = ''
|
143
|
+
old_spaces = ' ' * (tabs - 1)
|
144
|
+
spaces = ' ' * tabs
|
145
|
+
if style != :compressed
|
146
|
+
if @options[:debug_info]
|
147
|
+
to_return << debug_info_rule.to_s(tabs) << "\n"
|
148
|
+
elsif @options[:line_comments]
|
149
|
+
to_return << "#{old_spaces}/* line #{line}"
|
150
|
+
|
151
|
+
if filename
|
152
|
+
relative_filename = if @options[:css_filename]
|
153
|
+
begin
|
154
|
+
Pathname.new(filename).relative_path_from(
|
155
|
+
Pathname.new(File.dirname(@options[:css_filename]))).to_s
|
156
|
+
rescue ArgumentError
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
end
|
160
|
+
relative_filename ||= filename
|
161
|
+
to_return << ", #{relative_filename}"
|
162
|
+
end
|
163
|
+
|
164
|
+
to_return << " */\n"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if style == :compact
|
169
|
+
properties = children.map { |a| a.to_s(1) }.join(' ')
|
170
|
+
to_return << "#{total_rule} { #{properties} }#{"\n" if group_end}"
|
171
|
+
elsif style == :compressed
|
172
|
+
properties = children.map { |a| a.to_s(1) }.join(';')
|
173
|
+
to_return << "#{total_rule}{#{properties}}"
|
174
|
+
else
|
175
|
+
properties = children.map { |a| a.to_s(tabs + 1) }.join("\n")
|
176
|
+
end_props = (style == :expanded ? "\n" + old_spaces : ' ')
|
177
|
+
to_return << "#{total_rule} {\n#{properties}#{end_props}}#{"\n" if group_end}"
|
178
|
+
end
|
179
|
+
|
180
|
+
to_return
|
181
|
+
end
|
182
|
+
|
183
|
+
# Runs SassScript interpolation in the selector,
|
184
|
+
# and then parses the result into a {Sass::Selector::CommaSequence}.
|
185
|
+
#
|
186
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
187
|
+
# variable and mixin values
|
188
|
+
def perform!(environment)
|
189
|
+
@parsed_rules = Sass::SCSS::StaticParser.new(run_interp(@rule, environment), self.line).
|
190
|
+
parse_selector(self.filename)
|
191
|
+
super
|
192
|
+
end
|
193
|
+
|
194
|
+
# Converts nested rules into a flat list of rules.
|
195
|
+
#
|
196
|
+
# @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
|
197
|
+
# The extensions defined for this tree
|
198
|
+
# @param parent [RuleNode, nil] The parent node of this node,
|
199
|
+
# or nil if the parent isn't a {RuleNode}
|
200
|
+
def _cssize(extends, parent)
|
201
|
+
node = super
|
202
|
+
rules = node.children.select {|c| c.is_a?(RuleNode)}
|
203
|
+
props = node.children.reject {|c| c.is_a?(RuleNode) || c.invisible?}
|
204
|
+
|
205
|
+
unless props.empty?
|
206
|
+
node.children = props
|
207
|
+
rules.each {|r| r.tabs += 1} if style == :nested
|
208
|
+
rules.unshift(node)
|
209
|
+
end
|
210
|
+
|
211
|
+
rules.last.group_end = true unless parent || rules.empty?
|
212
|
+
|
213
|
+
rules
|
214
|
+
end
|
215
|
+
|
216
|
+
# Resolves parent references and nested selectors,
|
217
|
+
# and updates the indentation based on the parent's indentation.
|
218
|
+
#
|
219
|
+
# @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
|
220
|
+
# The extensions defined for this tree
|
221
|
+
# @param parent [RuleNode, nil] The parent node of this node,
|
222
|
+
# or nil if the parent isn't a {RuleNode}
|
223
|
+
# @raise [Sass::SyntaxError] if the rule has no parents but uses `&`
|
224
|
+
def cssize!(extends, parent)
|
225
|
+
self.resolved_rules = @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
|
226
|
+
super
|
227
|
+
end
|
228
|
+
|
229
|
+
# Returns an error message if the given child node is invalid,
|
230
|
+
# and false otherwise.
|
231
|
+
#
|
232
|
+
# {ExtendNode}s are valid within {RuleNode}s.
|
233
|
+
#
|
234
|
+
# @param child [Tree::Node] A potential child node.
|
235
|
+
# @return [Boolean, String] Whether or not the child node is valid,
|
236
|
+
# as well as the error message to display if it is invalid
|
237
|
+
def invalid_child?(child)
|
238
|
+
super unless child.is_a?(ExtendNode)
|
239
|
+
end
|
240
|
+
|
241
|
+
# A hash that will be associated with this rule in the CSS document
|
242
|
+
# if the {file:SASS_REFERENCE.md#debug_info-option `:debug_info` option} is enabled.
|
243
|
+
# This data is used by e.g. [the FireSass Firebug extension](https://addons.mozilla.org/en-US/firefox/addon/103988).
|
244
|
+
#
|
245
|
+
# @return [{#to_s => #to_s}]
|
246
|
+
def debug_info
|
247
|
+
{:filename => filename && ("file://" + URI.escape(File.expand_path(filename))),
|
248
|
+
:line => self.line}
|
249
|
+
end
|
250
|
+
|
251
|
+
private
|
252
|
+
|
253
|
+
def debug_info_rule
|
254
|
+
node = DirectiveNode.new("@media -sass-debug-info")
|
255
|
+
debug_info.map {|k, v| [k.to_s, v.to_s]}.sort.each do |k, v|
|
256
|
+
rule = RuleNode.new([""])
|
257
|
+
rule.resolved_rules = Sass::Selector::CommaSequence.new(
|
258
|
+
[Sass::Selector::Sequence.new(
|
259
|
+
[Sass::Selector::SimpleSequence.new(
|
260
|
+
[Sass::Selector::Element.new(k.to_s.gsub(/[^\w-]/, "\\\\\\0"), nil)])
|
261
|
+
])
|
262
|
+
])
|
263
|
+
prop = PropNode.new([""], "", :new)
|
264
|
+
prop.resolved_name = "font-family"
|
265
|
+
prop.resolved_value = Sass::SCSS::RX.escape_ident(v.to_s)
|
266
|
+
rule << prop
|
267
|
+
node << rule
|
268
|
+
end
|
269
|
+
node.options = @options.merge(:debug_info => false, :line_comments => false, :style => :compressed)
|
270
|
+
node
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|