Class Sass::Tree::PropNode
In: lib/sass/tree/prop_node.rb
Parent: Node
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class SelectorPseudoClass Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Interpolation Variable Lexer CssLexer Number Bool String Parser Parser CssParser EvaluationContext SassParser StaticParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode VariableNode RootNode ExtendNode WarnNode WhileNode RuleNode MixinDefNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/node.rb lib/sass/script/literal.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptLexer ScriptParser RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_63_0.png

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

Private Class methods

@private

[Source]

     # 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

[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

[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

[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

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

Private Instance methods

[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

[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

[Validate]