Class: Sass::Tree::PropNode

Inherits:
Node
  • Object
show all
Defined in:
lib/sass/tree/prop_node.rb

Overview

A static node reprenting a CSS property.

See Also:

Constant Summary

Constants inherited from Node

Node::SAVED_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #has_children, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #_around_dump, #_perform, #balance, #check_child!, #children_to_src, #cssize, #dasherize, #do_extend, #each, #invisible?, #perform, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_sass, #to_scss

Constructor Details

#initialize(name, value, prop_syntax) ⇒ PropNode

Returns a new instance of PropNode.

Parameters:



49
50
51
52
53
54
55
56
# File 'lib/sass/tree/prop_node.rb', line 49

def initialize(name, value, prop_syntax)
  @name = Haml::Util.strip_string_array(
    Haml::Util.merge_adjacent_strings(name))
  @value = value
  @tabs = 0
  @prop_syntax = prop_syntax
  super()
end

Instance Attribute Details

#nameArray<String, Sass::Script::Node>

The name of the property, interspersed with Script::Nodes representing #{}-interpolation. Any adjacent strings will be merged together.

Returns:



12
13
14
# File 'lib/sass/tree/prop_node.rb', line 12

def name
  @name
end

#resolved_nameString

The name of the property after any interpolated SassScript has been resolved. Only set once Node#perform has been called.

Returns:

  • (String)


19
20
21
# File 'lib/sass/tree/prop_node.rb', line 19

def resolved_name
  @resolved_name
end

#resolved_valueString

The value of the property after any interpolated SassScript has been resolved. Only set once Node#perform has been called.

Returns:

  • (String)


31
32
33
# File 'lib/sass/tree/prop_node.rb', line 31

def resolved_value
  @resolved_value
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)


43
44
45
# File 'lib/sass/tree/prop_node.rb', line 43

def tabs
  @tabs
end

#valueSass::Script::Node

The value of the property.

Returns:



24
25
26
# File 'lib/sass/tree/prop_node.rb', line 24

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



63
64
65
# File 'lib/sass/tree/prop_node.rb', line 63

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

#_cssize(extends, parent) (protected)

Converts nested properties into flat properties.

Parameters:

Raises:



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

def _cssize(extends, parent)
  node = super
  result = node.children.dup
  if !node.resolved_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



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

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

#cssize!(extends, parent) (protected)

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

Parameters:



119
120
121
122
123
# File 'lib/sass/tree/prop_node.rb', line 119

def cssize!(extends, parent)
  self.resolved_name = "#{parent.resolved_name}-#{resolved_name}" if parent
  self.tabs = parent.tabs + (parent.resolved_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



148
149
150
151
152
# File 'lib/sass/tree/prop_node.rb', line 148

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



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sass/tree/prop_node.rb', line 130

def perform!(environment)
  @resolved_name = run_interp(@name, environment)
  val = @value.perform(environment)
  @resolved_value =
    if @value.context == :equals && val.is_a?(Sass::Script::String)
      val.value
    else
      val.to_s
    end
  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



72
73
74
75
# File 'lib/sass/tree/prop_node.rb', line 72

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

#to_src(tabs, opts, fmt) (protected)

See Also:



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

def to_src(tabs, opts, fmt)
  res = declaration(tabs, opts, fmt)
  return res + "#{semi fmt}\n" if children.empty?
  res + children_to_src(tabs, opts, fmt).rstrip + semi(fmt) + "\n"
end