Class: Sass::Tree::PropNode
- Defined in:
- lib/sass/tree/prop_node.rb,
lib/sass/css.rb
Overview
A static node reprenting a CSS property.
Instance Attribute Summary collapse
-
#name ⇒ String
The name of the property.
-
#tabs ⇒ Fixnum
How deep this property is indented relative to a normal property.
-
#value ⇒ String, Script::Node
The value of the property, either a plain string or a SassScript parse tree.
Attributes inherited from Node
#children, #filename, #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_sass(tabs, opts = {})
Methods inherited from Node
#<<, #_perform, #balance, #cssize, #interpolate, #invisible?, #last, #perform, #perform_children, #render, #style, #to_s
Constructor Details
#initialize(name, value, prop_syntax) ⇒ PropNode
Returns a new instance of PropNode.
33 34 35 36 37 38 39 |
# File 'lib/sass/tree/prop_node.rb', line 33
def initialize(name, value, prop_syntax)
@name = name
@value = value
@tabs = 0
@prop_syntax = prop_syntax
super()
end
|
Instance Attribute Details
#name ⇒ String
The name of the property.
9 10 11 |
# File 'lib/sass/tree/prop_node.rb', line 9
def name
@name
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
27 28 29 |
# File 'lib/sass/tree/prop_node.rb', line 27
def tabs
@tabs
end
|
#value ⇒ String, Script::Node
The value of the property, either a plain string or a SassScript parse tree.
15 16 17 |
# File 'lib/sass/tree/prop_node.rb', line 15
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares the names and values of two properties.
46 47 48 |
# File 'lib/sass/tree/prop_node.rb', line 46
def ==(other)
self.class == other.class && name == other.name && value == other.value && super
end
|
#_cssize(parent) (protected)
Converts nested properties into flat properties.
76 77 78 79 80 81 82 83 84 |
# File 'lib/sass/tree/prop_node.rb', line 76
def _cssize(parent)
node = super
result = node.children.dup
if !node.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.
66 67 68 69 |
# File 'lib/sass/tree/prop_node.rb', line 66
def _to_s(tabs)
to_return = ' ' * (tabs - 1 + self.tabs) + name + ":" +
(style == :compressed ? '' : ' ') + value + (style == :compressed ? "" : ";")
end
|
#cssize!(parent) (protected)
Updates the name and indentation of this node based on the parent name and nesting level.
91 92 93 94 95 |
# File 'lib/sass/tree/prop_node.rb', line 91
def cssize!(parent)
self.name = "#{parent.name}-#{name}" if parent
self.tabs = parent.tabs + (parent.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.
114 115 116 117 118 |
# File 'lib/sass/tree/prop_node.rb', line 114
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.
102 103 104 105 106 |
# File 'lib/sass/tree/prop_node.rb', line 102
def perform!(environment)
@name = interpolate(@name, environment)
@value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
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.
55 56 57 58 |
# File 'lib/sass/tree/prop_node.rb', line 55
def pseudo_class_selector_message
return "" if @prop_syntax == :new || !value.empty?
"\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
end
|
#to_sass(tabs, opts = {})
41 42 43 |
# File 'lib/sass/css.rb', line 41
def to_sass(tabs, opts = {})
"#{' ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
end
|