sass4 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/AGENTS.md +534 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/CONTRIBUTING.md +148 -0
- data/MIT-LICENSE +20 -0
- data/README.md +242 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/sass +13 -0
- data/bin/sass-convert +12 -0
- data/bin/scss +13 -0
- data/extra/sass-spec-ref.sh +40 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass/cache_stores/base.rb +88 -0
- data/lib/sass/cache_stores/chain.rb +34 -0
- data/lib/sass/cache_stores/filesystem.rb +60 -0
- data/lib/sass/cache_stores/memory.rb +46 -0
- data/lib/sass/cache_stores/null.rb +25 -0
- data/lib/sass/cache_stores.rb +15 -0
- data/lib/sass/callbacks.rb +67 -0
- data/lib/sass/css.rb +407 -0
- data/lib/sass/deprecation.rb +55 -0
- data/lib/sass/engine.rb +1236 -0
- data/lib/sass/environment.rb +236 -0
- data/lib/sass/error.rb +198 -0
- data/lib/sass/exec/base.rb +188 -0
- data/lib/sass/exec/sass_convert.rb +283 -0
- data/lib/sass/exec/sass_scss.rb +436 -0
- data/lib/sass/exec.rb +9 -0
- data/lib/sass/features.rb +48 -0
- data/lib/sass/importers/base.rb +182 -0
- data/lib/sass/importers/deprecated_path.rb +51 -0
- data/lib/sass/importers/filesystem.rb +221 -0
- data/lib/sass/importers.rb +23 -0
- data/lib/sass/logger/base.rb +47 -0
- data/lib/sass/logger/delayed.rb +50 -0
- data/lib/sass/logger/log_level.rb +45 -0
- data/lib/sass/logger.rb +17 -0
- data/lib/sass/media.rb +210 -0
- data/lib/sass/plugin/compiler.rb +552 -0
- data/lib/sass/plugin/configuration.rb +134 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +60 -0
- data/lib/sass/plugin/rails.rb +47 -0
- data/lib/sass/plugin/staleness_checker.rb +199 -0
- data/lib/sass/plugin.rb +134 -0
- data/lib/sass/railtie.rb +10 -0
- data/lib/sass/repl.rb +57 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script/css_lexer.rb +33 -0
- data/lib/sass/script/css_parser.rb +36 -0
- data/lib/sass/script/functions.rb +3103 -0
- data/lib/sass/script/lexer.rb +518 -0
- data/lib/sass/script/parser.rb +1164 -0
- data/lib/sass/script/tree/funcall.rb +314 -0
- data/lib/sass/script/tree/interpolation.rb +220 -0
- data/lib/sass/script/tree/list_literal.rb +119 -0
- data/lib/sass/script/tree/literal.rb +49 -0
- data/lib/sass/script/tree/map_literal.rb +64 -0
- data/lib/sass/script/tree/node.rb +119 -0
- data/lib/sass/script/tree/operation.rb +149 -0
- data/lib/sass/script/tree/selector.rb +26 -0
- data/lib/sass/script/tree/string_interpolation.rb +125 -0
- data/lib/sass/script/tree/unary_operation.rb +69 -0
- data/lib/sass/script/tree/variable.rb +57 -0
- data/lib/sass/script/tree.rb +16 -0
- data/lib/sass/script/value/arg_list.rb +36 -0
- data/lib/sass/script/value/base.rb +258 -0
- data/lib/sass/script/value/bool.rb +35 -0
- data/lib/sass/script/value/callable.rb +25 -0
- data/lib/sass/script/value/color.rb +704 -0
- data/lib/sass/script/value/function.rb +19 -0
- data/lib/sass/script/value/helpers.rb +298 -0
- data/lib/sass/script/value/list.rb +135 -0
- data/lib/sass/script/value/map.rb +70 -0
- data/lib/sass/script/value/null.rb +44 -0
- data/lib/sass/script/value/number.rb +564 -0
- data/lib/sass/script/value/string.rb +138 -0
- data/lib/sass/script/value.rb +13 -0
- data/lib/sass/script.rb +66 -0
- data/lib/sass/scss/css_parser.rb +61 -0
- data/lib/sass/scss/parser.rb +1343 -0
- data/lib/sass/scss/rx.rb +134 -0
- data/lib/sass/scss/static_parser.rb +351 -0
- data/lib/sass/scss.rb +14 -0
- data/lib/sass/selector/abstract_sequence.rb +112 -0
- data/lib/sass/selector/comma_sequence.rb +195 -0
- data/lib/sass/selector/pseudo.rb +291 -0
- data/lib/sass/selector/sequence.rb +661 -0
- data/lib/sass/selector/simple.rb +124 -0
- data/lib/sass/selector/simple_sequence.rb +348 -0
- data/lib/sass/selector.rb +327 -0
- data/lib/sass/shared.rb +76 -0
- data/lib/sass/source/map.rb +209 -0
- data/lib/sass/source/position.rb +39 -0
- data/lib/sass/source/range.rb +41 -0
- data/lib/sass/stack.rb +140 -0
- data/lib/sass/supports.rb +225 -0
- data/lib/sass/tree/at_root_node.rb +83 -0
- data/lib/sass/tree/charset_node.rb +22 -0
- data/lib/sass/tree/comment_node.rb +82 -0
- data/lib/sass/tree/content_node.rb +9 -0
- data/lib/sass/tree/css_import_node.rb +68 -0
- data/lib/sass/tree/debug_node.rb +18 -0
- data/lib/sass/tree/directive_node.rb +59 -0
- data/lib/sass/tree/each_node.rb +24 -0
- data/lib/sass/tree/error_node.rb +18 -0
- data/lib/sass/tree/extend_node.rb +43 -0
- data/lib/sass/tree/for_node.rb +36 -0
- data/lib/sass/tree/function_node.rb +44 -0
- data/lib/sass/tree/if_node.rb +52 -0
- data/lib/sass/tree/import_node.rb +75 -0
- data/lib/sass/tree/keyframe_rule_node.rb +15 -0
- data/lib/sass/tree/media_node.rb +48 -0
- data/lib/sass/tree/mixin_def_node.rb +38 -0
- data/lib/sass/tree/mixin_node.rb +52 -0
- data/lib/sass/tree/node.rb +240 -0
- data/lib/sass/tree/prop_node.rb +162 -0
- data/lib/sass/tree/return_node.rb +19 -0
- data/lib/sass/tree/root_node.rb +44 -0
- data/lib/sass/tree/rule_node.rb +153 -0
- data/lib/sass/tree/supports_node.rb +38 -0
- data/lib/sass/tree/trace_node.rb +33 -0
- data/lib/sass/tree/variable_node.rb +36 -0
- data/lib/sass/tree/visitors/base.rb +72 -0
- data/lib/sass/tree/visitors/check_nesting.rb +173 -0
- data/lib/sass/tree/visitors/convert.rb +350 -0
- data/lib/sass/tree/visitors/cssize.rb +362 -0
- data/lib/sass/tree/visitors/deep_copy.rb +107 -0
- data/lib/sass/tree/visitors/extend.rb +64 -0
- data/lib/sass/tree/visitors/perform.rb +572 -0
- data/lib/sass/tree/visitors/set_options.rb +139 -0
- data/lib/sass/tree/visitors/to_css.rb +440 -0
- data/lib/sass/tree/warn_node.rb +18 -0
- data/lib/sass/tree/while_node.rb +18 -0
- data/lib/sass/util/multibyte_string_scanner.rb +151 -0
- data/lib/sass/util/normalized_map.rb +122 -0
- data/lib/sass/util/subset_map.rb +109 -0
- data/lib/sass/util/test.rb +9 -0
- data/lib/sass/util.rb +1137 -0
- data/lib/sass/version.rb +120 -0
- data/lib/sass.rb +102 -0
- data/rails/init.rb +1 -0
- metadata +283 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
module Sass::Tree
|
|
2
|
+
# A static node representing a CSS property.
|
|
3
|
+
#
|
|
4
|
+
# @see Sass::Tree
|
|
5
|
+
class PropNode < Node
|
|
6
|
+
# The name of the property,
|
|
7
|
+
# interspersed with {Sass::Script::Tree::Node}s
|
|
8
|
+
# representing `#{}`-interpolation.
|
|
9
|
+
# Any adjacent strings will be merged together.
|
|
10
|
+
#
|
|
11
|
+
# @return [Array<String, Sass::Script::Tree::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::Visitors::Perform} has been run.
|
|
17
|
+
#
|
|
18
|
+
# @return [String]
|
|
19
|
+
attr_accessor :resolved_name
|
|
20
|
+
|
|
21
|
+
# The value of the property.
|
|
22
|
+
#
|
|
23
|
+
# For most properties, this will just contain a single Node. However, for
|
|
24
|
+
# CSS variables, it will contain multiple strings and nodes representing
|
|
25
|
+
# interpolation. Any adjacent strings will be merged together.
|
|
26
|
+
#
|
|
27
|
+
# @return [Array<String, Sass::Script::Tree::Node>]
|
|
28
|
+
attr_accessor :value
|
|
29
|
+
|
|
30
|
+
# The value of the property
|
|
31
|
+
# after any interpolated SassScript has been resolved.
|
|
32
|
+
# Only set once \{Tree::Visitors::Perform} has been run.
|
|
33
|
+
#
|
|
34
|
+
# @return [String]
|
|
35
|
+
attr_accessor :resolved_value
|
|
36
|
+
|
|
37
|
+
# How deep this property is indented
|
|
38
|
+
# relative to a normal property.
|
|
39
|
+
# This is only greater than 0 in the case that:
|
|
40
|
+
#
|
|
41
|
+
# * This node is in a CSS tree
|
|
42
|
+
# * The style is :nested
|
|
43
|
+
# * This is a child property of another property
|
|
44
|
+
# * The parent property has a value, and thus will be rendered
|
|
45
|
+
#
|
|
46
|
+
# @return [Integer]
|
|
47
|
+
attr_accessor :tabs
|
|
48
|
+
|
|
49
|
+
# The source range in which the property name appears.
|
|
50
|
+
#
|
|
51
|
+
# @return [Sass::Source::Range]
|
|
52
|
+
attr_accessor :name_source_range
|
|
53
|
+
|
|
54
|
+
# The source range in which the property value appears.
|
|
55
|
+
#
|
|
56
|
+
# @return [Sass::Source::Range]
|
|
57
|
+
attr_accessor :value_source_range
|
|
58
|
+
|
|
59
|
+
# Whether this represents a CSS custom property.
|
|
60
|
+
#
|
|
61
|
+
# @return [Boolean]
|
|
62
|
+
def custom_property?
|
|
63
|
+
name.first.is_a?(String) && name.first.start_with?("--")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @param name [Array<String, Sass::Script::Tree::Node>] See \{#name}
|
|
67
|
+
# @param value [Array<String, Sass::Script::Tree::Node>] See \{#value}
|
|
68
|
+
# @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
|
|
69
|
+
# `:old` if it uses `:a b`-style syntax
|
|
70
|
+
def initialize(name, value, prop_syntax)
|
|
71
|
+
@name = Sass::Util.strip_string_array(
|
|
72
|
+
Sass::Util.merge_adjacent_strings(name))
|
|
73
|
+
@value = Sass::Util.merge_adjacent_strings(value)
|
|
74
|
+
@value = Sass::Util.strip_string_array(@value) unless custom_property?
|
|
75
|
+
@tabs = 0
|
|
76
|
+
@prop_syntax = prop_syntax
|
|
77
|
+
super()
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Compares the names and values of two properties.
|
|
81
|
+
#
|
|
82
|
+
# @param other [Object] The object to compare with
|
|
83
|
+
# @return [Boolean] Whether or not this node and the other object
|
|
84
|
+
# are the same
|
|
85
|
+
def ==(other)
|
|
86
|
+
self.class == other.class && name == other.name && value == other.value && super
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Returns a appropriate message indicating how to escape pseudo-class selectors.
|
|
90
|
+
# This only applies for old-style properties with no value,
|
|
91
|
+
# so returns the empty string if this is new-style.
|
|
92
|
+
#
|
|
93
|
+
# @return [String] The message
|
|
94
|
+
def pseudo_class_selector_message
|
|
95
|
+
if @prop_syntax == :new ||
|
|
96
|
+
custom_property? ||
|
|
97
|
+
!value.first.is_a?(Sass::Script::Tree::Literal) ||
|
|
98
|
+
!value.first.value.is_a?(Sass::Script::Value::String) ||
|
|
99
|
+
!value.first.value.value.empty?
|
|
100
|
+
return ""
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
"\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Computes the Sass or SCSS code for the variable declaration.
|
|
107
|
+
# This is like \{#to\_scss} or \{#to\_sass},
|
|
108
|
+
# except it doesn't print any child properties or a trailing semicolon.
|
|
109
|
+
#
|
|
110
|
+
# @param opts [{Symbol => Object}] The options hash for the tree.
|
|
111
|
+
# @param fmt [Symbol] `:scss` or `:sass`.
|
|
112
|
+
def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
|
|
113
|
+
name = self.name.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
|
|
114
|
+
value = self.value.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
|
|
115
|
+
value = "(#{value})" if value_needs_parens?
|
|
116
|
+
|
|
117
|
+
if name[0] == ?:
|
|
118
|
+
raise Sass::SyntaxError.new("The \"#{name}: #{value}\"" +
|
|
119
|
+
" hack is not allowed in the Sass indented syntax")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# The indented syntax doesn't support newlines in custom property values,
|
|
123
|
+
# but we can losslessly convert them to spaces instead.
|
|
124
|
+
value = value.tr("\n", " ") if fmt == :sass
|
|
125
|
+
|
|
126
|
+
old = opts[:old] && fmt == :sass
|
|
127
|
+
"#{old ? ':' : ''}#{name}#{old ? '' : ':'}#{custom_property? ? '' : ' '}#{value}".rstrip
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# A property node is invisible if its value is empty.
|
|
131
|
+
#
|
|
132
|
+
# @return [Boolean]
|
|
133
|
+
def invisible?
|
|
134
|
+
!custom_property? && resolved_value.empty?
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
private
|
|
138
|
+
|
|
139
|
+
# Returns whether \{#value} neesd parentheses in order to be parsed
|
|
140
|
+
# properly as division.
|
|
141
|
+
def value_needs_parens?
|
|
142
|
+
return false if custom_property?
|
|
143
|
+
|
|
144
|
+
root = value.first
|
|
145
|
+
root.is_a?(Sass::Script::Tree::Operation) &&
|
|
146
|
+
root.operator == :div &&
|
|
147
|
+
root.operand1.is_a?(Sass::Script::Tree::Literal) &&
|
|
148
|
+
root.operand1.value.is_a?(Sass::Script::Value::Number) &&
|
|
149
|
+
root.operand1.value.original.nil? &&
|
|
150
|
+
root.operand2.is_a?(Sass::Script::Tree::Literal) &&
|
|
151
|
+
root.operand2.value.is_a?(Sass::Script::Value::Number) &&
|
|
152
|
+
root.operand2.value.original.nil?
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def check!
|
|
156
|
+
return unless @options[:property_syntax] && @options[:property_syntax] != @prop_syntax
|
|
157
|
+
raise Sass::SyntaxError.new(
|
|
158
|
+
"Illegal property syntax: can't use #{@prop_syntax} syntax when " +
|
|
159
|
+
":property_syntax => #{@options[:property_syntax].inspect} is set.")
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Sass
|
|
2
|
+
module Tree
|
|
3
|
+
# A dynamic node representing returning from a function.
|
|
4
|
+
#
|
|
5
|
+
# @see Sass::Tree
|
|
6
|
+
class ReturnNode < Node
|
|
7
|
+
# The expression to return.
|
|
8
|
+
#
|
|
9
|
+
# @return [Script::Tree::Node]
|
|
10
|
+
attr_accessor :expr
|
|
11
|
+
|
|
12
|
+
# @param expr [Script::Tree::Node] The expression to return
|
|
13
|
+
def initialize(expr)
|
|
14
|
+
@expr = expr
|
|
15
|
+
super()
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
# Runs the dynamic Sass code and computes the CSS for the tree.
|
|
17
|
+
#
|
|
18
|
+
# @return [String] The compiled CSS.
|
|
19
|
+
def render
|
|
20
|
+
css_tree.css
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Runs the dynamic Sass code and computes the CSS for the tree, along with
|
|
24
|
+
# the sourcemap.
|
|
25
|
+
#
|
|
26
|
+
# @return [(String, Sass::Source::Map)] The compiled CSS, as well as
|
|
27
|
+
# the source map. @see #render
|
|
28
|
+
def render_with_sourcemap
|
|
29
|
+
css_tree.css_with_sourcemap
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def css_tree
|
|
35
|
+
Visitors::CheckNesting.visit(self)
|
|
36
|
+
result = Visitors::Perform.visit(self)
|
|
37
|
+
Visitors::CheckNesting.visit(result) # Check again to validate mixins
|
|
38
|
+
result, extends = Visitors::Cssize.visit(result)
|
|
39
|
+
Visitors::Extend.visit(result, extends)
|
|
40
|
+
result
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
|
|
3
|
+
module Sass::Tree
|
|
4
|
+
# A static node representing a CSS rule.
|
|
5
|
+
#
|
|
6
|
+
# @see Sass::Tree
|
|
7
|
+
class RuleNode < Node
|
|
8
|
+
# The character used to include the parent selector
|
|
9
|
+
PARENT = '&'
|
|
10
|
+
|
|
11
|
+
# The CSS selector for this rule,
|
|
12
|
+
# interspersed with {Sass::Script::Tree::Node}s
|
|
13
|
+
# representing `#{}`-interpolation.
|
|
14
|
+
# Any adjacent strings will be merged together.
|
|
15
|
+
#
|
|
16
|
+
# @return [Array<String, Sass::Script::Tree::Node>]
|
|
17
|
+
attr_accessor :rule
|
|
18
|
+
|
|
19
|
+
# The CSS selector for this rule, without any unresolved
|
|
20
|
+
# interpolation but with parent references still intact. It's only
|
|
21
|
+
# guaranteed to be set once {Tree::Visitors::Perform} has been
|
|
22
|
+
# run, but it may be set before then for optimization reasons.
|
|
23
|
+
#
|
|
24
|
+
# @return [Selector::CommaSequence]
|
|
25
|
+
attr_accessor :parsed_rules
|
|
26
|
+
|
|
27
|
+
# The CSS selector for this rule, without any unresolved
|
|
28
|
+
# interpolation or parent references. It's only set once
|
|
29
|
+
# {Tree::Visitors::Perform} has been run.
|
|
30
|
+
#
|
|
31
|
+
# @return [Selector::CommaSequence]
|
|
32
|
+
attr_accessor :resolved_rules
|
|
33
|
+
|
|
34
|
+
# How deep this rule is indented
|
|
35
|
+
# relative to a base-level rule.
|
|
36
|
+
# This is only greater than 0 in the case that:
|
|
37
|
+
#
|
|
38
|
+
# * This node is in a CSS tree
|
|
39
|
+
# * The style is :nested
|
|
40
|
+
# * This is a child rule of another rule
|
|
41
|
+
# * The parent rule has properties, and thus will be rendered
|
|
42
|
+
#
|
|
43
|
+
# @return [Integer]
|
|
44
|
+
attr_accessor :tabs
|
|
45
|
+
|
|
46
|
+
# The entire selector source range for this rule.
|
|
47
|
+
# @return [Sass::Source::Range]
|
|
48
|
+
attr_accessor :selector_source_range
|
|
49
|
+
|
|
50
|
+
# Whether or not this rule is the last rule in a nested group.
|
|
51
|
+
# This is only set in a CSS tree.
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean]
|
|
54
|
+
attr_accessor :group_end
|
|
55
|
+
|
|
56
|
+
# The stack trace.
|
|
57
|
+
# This is only readable in a CSS tree as it is written during the perform step
|
|
58
|
+
# and only when the :trace_selectors option is set.
|
|
59
|
+
#
|
|
60
|
+
# @return [String]
|
|
61
|
+
attr_accessor :stack_trace
|
|
62
|
+
|
|
63
|
+
# @param rule [Array<String, Sass::Script::Tree::Node>, Sass::Selector::CommaSequence]
|
|
64
|
+
# The CSS rule, either unparsed or parsed.
|
|
65
|
+
# @param selector_source_range [Sass::Source::Range]
|
|
66
|
+
def initialize(rule, selector_source_range = nil)
|
|
67
|
+
if rule.is_a?(Sass::Selector::CommaSequence)
|
|
68
|
+
@rule = [rule.to_s]
|
|
69
|
+
@parsed_rules = rule
|
|
70
|
+
else
|
|
71
|
+
merged = Sass::Util.merge_adjacent_strings(rule)
|
|
72
|
+
@rule = Sass::Util.strip_string_array(merged)
|
|
73
|
+
try_to_parse_non_interpolated_rules
|
|
74
|
+
end
|
|
75
|
+
@selector_source_range = selector_source_range
|
|
76
|
+
@tabs = 0
|
|
77
|
+
super()
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# If we've precached the parsed selector, set the line on it, too.
|
|
81
|
+
def line=(line)
|
|
82
|
+
@parsed_rules.line = line if @parsed_rules
|
|
83
|
+
super
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# If we've precached the parsed selector, set the filename on it, too.
|
|
87
|
+
def filename=(filename)
|
|
88
|
+
@parsed_rules.filename = filename if @parsed_rules
|
|
89
|
+
super
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Compares the contents of two rules.
|
|
93
|
+
#
|
|
94
|
+
# @param other [Object] The object to compare with
|
|
95
|
+
# @return [Boolean] Whether or not this node and the other object
|
|
96
|
+
# are the same
|
|
97
|
+
def ==(other)
|
|
98
|
+
self.class == other.class && rule == other.rule && super
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Adds another {RuleNode}'s rules to this one's.
|
|
102
|
+
#
|
|
103
|
+
# @param node [RuleNode] The other node
|
|
104
|
+
def add_rules(node)
|
|
105
|
+
@rule = Sass::Util.strip_string_array(
|
|
106
|
+
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
|
|
107
|
+
try_to_parse_non_interpolated_rules
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# @return [Boolean] Whether or not this rule is continued on the next line
|
|
111
|
+
def continued?
|
|
112
|
+
last = @rule.last
|
|
113
|
+
last.is_a?(String) && last[-1] == ?,
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# A hash that will be associated with this rule in the CSS document
|
|
117
|
+
# if the {file:SASS_REFERENCE.md#debug_info-option `:debug_info` option} is enabled.
|
|
118
|
+
# This data is used by e.g. [the FireSass Firebug
|
|
119
|
+
# extension](https://addons.mozilla.org/en-US/firefox/addon/103988).
|
|
120
|
+
#
|
|
121
|
+
# @return [{#to_s => #to_s}]
|
|
122
|
+
def debug_info
|
|
123
|
+
{:filename => filename &&
|
|
124
|
+
("file://" + URI::DEFAULT_PARSER.escape(File.expand_path(filename))),
|
|
125
|
+
:line => line}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# A rule node is invisible if it has only placeholder selectors.
|
|
129
|
+
def invisible?
|
|
130
|
+
resolved_rules.members.all? {|seq| seq.invisible?}
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
private
|
|
134
|
+
|
|
135
|
+
def try_to_parse_non_interpolated_rules
|
|
136
|
+
@parsed_rules = nil
|
|
137
|
+
return unless @rule.all? {|t| t.is_a?(String)}
|
|
138
|
+
|
|
139
|
+
# We don't use real filename/line info because we don't have it yet.
|
|
140
|
+
# When we get it, we'll set it on the parsed rules if possible.
|
|
141
|
+
parser = nil
|
|
142
|
+
warnings = Sass.logger.capture do
|
|
143
|
+
parser = Sass::SCSS::StaticParser.new(
|
|
144
|
+
Sass::Util.strip_except_escapes(@rule.join), nil, nil, 1)
|
|
145
|
+
@parsed_rules = parser.parse_selector rescue nil
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# If parsing produces a warning, throw away the result so we can parse
|
|
149
|
+
# later with the real filename info.
|
|
150
|
+
@parsed_rules = nil unless warnings.empty?
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Sass::Tree
|
|
2
|
+
# A static node representing a `@supports` rule.
|
|
3
|
+
#
|
|
4
|
+
# @see Sass::Tree
|
|
5
|
+
class SupportsNode < DirectiveNode
|
|
6
|
+
# The name, which may include a browser prefix.
|
|
7
|
+
#
|
|
8
|
+
# @return [String]
|
|
9
|
+
attr_accessor :name
|
|
10
|
+
|
|
11
|
+
# The supports condition.
|
|
12
|
+
#
|
|
13
|
+
# @return [Sass::Supports::Condition]
|
|
14
|
+
attr_accessor :condition
|
|
15
|
+
|
|
16
|
+
# @param condition [Sass::Supports::Condition] See \{#condition}
|
|
17
|
+
def initialize(name, condition)
|
|
18
|
+
@name = name
|
|
19
|
+
@condition = condition
|
|
20
|
+
super('')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @see DirectiveNode#value
|
|
24
|
+
def value; raise NotImplementedError; end
|
|
25
|
+
|
|
26
|
+
# @see DirectiveNode#resolved_value
|
|
27
|
+
def resolved_value
|
|
28
|
+
@resolved_value ||= "@#{name} #{condition.to_css}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# True when the directive has no visible children.
|
|
32
|
+
#
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def invisible?
|
|
35
|
+
children.all? {|c| c.invisible?}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'sass/tree/node'
|
|
2
|
+
|
|
3
|
+
module Sass::Tree
|
|
4
|
+
# A solely static node left over after a mixin include or @content has been performed.
|
|
5
|
+
# Its sole purpose is to wrap exceptions to add to the backtrace.
|
|
6
|
+
#
|
|
7
|
+
# @see Sass::Tree
|
|
8
|
+
class TraceNode < Node
|
|
9
|
+
# The name of the trace entry to add.
|
|
10
|
+
#
|
|
11
|
+
# @return [String]
|
|
12
|
+
attr_reader :name
|
|
13
|
+
|
|
14
|
+
# @param name [String] The name of the trace entry to add.
|
|
15
|
+
def initialize(name)
|
|
16
|
+
@name = name
|
|
17
|
+
self.has_children = true
|
|
18
|
+
super()
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Initializes this node from an existing node.
|
|
22
|
+
# @param name [String] The name of the trace entry to add.
|
|
23
|
+
# @param node [Node] The node to copy information from.
|
|
24
|
+
# @return [TraceNode]
|
|
25
|
+
def self.from_node(name, node)
|
|
26
|
+
trace = new(name)
|
|
27
|
+
trace.line = node.line
|
|
28
|
+
trace.filename = node.filename
|
|
29
|
+
trace.options = node.options
|
|
30
|
+
trace
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Sass
|
|
2
|
+
module Tree
|
|
3
|
+
# A dynamic node representing a variable definition.
|
|
4
|
+
#
|
|
5
|
+
# @see Sass::Tree
|
|
6
|
+
class VariableNode < Node
|
|
7
|
+
# The name of the variable.
|
|
8
|
+
# @return [String]
|
|
9
|
+
attr_reader :name
|
|
10
|
+
|
|
11
|
+
# The parse tree for the variable value.
|
|
12
|
+
# @return [Script::Tree::Node]
|
|
13
|
+
attr_accessor :expr
|
|
14
|
+
|
|
15
|
+
# Whether this is a guarded variable assignment (`!default`).
|
|
16
|
+
# @return [Boolean]
|
|
17
|
+
attr_reader :guarded
|
|
18
|
+
|
|
19
|
+
# Whether this is a global variable assignment (`!global`).
|
|
20
|
+
# @return [Boolean]
|
|
21
|
+
attr_reader :global
|
|
22
|
+
|
|
23
|
+
# @param name [String] The name of the variable
|
|
24
|
+
# @param expr [Script::Tree::Node] See \{#expr}
|
|
25
|
+
# @param guarded [Boolean] See \{#guarded}
|
|
26
|
+
# @param global [Boolean] See \{#global}
|
|
27
|
+
def initialize(name, expr, guarded, global)
|
|
28
|
+
@name = name
|
|
29
|
+
@expr = expr
|
|
30
|
+
@guarded = guarded
|
|
31
|
+
@global = global
|
|
32
|
+
super()
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Visitors are used to traverse the Sass parse tree.
|
|
2
|
+
# Visitors should extend {Visitors::Base},
|
|
3
|
+
# which provides a small amount of scaffolding for traversal.
|
|
4
|
+
module Sass::Tree::Visitors
|
|
5
|
+
# The abstract base class for Sass visitors.
|
|
6
|
+
# Visitors should extend this class,
|
|
7
|
+
# then implement `visit_*` methods for each node they care about
|
|
8
|
+
# (e.g. `visit_rule` for {RuleNode} or `visit_for` for {ForNode}).
|
|
9
|
+
# These methods take the node in question as argument.
|
|
10
|
+
# They may `yield` to visit the child nodes of the current node.
|
|
11
|
+
#
|
|
12
|
+
# *Note*: due to the unusual nature of {Sass::Tree::IfNode},
|
|
13
|
+
# special care must be taken to ensure that it is properly handled.
|
|
14
|
+
# In particular, there is no built-in scaffolding
|
|
15
|
+
# for dealing with the return value of `@else` nodes.
|
|
16
|
+
#
|
|
17
|
+
# @abstract
|
|
18
|
+
class Base
|
|
19
|
+
# Runs the visitor on a tree.
|
|
20
|
+
#
|
|
21
|
+
# @param root [Tree::Node] The root node of the Sass tree.
|
|
22
|
+
# @return [Object] The return value of \{#visit} for the root node.
|
|
23
|
+
def self.visit(root)
|
|
24
|
+
new.send(:visit, root)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# Runs the visitor on the given node.
|
|
30
|
+
# This can be overridden by subclasses that need to do something for each node.
|
|
31
|
+
#
|
|
32
|
+
# @param node [Tree::Node] The node to visit.
|
|
33
|
+
# @return [Object] The return value of the `visit_*` method for this node.
|
|
34
|
+
def visit(node)
|
|
35
|
+
if respond_to?(node.class.visit_method, true)
|
|
36
|
+
send(node.class.visit_method, node) {visit_children(node)}
|
|
37
|
+
else
|
|
38
|
+
visit_children(node)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Visit the child nodes for a given node.
|
|
43
|
+
# This can be overridden by subclasses that need to do something
|
|
44
|
+
# with the child nodes' return values.
|
|
45
|
+
#
|
|
46
|
+
# This method is run when `visit_*` methods `yield`,
|
|
47
|
+
# and its return value is returned from the `yield`.
|
|
48
|
+
#
|
|
49
|
+
# @param parent [Tree::Node] The parent node of the children to visit.
|
|
50
|
+
# @return [Array<Object>] The return values of the `visit_*` methods for the children.
|
|
51
|
+
def visit_children(parent)
|
|
52
|
+
parent.children.map {|c| visit(c)}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns the name of a node as used in the `visit_*` method.
|
|
56
|
+
#
|
|
57
|
+
# @param [Tree::Node] node The node.
|
|
58
|
+
# @return [String] The name.
|
|
59
|
+
def self.node_name(node)
|
|
60
|
+
Sass::Util.deprecated(self, "Call node.class.node_name instead.")
|
|
61
|
+
node.class.node_name
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# `yield`s, then runs the visitor on the `@else` clause if the node has one.
|
|
65
|
+
# This exists to ensure that the contents of the `@else` clause get visited.
|
|
66
|
+
def visit_if(node)
|
|
67
|
+
yield
|
|
68
|
+
visit(node.else) if node.else
|
|
69
|
+
node
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|