Class Sass::Tree::ForNode
In: lib/sass/tree/for_node.rb
Parent: Node
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class SelectorPseudoClass Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Interpolation Variable Lexer CssLexer Number Bool String Parser Parser CssParser EvaluationContext StaticParser SassParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode ExtendNode VariableNode WarnNode RootNode WhileNode RuleNode MixinDefNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/literal.rb lib/sass/script/node.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptLexer ScriptParser RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_85_0.png

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

@see Sass::Tree

Methods

_perform   invalid_child?   new   to_src  

Public Class methods

@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

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

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

@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]