Created
March 3, 2011 15:55
-
-
Save did/852986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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