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

Methods

Attributes

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]

Public Class methods

@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

[Source]

    # 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

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 33
33:     def ==(other)
34:       self.class == other.class && name == other.name && value == other.value && super
35:     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 86
86:     def pseudo_class_selector_message
87:       return "" if @prop_syntax == :new || !value.empty?
88:       "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
89:     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

[Source]

    # 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.", @line)
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.", @line)
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:         message = "Invalid property: #{declaration.dump} (no value)." +
58:           pseudo_class_selector_message
59:         raise Sass::SyntaxError.new(message, @line)
60:       end
61:       
62:       join_string = case style
63:                     when :compact; ' '
64:                     when :compressed; ''
65:                     else "\n"
66:                     end
67:       spaces = '  ' * (tabs - 1)
68:       to_return = ''
69:       if !value.empty?
70:         to_return << "#{spaces}#{real_name}:#{style == :compressed ? '' : ' '}#{value};#{join_string}"
71:       end
72:       
73:       children.each do |kid|
74:         next if kid.invisible?
75:         to_return << kid.to_s(tabs, real_name) << join_string
76:       end
77:       
78:       (style == :compressed && parent_name) ? to_return : to_return[0...-1]
79:     end

@see Node#to_sass

[Source]

    # File lib/sass/css.rb, line 41
41:       def to_sass(tabs, opts = {})
42:         "#{'  ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
43:       end

Protected Instance methods

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 109
109:     def invalid_child?(child)
110:       if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
111:         "Illegal nesting: Only properties may be nested beneath properties."
112:       end
113:     end

Runs any SassScript that may be embedded in the property.

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

  variable and mixin values

[Source]

     # File lib/sass/tree/prop_node.rb, line 97
 97:     def perform!(environment)
 98:       @name = interpolate(@name, environment)
 99:       @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
100:       super
101:     end

[Validate]