| Class | Sass::Tree::PropNode |
| In: |
lib/sass/css.rb
lib/sass/tree/prop_node.rb |
| Parent: | Object |
A static node reprenting a CSS property.
@see Sass::Tree
| name | [RW] |
The name of the property.
@return [String] |
| value | [RW] |
The value of the property, either a plain string or a SassScript parse
tree.
@return [String, Script::Node] |
@param name [String] See \{name} @param value [String] See \{value} @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
`:old` if it uses `:a b`-style syntax
# File lib/sass/tree/prop_node.rb, line 21
21: def initialize(name, value, prop_syntax)
22: @name = name
23: @value = value
24: @prop_syntax = prop_syntax
25: super()
26: end
Compares the names and values of two properties.
@param other [Object] The object to compare with @return [Boolean] Whether or not this node and the other object
are the same
# File lib/sass/tree/prop_node.rb, line 33
33: def ==(other)
34: self.class == other.class && name == other.name && value == other.value && super
35: end
Computes the CSS for the property.
@param tabs [Fixnum] The level of indentation for the CSS @param parent_name [String] The name of the parent property (e.g. `text`) or nil @return [String] The resulting CSS @raise [Sass::SyntaxError] if the property uses invalid syntax
# File lib/sass/tree/prop_node.rb, line 43
43: def to_s(tabs, parent_name = nil)
44: if @options[:property_syntax] == :old && @prop_syntax == :new
45: raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
46: elsif @options[:property_syntax] == :new && @prop_syntax == :old
47: raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
48: end
49:
50: if value[-1] == ?;
51: raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).", @line)
52: end
53: real_name = name
54: real_name = "#{parent_name}-#{real_name}" if parent_name
55:
56: if value.empty? && children.empty?
57: raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value).", @line)
58: end
59:
60: join_string = case style
61: when :compact; ' '
62: when :compressed; ''
63: else "\n"
64: end
65: spaces = ' ' * (tabs - 1)
66: to_return = ''
67: if !value.empty?
68: to_return << "#{spaces}#{real_name}:#{style == :compressed ? '' : ' '}#{value};#{join_string}"
69: end
70:
71: children.each do |kid|
72: next if kid.invisible?
73: to_return << kid.to_s(tabs, real_name) << join_string
74: end
75:
76: (style == :compressed && parent_name) ? to_return : to_return[0...-1]
77: end
@see Node#to_sass
# File lib/sass/css.rb, line 39
39: def to_sass(tabs, opts = {})
40: "#{' ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
41: end
Returns an error message if the given child node is invalid, and false otherwise.
{PropNode} only allows other {PropNode}s and {CommentNode}s as children. @param child [Tree::Node] A potential child node @return [String] An error message if the child is invalid, or nil otherwise
# File lib/sass/tree/prop_node.rb, line 97
97: def invalid_child?(child)
98: if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
99: "Illegal nesting: Only properties may be nested beneath properties."
100: end
101: end
Runs any SassScript that may be embedded in the property.
@param environment [Sass::Environment] The lexical environment containing
variable and mixin values
# File lib/sass/tree/prop_node.rb, line 85
85: def perform!(environment)
86: @name = interpolate(@name, environment)
87: @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
88: super
89: end