lib/volt/server/html_parser/each_scope.rb in volt-0.8.26 vs lib/volt/server/html_parser/each_scope.rb in volt-0.8.27.beta1

- old
+ new

@@ -1,23 +1,26 @@ module Volt class EachScope < ViewScope - def initialize(handler, path, content) + def initialize(handler, path, content, with_index) super(handler, path) - # @content, @variable_name = content.strip.split(/ as /) - @content, @variable_name = content.split(/.each\s+do\s+\|/) - - @variable_name = @variable_name.gsub(/\|/, '') + if with_index + @content, @variable_name = content.split(/.each_with_index\s+do\s+\|/) + @variable_name, @index_name = @variable_name.gsub(/\|/, '').split(/\s*,\s*/) + else + @content, @variable_name = content.split(/.each\s+do\s+\|/) + @variable_name = @variable_name.gsub(/\|/, '') + end end def close_scope binding_number = @handler.scope[-2].binding_number @handler.scope[-2].binding_number += 1 @path += "/__template/#{binding_number}" super @handler.html << "<!-- $#{binding_number} --><!-- $/#{binding_number} -->" - @handler.scope.last.save_binding(binding_number, "lambda { |__p, __t, __c, __id| Volt::EachBinding.new(__p, __t, __c, __id, Proc.new { #{@content} }, #{@variable_name.inspect}, #{@path.inspect}) }") + @handler.scope.last.save_binding(binding_number, "lambda { |__p, __t, __c, __id| Volt::EachBinding.new(__p, __t, __c, __id, Proc.new { #{@content} }, #{@variable_name.inspect}, #{@index_name.inspect}, #{@path.inspect}) }") end end end