Class: Sass::Tree::PropNode
- Inherits:
-
Node
- Object
- Node
- Sass::Tree::PropNode
- Defined in:
- .ruby-sass/lib/sass/tree/prop_node.rb
Overview
A static node representing a CSS property.
Instance Attribute Summary (collapse)
-
#name ⇒ Array<String, Sass::Script::Tree::Node>
The name of the property, interspersed with Script::Tree::Nodes representing `#{}`-interpolation.
-
#name_source_range ⇒ Sass::Source::Range
The source range in which the property name appears.
-
#resolved_name ⇒ String
The name of the property after any interpolated SassScript has been resolved.
-
#resolved_value ⇒ String
The value of the property after any interpolated SassScript has been resolved.
-
#tabs ⇒ Integer
How deep this property is indented relative to a normal property.
-
#value ⇒ Array<String, Sass::Script::Tree::Node>
The value of the property.
-
#value_source_range ⇒ Sass::Source::Range
The source range in which the property value appears.
Attributes inherited from Node
#children, #filename, #has_children, #line, #options, #source_range
Instance Method Summary (collapse)
-
#==(other) ⇒ Boolean
Compares the names and values of two properties.
-
#custom_property? ⇒ Boolean
Whether this represents a CSS custom property.
-
#declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass) ⇒ Object
Computes the Sass or SCSS code for the variable declaration.
-
#initialize(name, value, prop_syntax) ⇒ PropNode
constructor
A new instance of PropNode.
-
#invisible? ⇒ Boolean
A property node is invisible if its value is empty.
-
#pseudo_class_selector_message ⇒ String
Returns a appropriate message indicating how to escape pseudo-class selectors.
Methods inherited from Node
#<<, #bubbles?, #css, #css_with_sourcemap, #deep_copy, #each, inherited, #inspect, #style, #to_sass, #to_scss
Constructor Details
#initialize(name, value, prop_syntax) ⇒ PropNode
Returns a new instance of PropNode
70 71 72 73 74 75 76 77 78 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 70 def initialize(name, value, prop_syntax) @name = Sass::Util.strip_string_array( Sass::Util.merge_adjacent_strings(name)) @value = Sass::Util.merge_adjacent_strings(value) @value = Sass::Util.strip_string_array(@value) unless custom_property? @tabs = 0 @prop_syntax = prop_syntax super() end |
Constructor Details
#initialize(name, value, prop_syntax) ⇒ PropNode
Returns a new instance of PropNode
70 71 72 73 74 75 76 77 78 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 70 def initialize(name, value, prop_syntax) @name = Sass::Util.strip_string_array( Sass::Util.merge_adjacent_strings(name)) @value = Sass::Util.merge_adjacent_strings(value) @value = Sass::Util.strip_string_array(@value) unless custom_property? @tabs = 0 @prop_syntax = prop_syntax super() end |
Instance Attribute Details
#name ⇒ Array<String, Sass::Script::Tree::Node>
The name of the property, interspersed with Script::Tree::Nodes representing `#{}`-interpolation. Any adjacent strings will be merged together.
12 13 14 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 12 def name @name end |
#name_source_range ⇒ Sass::Source::Range
The source range in which the property name appears.
52 53 54 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 52 def name_source_range @name_source_range end |
#resolved_name ⇒ String
The name of the property after any interpolated SassScript has been resolved. Only set once Visitors::Perform has been run.
19 20 21 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 19 def resolved_name @resolved_name end |
#resolved_value ⇒ String
The value of the property after any interpolated SassScript has been resolved. Only set once Visitors::Perform has been run.
35 36 37 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 35 def resolved_value @resolved_value end |
#tabs ⇒ Integer
How deep this property is indented relative to a normal property. This is only greater than 0 in the case that:
-
This node is in a CSS tree
-
The style is :nested
-
This is a child property of another property
-
The parent property has a value, and thus will be rendered
47 48 49 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 47 def tabs @tabs end |
#value ⇒ Array<String, Sass::Script::Tree::Node>
The value of the property.
For most properties, this will just contain a single Node. However, for CSS variables, it will contain multiple strings and nodes representing interpolation. Any adjacent strings will be merged together.
28 29 30 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 28 def value @value end |
#value_source_range ⇒ Sass::Source::Range
The source range in which the property value appears.
57 58 59 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 57 def value_source_range @value_source_range end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the names and values of two properties.
85 86 87 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 85 def ==(other) self.class == other.class && name == other.name && value == other.value && super end |
#custom_property? ⇒ Boolean
Whether this represents a CSS custom property.
62 63 64 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 62 def custom_property? name.first.is_a?(String) && name.first.start_with?("--") end |
#declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass) ⇒ Object
Computes the Sass or SCSS code for the variable declaration. This is like Node#to_scss or Node#to_sass, except it doesn't print any child properties or a trailing semicolon.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 112 def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass) name = self.name.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join value = self.value.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join value = "(#{value})" if value_needs_parens? if name[0] == ?: raise Sass::SyntaxError.new("The \"#{name}: #{value}\"" + " hack is not allowed in the Sass indented syntax") end # The indented syntax doesn't support newlines in custom property values, # but we can losslessly convert them to spaces instead. value = value.tr("\n", " ") if fmt == :sass old = opts[:old] && fmt == :sass "#{old ? ':' : ''}#{name}#{old ? '' : ':'}#{custom_property? ? '' : ' '}#{value}".rstrip end |
#invisible? ⇒ Boolean
A property node is invisible if its value is empty.
133 134 135 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 133 def invisible? !custom_property? && resolved_value.empty? end |
#pseudo_class_selector_message ⇒ String
Returns a appropriate message indicating how to escape pseudo-class selectors. This only applies for old-style properties with no value, so returns the empty string if this is new-style.
94 95 96 97 98 99 100 101 102 103 104 |
# File '.ruby-sass/lib/sass/tree/prop_node.rb', line 94 def if @prop_syntax == :new || custom_property? || !value.first.is_a?(Sass::Script::Tree::Literal) || !value.first.value.is_a?(Sass::Script::Value::String) || !value.first.value.value.empty? return "" end "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead." end |