Class Index [+]

Quicksearch

Sass::Tree::ForNode

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

@see Sass::Tree

Public Class Methods

new(var, from, to, exclusive) click to toggle source

@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
    # 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) click to toggle source

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] The resulting static nodes @see Sass::Tree

    # 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) click to toggle source

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
    # 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) click to toggle source

@see Node#to_src

    # 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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.