Class: Sass::Tree::PropNode

Inherits:
Node
  • Object
show all
Defined in:
/Users/ceppstei/Projects/sass-lang/.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:



59
60
61
62
63
64
65
66
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 59

def initialize(name, value, prop_syntax)
  @name = Sass::Util.strip_string_array(
    Sass::Util.merge_adjacent_strings(name))
  @value = value
  @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 '/Users/ceppstei/Projects/sass-lang/.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:



48
49
50
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 48

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 '/Users/ceppstei/Projects/sass-lang/.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)


31
32
33
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 31

def resolved_value
  @resolved_value
end

- (Fixnum) 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:

  • (Fixnum)


43
44
45
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 43

def tabs
  @tabs
end

- (Sass::Script::Tree::Node) value

The value of the property.



24
25
26
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 24

def value
  @value
end

- (Sass::Source::Range) value_source_range

The source range in which the property value appears.

Returns:



53
54
55
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 53

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



73
74
75
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 73

def ==(other)
  self.class == other.class && name == other.name && value == other.value && super
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.



99
100
101
102
103
104
105
106
107
108
109
110
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 99

def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
  name = self.name.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
  if name[0] == ?:
    raise Sass::SyntaxError.new("The \"#{name}: #{self.class.val_to_sass(value, opts)}\"" +
                                " hack is not allowed in the Sass indented syntax")
  end

  old = opts[:old] && fmt == :sass
  initial = old ? ':' : ''
  mid = old ? '' : ':'
  "#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
end

- (Boolean) invisible?

A property node is invisible if its value is empty.

Returns:

  • (Boolean)


115
116
117
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 115

def invisible?
  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



82
83
84
85
86
87
88
89
90
91
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/prop_node.rb', line 82

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

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