Class: Sass::Tree::PropNode

Inherits:
Node
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb

Overview

A static node representing a CSS property.

See Also:

Instance Attribute Summary (collapse)

Attributes inherited from Node

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

Instance Method Summary (collapse)

Methods inherited from Node

#<<, #balance, #bubbles?, #css, #css_with_sourcemap, #deep_copy, #each, #inspect, #style, #to_sass, #to_scss

Constructor Details

- (PropNode) initialize(name, value, prop_syntax)

Returns a new instance of PropNode

Parameters:



70
71
72
73
74
75
76
77
78
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 70

def initialize(name, value, prop_syntax)
  @name = Sass::Util.strip_string_array(
    Sass::Util.merge_adjacent_strings(name))
  @value = Sass::Util.merge_adjacent_strings(value)
  @value = Sass::Util.strip_string_array(@value) unless custom_property?
  @tabs = 0
  @prop_syntax = prop_syntax
  super()
end

Instance Attribute Details

- (Array<String, Sass::Script::Tree::Node>) name

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

Returns:



12
13
14
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 12

def name
  @name
end

- (Sass::Source::Range) name_source_range

The source range in which the property name appears.

Returns:



52
53
54
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 52

def name_source_range
  @name_source_range
end

- (String) resolved_name

The name of the property after any interpolated SassScript has been resolved. Only set once Visitors::Perform has been run.

Returns:

  • (String)


19
20
21
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 19

def resolved_name
  @resolved_name
end

- (String) resolved_value

The value of the property after any interpolated SassScript has been resolved. Only set once Visitors::Perform has been run.

Returns:

  • (String)


35
36
37
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 35

def resolved_value
  @resolved_value
end

- (Integer) tabs

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:

  • (Integer)


47
48
49
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 47

def tabs
  @tabs
end

- (Array<String, Sass::Script::Tree::Node>) value

The value of the property.

For most properties, this will just contain a single Node. However, for CSS variables, it will contain multiple strings and nodes representing interpolation. Any adjacent strings will be merged together.

Returns:



28
29
30
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 28

def value
  @value
end

- (Sass::Source::Range) value_source_range

The source range in which the property value appears.

Returns:



57
58
59
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 57

def value_source_range
  @value_source_range
end

Instance Method Details

- (Boolean) ==(other)

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



85
86
87
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 85

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

- (Boolean) custom_property?

Whether this represents a CSS custom property.

Returns:

  • (Boolean)


62
63
64
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 62

def custom_property?
  name.first.is_a?(String) && name.first.start_with?("--")
end

- declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)

Computes the Sass or SCSS code for the variable declaration. This is like Node#to_scss or Node#to_sass, except it doesn't print any child properties or a trailing semicolon.

Parameters:

  • opts ({Symbol => Object}) (defaults to: {:old => @prop_syntax == :old})

    The options hash for the tree.

  • fmt (Symbol) (defaults to: :sass)

    :scss or :sass.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 112

def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
  name = self.name.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
  value = self.value.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
  value = "(#{value})" if value_needs_parens?

  if name[0] == ?:
    raise Sass::SyntaxError.new("The \"#{name}: #{value}\"" +
                                " hack is not allowed in the Sass indented syntax")
  end

  # The indented syntax doesn't support newlines in custom property values,
  # but we can losslessly convert them to spaces instead.
  value = value.tr("\n", " ") if fmt == :sass

  old = opts[:old] && fmt == :sass
  "#{old ? ':' : ''}#{name}#{old ? '' : ':'}#{custom_property? ? '' : ' '}#{value}".rstrip
end

- (Boolean) invisible?

A property node is invisible if its value is empty.

Returns:

  • (Boolean)


133
134
135
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 133

def invisible?
  !custom_property? && resolved_value.empty?
end

- (String) pseudo_class_selector_message

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



94
95
96
97
98
99
100
101
102
103
104
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/prop_node.rb', line 94

def pseudo_class_selector_message
  if @prop_syntax == :new ||
      custom_property? ||
      !value.first.is_a?(Sass::Script::Tree::Literal) ||
      !value.first.value.is_a?(Sass::Script::Value::String) ||
      !value.first.value.value.empty?
    return ""
  end

  "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
end