Class: Sass::Tree::PropNode
Overview
A static node reprenting a CSS property.
Instance Attribute Summary collapse
-
#name ⇒ Array<String, Sass::Script::Node>
The name of the property, interspersed with Script::Nodes representing
#{}
-interpolation. -
#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 ⇒ Fixnum
How deep this property is indented relative to a normal property.
-
#value ⇒ Sass::Script::Node
The value of the property.
Attributes inherited from Node
#children, #filename, #has_children, #line, #options
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the names and values of two properties.
-
#_cssize(parent)
protected
Converts nested properties into flat properties.
-
#_to_s(tabs) ⇒ String
protected
Computes the CSS for the property.
-
#cssize!(parent)
protected
Updates the name and indentation of this node based on the parent name and nesting level.
-
#initialize(name, value, prop_syntax) ⇒ PropNode
constructor
A new instance of PropNode.
-
#invalid_child?(child) ⇒ String
protected
Returns an error message if the given child node is invalid, and false otherwise.
-
#perform!(environment)
protected
Runs any SassScript that may be embedded in the property, and invludes the parent property, if any.
-
#pseudo_class_selector_message ⇒ String
Returns a appropriate message indicating how to escape pseudo-class selectors.
- #to_src(tabs, opts, fmt) protected
Methods inherited from Node
#<<, #_perform, #balance, #children_to_src, #cssize, #dasherize, #each, #invisible?, #perform, #perform_children, #render, #run_interp, #semi, #style, #to_s, #to_sass, #to_scss
Constructor Details
#initialize(name, value, prop_syntax) ⇒ PropNode
Returns a new instance of PropNode.
49 50 51 52 53 54 55 56 |
# File 'lib/sass/tree/prop_node.rb', line 49
def initialize(name, value, prop_syntax)
@name = Haml::Util.strip_string_array(
Haml::Util.merge_adjacent_strings(name))
@value = value
@tabs = 0
@prop_syntax = prop_syntax
super()
end
|
Instance Attribute Details
#name ⇒ Array<String, Sass::Script::Node>
The name of the property,
interspersed with Script::Nodes
representing #{}
-interpolation.
Any adjacent strings will be merged together.
12 13 14 |
# File 'lib/sass/tree/prop_node.rb', line 12
def name
@name
end
|
#resolved_name ⇒ String
The name of the property after any interpolated SassScript has been resolved. Only set once Node#perform has been called.
19 20 21 |
# File '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 Node#perform has been called.
31 32 33 |
# File 'lib/sass/tree/prop_node.rb', line 31
def resolved_value
@resolved_value
end
|
#tabs ⇒ Fixnum
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
43 44 45 |
# File 'lib/sass/tree/prop_node.rb', line 43
def tabs
@tabs
end
|
#value ⇒ Sass::Script::Node
The value of the property.
24 25 26 |
# File 'lib/sass/tree/prop_node.rb', line 24
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares the names and values of two properties.
63 64 65 |
# File 'lib/sass/tree/prop_node.rb', line 63
def ==(other)
self.class == other.class && name == other.name && value == other.value && super
end
|
#_cssize(parent) (protected)
Converts nested properties into flat properties.
109 110 111 112 113 114 115 116 117 |
# File 'lib/sass/tree/prop_node.rb', line 109
def _cssize(parent)
node = super
result = node.children.dup
if !node.resolved_value.empty? || node.children.empty?
node.send(:check!)
result.unshift(node)
end
result
end
|
#_to_s(tabs) ⇒ String (protected)
Computes the CSS for the property.
99 100 101 102 |
# File 'lib/sass/tree/prop_node.rb', line 99
def _to_s(tabs)
to_return = ' ' * (tabs - 1 + self.tabs) + resolved_name + ":" +
(style == :compressed ? '' : ' ') + resolved_value + (style == :compressed ? "" : ";")
end
|
#cssize!(parent) (protected)
Updates the name and indentation of this node based on the parent name and nesting level.
124 125 126 127 128 |
# File 'lib/sass/tree/prop_node.rb', line 124
def cssize!(parent)
self.resolved_name = "#{parent.resolved_name}-#{resolved_name}" if parent
self.tabs = parent.tabs + (parent.resolved_value.empty? ? 0 : 1) if parent && style == :nested
super
end
|
#invalid_child?(child) ⇒ String (protected)
Returns an error message if the given child node is invalid, and false otherwise.
Sass::Tree::PropNode only allows other Sass::Tree::PropNodes and CommentNodes as children.
153 154 155 156 157 |
# File 'lib/sass/tree/prop_node.rb', line 153
def invalid_child?(child)
if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
"Illegal nesting: Only properties may be nested beneath properties."
end
end
|
#perform!(environment) (protected)
Runs any SassScript that may be embedded in the property, and invludes the parent property, if any.
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/sass/tree/prop_node.rb', line 135
def perform!(environment)
@resolved_name = run_interp(@name, environment)
val = @value.perform(environment)
@resolved_value =
if @value.context == :equals && val.is_a?(Sass::Script::String)
val.value
else
val.to_s
end
super
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.
This should only be called once Node#perform has been called.
74 75 76 77 |
# File 'lib/sass/tree/prop_node.rb', line 74
def pseudo_class_selector_message
return "" if @prop_syntax == :new || !resolved_value.empty?
"\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
end
|
#to_src(tabs, opts, fmt) (protected)
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sass/tree/prop_node.rb', line 81
def to_src(tabs, opts, fmt)
name = self.name.map {|n| n.is_a?(String) ? n : "\#{#{n.to_sass(opts)}}"}.join
if name[0] == ?:
raise Sass::SyntaxError.new("The \":#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
end
old = opts[:old] && fmt == :sass
initial = old ? ':' : ''
mid = old ? '' : ':'
res = "#{' ' * tabs}#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}"
return res + "#{semi fmt}\n" if children.empty?
res.rstrip + children_to_src(tabs, opts, fmt).rstrip + semi(fmt) + "\n"
end
|