Class: Less2Sass::Less::Tree::RuleNode

Inherits:
Node
  • Object
show all
Defined in:
lib/less2sass/less/tree/rule_node.rb

Overview

A RuleNode in Less can be a CSS rule, or a variable definition.

Examples:

- color: @var;
- @var: 50px;

The Sass equivalent is Sass::Tree::VariableNode or Sass::Tree::RuleNode.

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #has_children, #has_parent, #line, #parent, #ref_vars

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #contains_variables?, #creates_context?, #each, #get_referenced_variable_names, #initialize, #transform

Constructor Details

This class inherits a constructor from Less2Sass::Less::Tree::Node

Instance Attribute Details

#currentFileInfoObject

Returns the value of attribute currentFileInfo.



19
20
21
# File 'lib/less2sass/less/tree/rule_node.rb', line 19

def currentFileInfo
  @currentFileInfo
end

#globalObject

Returns the value of attribute global.



24
25
26
# File 'lib/less2sass/less/tree/rule_node.rb', line 24

def global
  @global
end

#guardedObject

Returns the value of attribute guarded.



23
24
25
# File 'lib/less2sass/less/tree/rule_node.rb', line 23

def guarded
  @guarded
end

#importantObject

Returns the value of attribute important.



16
17
18
# File 'lib/less2sass/less/tree/rule_node.rb', line 16

def important
  @important
end

#indexObject

Returns the value of attribute index.



18
19
20
# File 'lib/less2sass/less/tree/rule_node.rb', line 18

def index
  @index
end

#inlineObject

Returns the value of attribute inline.



20
21
22
# File 'lib/less2sass/less/tree/rule_node.rb', line 20

def inline
  @inline
end

#mergeObject

Returns the value of attribute merge.



17
18
19
# File 'lib/less2sass/less/tree/rule_node.rb', line 17

def merge
  @merge
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/less2sass/less/tree/rule_node.rb', line 14

def name
  @name
end

#valueObject

Returns the value of attribute value.



15
16
17
# File 'lib/less2sass/less/tree/rule_node.rb', line 15

def value
  @value
end

#variableObject

Returns the value of attribute variable.



21
22
23
# File 'lib/less2sass/less/tree/rule_node.rb', line 21

def variable
  @variable
end

Instance Method Details

#is_variable_definition?Boolean

Returns whether the node is a variable definition.



34
35
36
# File 'lib/less2sass/less/tree/rule_node.rb', line 34

def is_variable_definition?
  @variable
end

#references?(variable) ⇒ Boolean

Checks, if the given variable is referenced by the variable’s definition



43
44
45
46
47
48
49
# File 'lib/less2sass/less/tree/rule_node.rb', line 43

def references?(variable)
  if variable.is_a?(String)
    @ref_vars.include?(variable)
  else
    @ref_vars.include?(variable.name)
  end
end

#sass_nameObject



27
28
29
# File 'lib/less2sass/less/tree/rule_node.rb', line 27

def sass_name
  @name[1..-1] if @name
end

#to_sass::Sass::Tree::VariableNode, ::Sass::Tree::PropNode

Note:

Always put on a new line.

Converts this node to Sass::Tree::VariableNode, if it’s a variable definition. Otherwise it must be a CSS property declaration and gets converted to Sass::Tree::PropNode.

The 3rd param of ‘::Sass::Tree::PropNode` refers to the CSS syntax to be outputted. Its value can be:

- `:new` using `a: b`-style syntax
- `:old` using `:a b`-style syntax

For the sake of simplicity, we’ll use the new syntax only. Later could be set in cli arguments as option.

See Also:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/less2sass/less/tree/rule_node.rb', line 66

def to_sass
  node ||=
    begin
      if is_variable_definition?
        ::Sass::Tree::VariableNode.new(
          sass_name, @value.to_sass, @guarded, @global
        )
      else
        # TODO: Don't forget about the `#{}`
        ::Sass::Tree::PropNode.new(
          process_property_name, @value.to_sass, :new
        )
      end
    end
  node(node, line(:new))
end