Class Index [+]

Quicksearch

Sass::Tree::PropNode

A static node reprenting a CSS property.

@see Sass::Tree

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]

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]

value[RW]

The value of the property.

@return [Sass::Script::Node]

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]

Public Class Methods

new(name, value, prop_syntax) click to toggle source

@param name [Array] 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
    # 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

Private Class Methods

val_to_sass(value, opts) click to toggle source

@private

     # File lib/sass/tree/prop_node.rb, line 181
181:       def val_to_sass(value, opts)
182:         val_to_sass_comma(value, opts).to_sass(opts)
183:       end
val_to_sass_comma(node, opts) click to toggle source
     # File lib/sass/tree/prop_node.rb, line 187
187:       def val_to_sass_comma(node, opts)
188:         return node unless node.is_a?(Sass::Script::Operation)
189:         return val_to_sass_concat(node, opts) unless node.operator == :comma
190: 
191:         Sass::Script::Operation.new(
192:           val_to_sass_concat(node.operand1, opts),
193:           val_to_sass_comma(node.operand2, opts),
194:           node.operator)
195:       end
val_to_sass_concat(node, opts) click to toggle source
     # File lib/sass/tree/prop_node.rb, line 197
197:       def val_to_sass_concat(node, opts)
198:         return node unless node.is_a?(Sass::Script::Operation)
199:         return val_to_sass_div(node, opts) unless node.operator == :concat
200: 
201:         Sass::Script::Operation.new(
202:           val_to_sass_div(node.operand1, opts),
203:           val_to_sass_concat(node.operand2, opts),
204:           node.operator)
205:       end
val_to_sass_div(node, opts) click to toggle source
     # File lib/sass/tree/prop_node.rb, line 207
207:       def val_to_sass_div(node, opts)
208:         unless node.is_a?(Sass::Script::Operation) && node.operator == :div &&
209:             node.operand1.is_a?(Sass::Script::Number) &&
210:             node.operand2.is_a?(Sass::Script::Number) &&
211:             (node.context == :equals || !node.operand1.original || !node.operand2.original)
212:           return node
213:         end
214: 
215:         Sass::Script::String.new("(#{node.to_sass(opts)})")
216:       end

Public Instance Methods

==(other) click to toggle source

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 63
63:     def ==(other)
64:       self.class == other.class && name == other.name && value == other.value && super
65:     end
pseudo_class_selector_message() click to toggle source

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

    # 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

_cssize(extends, parent) click to toggle source

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

     # 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
_to_s(tabs) click to toggle source

Computes the CSS for the property.

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

    # 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
cssize!(extends, parent) click to toggle source

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}
     # 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
invalid_child?(child) click to toggle source

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 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
perform!(environment) click to toggle source

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
     # 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
to_src(tabs, opts, fmt) click to toggle source

@see Node#to_src

    # 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

Private Instance Methods

check!() click to toggle source
     # File lib/sass/tree/prop_node.rb, line 156
156:     def check!
157:       if @options[:property_syntax] == :old && @prop_syntax == :new
158:         raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
159:       elsif @options[:property_syntax] == :new && @prop_syntax == :old
160:         raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
161:       elsif resolved_value.empty?
162:         raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
163:           pseudo_class_selector_message)
164:       end
165:     end
declaration(tabs = 0, opts = {:old => @prop_syntax == :old}, fmt = :sass) click to toggle source
     # File lib/sass/tree/prop_node.rb, line 167
167:     def declaration(tabs = 0, opts = {:old => @prop_syntax == :old}, fmt = :sass)
168:       name = self.name.map {|n| n.is_a?(String) ? n : "\#{#{n.to_sass(opts)}}"}.join
169:       if name[0] == ::
170:         raise Sass::SyntaxError.new("The \":#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
171:       end
172: 
173:       old = opts[:old] && fmt == :sass
174:       initial = old ? ':' : ''
175:       mid = old ? '' : ':'
176:       "#{'  ' * tabs}#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
177:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.