Sha256: 5f08767d034a296364f5a4f08f95f299466777fea1eb5394ea742e58b42d3da5

Contents?: true

Size: 1016 Bytes

Versions: 35

Compression:

Stored size: 1016 Bytes

Contents

module Volt
  class EachScope < ViewScope
    def initialize(handler, path, content, with_index)
      super(handler, path)

      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.try(:strip).inspect}, #{@index_name.try(:strip).inspect}, #{@path.inspect}) }")
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 lib/volt/server/html_parser/each_scope.rb
volt-0.9.7.pre7 lib/volt/server/html_parser/each_scope.rb
volt-0.9.7.pre6 lib/volt/server/html_parser/each_scope.rb
volt-0.9.7.pre5 lib/volt/server/html_parser/each_scope.rb
volt-0.9.7.pre3 lib/volt/server/html_parser/each_scope.rb
volt-0.9.7.pre2 lib/volt/server/html_parser/each_scope.rb
volt-0.9.6 lib/volt/server/html_parser/each_scope.rb
volt-0.9.6.pre3 lib/volt/server/html_parser/each_scope.rb
volt-0.9.6.pre2 lib/volt/server/html_parser/each_scope.rb
volt-0.9.6.pre1 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre12 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre11 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre9 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre8 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre7 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre6 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre5 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre4 lib/volt/server/html_parser/each_scope.rb
volt-0.9.5.pre3 lib/volt/server/html_parser/each_scope.rb