Skip to content

Instantly share code, notes, and snippets.

@did
Created March 3, 2011 15:55
Show Gist options
  • Save did/852986 to your computer and use it in GitHub Desktop.
Save did/852986 to your computer and use it in GitHub Desktop.
require 'sass/scss/parser'
module Sass
module SCSS
class Parser
private
def each_directive
list = tok! STRING
ss
tok!(/do \$/)
var_i = tok! IDENT
ss
tok!(/and \$/)
var_v = tok! IDENT
ss
block(node(Sass::Tree::EachNode.new(list, var_i, var_v)), :directive)
end
def special_directive_with_each(name)
if name == 'each'
send(:each_directive)
else
special_directive_without_each(name)
end
end
alias_method_chain :special_directive, :each
end
end
module Tree
class EachNode < Node
def initialize(list, var_v, var_i)
@list = list.gsub(/["']/, '').split(' ')
@var_v = var_v
@var_i = var_i
super()
end
def _perform(environment)
children = []
environment = Sass::Environment.new(environment)
@list.each_with_index do |name, i|
environment.set_local_var(@var_v, Sass::Script::String.new(name))
environment.set_local_var(@var_i, Sass::Script::Number.new(i + 1))
children += perform_children(environment)
end
children
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment