Class | Sass::Tree::ForNode
In: | lib/sass/tree/for_node.rb
Parent: | Node

A dynamic node representing a Sass `@for` loop.

@see Sass::Tree

### Methods

_perform invalid_child? new to_src

### Public Class methods

new(var, from, to, exclusive)

@param var [String] The name of the loop variable @param from [Script::Node] The parse tree for the initial expression @param to [Script::Node] The parse tree for the final expression @param exclusive [Boolean] Whether to include `to` in the loop

      or stop just before

[Source]

        # File lib/sass/tree/for_node.rb, line 13
    13:     def initialize(var, from, to, exclusive)
    14:       @var = var
    15:       @from = from
    16:       @to = to
    17:       @exclusive = exclusive
    18:       super()
    19:     end

### Protected Instance methods

_perform(environment)

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

@param environment [Sass::Environment] The lexical environment containing

      variable and mixin values

@return [Array<Tree::Node>] The resulting static nodes @see Sass::Tree

[Source]

        # File lib/sass/tree/for_node.rb, line 37
    37:     def _perform(environment)
    38:       from = @from.perform(environment)
    39:       to = @to.perform(environment)
    40:       from.assert_int!
    41:       to.assert_int!
    42:
    43:       to = to.coerce(from.numerator_units, from.denominator_units)
    44:       range = Range.new(from.to_i, to.to_i, @exclusive)
    45:
    46:       children = []
    47:       environment = Sass::Environment.new(environment)
    48:       range.each do |i|
    49:         environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units))
    50:         children += perform_children(environment)
    51:       end
    52:       children
    53:     end

invalid_child?(child)

Returns an error message if the given child node is invalid, and false otherwise.

{ExtendNode}s are valid within {ForNode}s.

@param child [Tree::Node] A potential child node. @return [Boolean, String] Whether or not the child node is valid,

      as well as the error message to display if it is invalid

[Source]

        # File lib/sass/tree/for_node.rb, line 63
    63:     def invalid_child?(child)
    64:       super unless child.is_a?(ExtendNode)
    65:     end

to_src(tabs, opts, fmt)

@see Node#to_src

[Source]

        # File lib/sass/tree/for_node.rb, line 24
    24:     def to_src(tabs, opts, fmt)
    25:       to = @exclusive ? "to" : "through"
    26:       "#{'  ' * tabs}@for $#{dasherize(@var, opts)} from #{@from.to_sass(opts)} #{to} #{@to.to_sass(opts)}" +
    27:         children_to_src(tabs, opts, fmt)
    28:     end

[Validate]