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
-
#indentation ⇒ Fixnum
How deep this property is indented relative to a normal property.
-
#name ⇒ String
The name of the 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.
-
#_perform(environment) ⇒ Object
protected
Returns this node's fully-resolved child properties, and/or this node.
-
#_to_s(tabs) ⇒ String
protected
Computes the CSS for the property.
-
#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) ⇒ Object
protected
Runs any SassScript that may be embedded in the property, and invludes the parent property, if any.
- #to_sass(tabs, opts = {}) ⇒ Object
Methods inherited from Node
#<<, #balance, #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
@indentation = 0
@prop_syntax = prop_syntax
super()
end
|
Instance Attribute Details
#indentation ⇒ 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 static 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 indentation
@indentation
end
|
#name ⇒ String
The name of the property.
9 10 11 |
# File 'lib/sass/tree/prop_node.rb', line 9
def name
@name
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
|
#_perform(environment) ⇒ Object (protected)
Returns this node's fully-resolved child properties, and/or this node.
76 77 78 79 80 81 |
# File 'lib/sass/tree/prop_node.rb', line 76
def _perform(environment)
node = super
result = node.children.dup
result.unshift(node) if !node.value.empty? || node.children.empty?
result
end
|
#_to_s(tabs) ⇒ String (protected)
Computes the CSS for the property.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sass/tree/prop_node.rb', line 57
def _to_s(tabs)
if @options[:property_syntax] == :old && @prop_syntax == :new
raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
elsif @options[:property_syntax] == :new && @prop_syntax == :old
raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
elsif value[-1] == ?;
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).")
elsif value.empty?
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value).")
end
to_return = ' ' * (tabs - 1 + indentation) + name + ":" +
(style == :compressed ? '' : ' ') + value + (style == :compressed ? "" : ";")
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.
106 107 108 109 110 |
# File 'lib/sass/tree/prop_node.rb', line 106
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) ⇒ Object (protected)
Runs any SassScript that may be embedded in the property, and invludes the parent property, if any.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sass/tree/prop_node.rb', line 88 def perform!(environment) @name = interpolate(@name, environment) @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s super # Once we've called super, the child nodes have been dup'ed # so we can destructively modify them children.select {|c| c.is_a?(PropNode)}.each do |c| c.name = "#{name}-#{c.name}" c.indentation += 1 if style == :nested && [email protected]? end end |
#to_sass(tabs, opts = {}) ⇒ Object
39 40 41 |
# File 'lib/sass/css.rb', line 39
def to_sass(tabs, opts = {})
"#{' ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
end
|