Class: Sass::Tree::ForNode

Inherits:
Node show all
Defined in:
/var/www/sass-pages/.haml/lib/sass/tree/for_node.rb

Overview

A dynamic node representing a Sass @for loop.

See Also:

Instance Method Summary

Methods inherited from Node

#<<, #==, #_cssize, #_to_s, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invisible?, #perform, #perform!, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_sass, #to_scss

Constructor Details

- (ForNode) initialize(var, from, to, exclusive)

A new instance of ForNode

Parameters:

  • (String) var — The name of the loop variable
  • (Script::Node) from — The parse tree for the initial expression
  • (Script::Node) to — The parse tree for the final expression
  • (Boolean) exclusive — Whether to include to in the loop or stop just before


13
14
15
16
17
18
19
# File '/var/www/sass-pages/.haml/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

- (Array<Tree::Node>) _perform(environment) (protected)

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

Parameters:

  • (Sass::Environment) environment — The lexical environment containing variable and mixin values

Returns:

  • (Array<Tree::Node>) — The resulting static nodes

See Also:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File '/var/www/sass-pages/.haml/lib/sass/tree/for_node.rb', line 37

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

- (Boolean, String) invalid_child?(child) (protected)

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

ExtendNodes are valid within ForNodes.

Parameters:

Returns:

  • (Boolean, String) — Whether or not the child node is valid, as well as the error message to display if it is invalid


63
64
65
# File '/var/www/sass-pages/.haml/lib/sass/tree/for_node.rb', line 63

def invalid_child?(child)
  super unless child.is_a?(ExtendNode)
end

- to_src(tabs, opts, fmt) (protected)

See Also:



24
25
26
27
28
# File '/var/www/sass-pages/.haml/lib/sass/tree/for_node.rb', line 24

def to_src(tabs, opts, fmt)
  to = @exclusive ? "to" : "through"
  "#{'  ' * tabs}@for $#{dasherize(@var, opts)} from #{@from.to_sass(opts)} #{to} #{@to.to_sass(opts)}" +
    children_to_src(tabs, opts, fmt)
end