Class: Less2Sass::Less::Tree::RulesetNode
- 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
-
#_lookups ⇒ Object
Returns the value of attribute _lookups.
-
#firstRoot ⇒ Object
Returns the value of attribute firstRoot.
-
#root ⇒ Object
Returns the value of attribute root.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#selectors ⇒ Object
Returns the value of attribute selectors.
-
#strictImports ⇒ Object
Returns the value of attribute strictImports.
Attributes inherited from Node
#children, #has_children, #has_parent, #line, #parent, #ref_vars
Instance Method Summary collapse
- #creates_context? ⇒ Boolean
-
#initialize(options = nil) ⇒ RulesetNode
constructor
A new instance of RulesetNode.
-
#to_sass(options = nil) ⇒ ::Sass::Tree::RootNode, ::Sass::Tree::RuleNode
Converts node to Sass::Tree::RootNode if it’s root.
-
#transform(env = nil) ⇒ Void
Transforms the ruleset node by reordering the child nodes.
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( = nil) super @options = unless .nil? end |
Instance Attribute Details
#_lookups ⇒ Object
Returns the value of attribute _lookups.
10 11 12 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10 def _lookups @_lookups end |
#firstRoot ⇒ Object
Returns the value of attribute firstRoot.
10 11 12 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10 def firstRoot @firstRoot end |
#root ⇒ Object
Returns the value of attribute root.
10 11 12 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10 def root @root end |
#rules ⇒ Object
Returns the value of attribute rules.
10 11 12 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10 def rules @rules end |
#selectors ⇒ Object
Returns the value of attribute selectors.
10 11 12 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 10 def selectors @selectors end |
#strictImports ⇒ Object
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
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
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.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/less2sass/less/tree/ruleset_node.rb', line 52 def to_sass( = nil) if @root node = node(::Sass::Engine.new('', ).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.
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 |