Class: Less2Sass::Less::Tree::RulesetNode

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

Overview

The Ruleset node is the root node of every Less AST. It also means a block of selector and its inner rules.

Its Sass equivalent is a Sass::Tree::RootNode, 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?, #each, #get_referenced_variable_names

Constructor Details

#initialize(options = nil) ⇒ RulesetNode

Returns a new instance of RulesetNode.



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

def initialize(options = nil)
  super
  @options = options unless options.nil?
end

Instance Attribute Details

#_lookupsObject

Returns the value of attribute _lookups.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def _lookups
  @_lookups
end

#firstRootObject

Returns the value of attribute firstRoot.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def firstRoot
  @firstRoot
end

#rootObject

Returns the value of attribute root.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def root
  @root
end

#rulesObject

Returns the value of attribute rules.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def rules
  @rules
end

#selectorsObject

Returns the value of attribute selectors.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def selectors
  @selectors
end

#strictImportsObject

Returns the value of attribute strictImports.



10
11
12
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10

def strictImports
  @strictImports
end

Instance Method Details

#creates_context?Boolean

Returns:

  • (Boolean)

See Also:



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

def creates_context?
  true
end

#to_sass(options = nil) ⇒ ::Sass::Tree::RootNode, ::Sass::Tree::RuleNode

Note:

I both cases the node is placed on a new line.

Converts node to Sass::Tree::RootNode if it’s root. Otherwise it converts to Sass::Tree::RuleNode.

In case of root node, all the children nodes have to be converted. Otherwise rule nodes only.

Returns:

  • (::Sass::Tree::RootNode, ::Sass::Tree::RuleNode)

See Also:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 52

def to_sass(options = nil)
  if @root
    node = node(::Sass::Engine.new('', options).to_tree, line(:new))
    children = @children
  else
    node = node(::Sass::Tree::RuleNode.new(get_full_selector), line(:new))
    children = @rules.is_a?(Array) ? @rules : [@rules]
  end
  children.each { |c| node << c.to_sass }
  node
end

#transform(env = nil) ⇒ Void

Transforms the ruleset node by reordering the child nodes.

1. Creates a new environment and puts the child
   nodes into it.

2. Further traverses the tree of nodes and transforms them, as well.

3. Saves the re-ordered rules and child nodes.

Parameters:

Returns:

  • (Void)


34
35
36
37
38
39
40
41
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 34

def transform(env = nil)
  env = Less2Sass::Less::Environment.new(env)
  env.set_environment(@children)
  env.build
  super(env)
  @rules = env.get_ordered_child_nodes
  @children = @rules
end