Class: Sass::Tree::PropNode

Inherits:
Node show all
Defined in:
lib/sass/tree/prop_node.rb,
lib/sass/css.rb

Overview

A static node reprenting a CSS property.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #_perform, #balance, #cssize, #interpolate, #invisible?, #last, #perform, #perform_children, #render, #style, #to_s

Constructor Details

#initialize(name, value, prop_syntax) ⇒ PropNode

Returns a new instance of PropNode.

Parameters:

  • name (String)

    See #name

  • value (String)

    See #value

  • prop_syntax (Symbol)

    :new if this property uses a: b-style syntax, :old if it uses :a b-style syntax



33
34
35
36
37
38
39
# File 'lib/sass/tree/prop_node.rb', line 33

def initialize(name, value, prop_syntax)
  @name = name
  @value = value
  @tabs = 0
  @prop_syntax = prop_syntax
  super()
end

Instance Attribute Details

#nameString

The name of the property.

Returns:

  • (String)


9
10
11
# File 'lib/sass/tree/prop_node.rb', line 9

def name
  @name
end

#tabsFixnum

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

Returns:

  • (Fixnum)


27
28
29
# File 'lib/sass/tree/prop_node.rb', line 27

def tabs
  @tabs
end

#valueString, Script::Node

The value of the property, either a plain string or a SassScript parse tree.

Returns:



15
16
17
# File 'lib/sass/tree/prop_node.rb', line 15

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Compares the names and values of two properties.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)

    Whether or not this node and the other object are the same



46
47
48
# File 'lib/sass/tree/prop_node.rb', line 46

def ==(other)
  self.class == other.class && name == other.name && value == other.value && super
end

#_cssize(parent) (protected)

Converts nested properties into flat properties.

Parameters:

Raises:



76
77
78
79
80
81
82
83
84
# File 'lib/sass/tree/prop_node.rb', line 76

def _cssize(parent)
  node = super
  result = node.children.dup
  if !node.value.empty? || node.children.empty?
    node.send(:check!)
    result.unshift(node)
  end
  result
end

#_to_s(tabs) ⇒ String (protected)

Computes the CSS for the property.

Parameters:

  • tabs (Fixnum)

    The level of indentation for the CSS

Returns:

  • (String)

    The resulting CSS



66
67
68
69
# File 'lib/sass/tree/prop_node.rb', line 66

def _to_s(tabs)
  to_return = '  ' * (tabs - 1 + self.tabs) + name + ":" +
    (style == :compressed ? '' : ' ') + value + (style == :compressed ? "" : ";")
end

#cssize!(parent) (protected)

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

Parameters:



91
92
93
94
95
# File 'lib/sass/tree/prop_node.rb', line 91

def cssize!(parent)
  self.name = "#{parent.name}-#{name}" if parent
  self.tabs = parent.tabs + (parent.value.empty? ? 0 : 1) if parent && style == :nested
  super
end

#invalid_child?(child) ⇒ String (protected)

Returns an error message if the given child node is invalid, and false otherwise.

Sass::Tree::PropNode only allows other Sass::Tree::PropNodes and CommentNodes as children.

Parameters:

Returns:

  • (String)

    An error message if the child is invalid, or nil otherwise



114
115
116
117
118
# File 'lib/sass/tree/prop_node.rb', line 114

def invalid_child?(child)
  if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
    "Illegal nesting: Only properties may be nested beneath properties."
  end
end

#perform!(environment) (protected)

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

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values



102
103
104
105
106
# File 'lib/sass/tree/prop_node.rb', line 102

def perform!(environment)
  @name = interpolate(@name, environment)
  @value = @value.is_a?(String) ? interpolate(@value, environment) : @value.perform(environment).to_s
  super
end

#pseudo_class_selector_messageString

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.

Returns:

  • (String)

    The message



55
56
57
58
# File 'lib/sass/tree/prop_node.rb', line 55

def pseudo_class_selector_message
  return "" if @prop_syntax == :new || !value.empty?
  "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
end

#to_sass(tabs, opts = {})

See Also:



41
42
43
# File 'lib/sass/css.rb', line 41

def to_sass(tabs, opts = {})
  "#{'  ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
end