Class: Sass::Tree::ForNode

Inherits:
Node show all
Defined in:
lib/sass/tree/for_node.rb

Overview

A dynamic node representing a Sass @for loop.

See Also:

Instance Attribute Summary

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_to_s, #balance, #interpolate, #invalid_child?, #invisible?, #last, #perform, #perform!, #perform_children, #render, #style, #to_s, #to_sass

Constructor Details

#initialize(var, from, to, exclusive) ⇒ ForNode

Returns a new instance of ForNode.

Parameters:

  • var (String)

    The name of the loop variable

  • from (Script::Node)

    The parse tree for the initial expression

  • to (Script::Node)

    The parse tree for the final expression

  • exclusive (Boolean)

    Whether to include to in the loop or stop just before



13
14
15
16
17
18
19
# File 'lib/sass/tree/for_node.rb', line 13

def initialize(var, from, to, exclusive)
  @var = var
  @from = from
  @to = to
  @exclusive = exclusive
  super()
end

Instance Method Details

#_perform(environment) ⇒ Array<Tree::Node> (protected)

Runs the child nodes once for each time through the loop, varying the variable each time.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values

Returns:

  • (Array<Tree::Node>)

    The resulting static nodes

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sass/tree/for_node.rb', line 30

def _perform(environment)
  from = @from.perform(environment)
  to = @to.perform(environment)
  from.assert_int!
  to.assert_int!

  to = to.coerce(from.numerator_units, from.denominator_units)
  range = Range.new(from.to_i, to.to_i, @exclusive)

  children = []
  environment = Sass::Environment.new(environment)
  range.each do |i|
    environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units))
    children += perform_children(environment)
  end
  children
end