Class Sass::Tree::PropNode
In: lib/sass/tree/prop_node.rb
Parent: Node

A static node reprenting a CSS property.

@see Sass::Tree

Methods

Attributes

name  [RW]  The name of the property, interspersed with {Sass::Script::Node}s representing `#{}`-interpolation. Any adjacent strings will be merged together.

@return [Array<String, Sass::Script::Node>]

resolved_name  [RW]  The name of the property after any interpolated SassScript has been resolved. Only set once \{Tree::Node#perform} has been called.

@return [String]

resolved_value  [RW]  The value of the property after any interpolated SassScript has been resolved. Only set once \{Tree::Node#perform} has been called.

@return [String]

tabs  [RW]  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

@return [Fixnum]

value  [RW]  The value of the property.

@return [Sass::Script::Node]

Public Class methods

@param name [Array<String, Sass::Script::Node>] See \{name} @param value [Sass::Script::Node] See \{value} @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,

  `:old` if it uses `:a b`-style syntax

[Source]

    # File lib/sass/tree/prop_node.rb, line 49
49:     def initialize(name, value, prop_syntax)
50:       @name = Haml::Util.strip_string_array(
51:         Haml::Util.merge_adjacent_strings(name))
52:       @value = value
53:       @tabs = 0
54:       @prop_syntax = prop_syntax
55:       super()
56:     end

Public Instance methods

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

[Source]

    # File lib/sass/tree/prop_node.rb, line 63
63:     def ==(other)
64:       self.class == other.class && name == other.name && value == other.value && super
65:     end

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.

@return [String] The message

[Source]

    # File lib/sass/tree/prop_node.rb, line 72
72:     def pseudo_class_selector_message
73:       return "" if @prop_syntax == :new || !value.is_a?(Sass::Script::String) || !value.value.empty?
74:       "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
75:     end

Protected Instance methods

Converts nested properties into flat properties.

@param extends [Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}]

  The extensions defined for this tree

@param parent [PropNode, nil] The parent node of this node,

  or nil if the parent isn't a {PropNode}

@raise [Sass::SyntaxError] if the property uses invalid syntax

[Source]

     # File lib/sass/tree/prop_node.rb, line 102
102:     def _cssize(extends, parent)
103:       node = super
104:       result = node.children.dup
105:       if !node.resolved_value.empty? || node.children.empty?
106:         node.send(:check!)
107:         result.unshift(node)
108:       end
109:       result
110:     end

Computes the CSS for the property.

@param tabs [Fixnum] The level of indentation for the CSS @return [String] The resulting CSS

[Source]

    # File lib/sass/tree/prop_node.rb, line 90
90:     def _to_s(tabs)
91:       to_return = '  ' * (tabs - 1 + self.tabs) + resolved_name + ":" +
92:         (style == :compressed ? '' : ' ') + resolved_value + (style == :compressed ? "" : ";")
93:     end

Updates the name and indentation of this node based on the parent name and nesting level.

@param extends [Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}]

  The extensions defined for this tree

@param parent [PropNode, nil] The parent node of this node,

  or nil if the parent isn't a {PropNode}

[Source]

     # File lib/sass/tree/prop_node.rb, line 119
119:     def cssize!(extends, parent)
120:       self.resolved_name = "#{parent.resolved_name}-#{resolved_name}" if parent
121:       self.tabs = parent.tabs + (parent.resolved_value.empty? ? 0 : 1) if parent && style == :nested
122:       super
123:     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

[Source]

     # File lib/sass/tree/prop_node.rb, line 148
148:     def invalid_child?(child)
149:       if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
150:         "Illegal nesting: Only properties may be nested beneath properties."
151:       end
152:     end

Runs any SassScript that may be embedded in the property, and invludes the parent property, if any.

@param environment [Sass::Environment] The lexical environment containing

  variable and mixin values

[Source]

     # File lib/sass/tree/prop_node.rb, line 130
130:     def perform!(environment)
131:       @resolved_name = run_interp(@name, environment)
132:       val = @value.perform(environment)
133:       @resolved_value =
134:         if @value.context == :equals && val.is_a?(Sass::Script::String)
135:           val.value
136:         else
137:           val.to_s
138:         end
139:       super
140:     end

@see Node#to_src

[Source]

    # File lib/sass/tree/prop_node.rb, line 80
80:     def to_src(tabs, opts, fmt)
81:       res = declaration(tabs, opts, fmt)
82:       return res + "#{semi fmt}\n" if children.empty?
83:       res + children_to_src(tabs, opts, fmt).rstrip + semi(fmt) + "\n"
84:     end

[Validate]