Sha256: 1a318f0bc66b57b25083c825515a3719ec60bd6c448327956188d9a93c9f62b5

Contents?: true

Size: 1.16 KB

Versions: 40

Compression:

Stored size: 1.16 KB

Contents

require 'spiderfw/templates/template_blocks'

module Spider; module TemplateBlocks
    
    class Recurse < Block
        
        def compile(options={})
            init = ""
            c = ""
            lambda_name = @el.attributes['lambda']
            vars_attr = @el.attributes['vars']
            vars = nil
            unless vars_attr.blank?
                vars = {}
                var_pairs = vars_attr.split(/\s*,\s*/)
                var_pairs.each do |pair|
                    from, to = pair.split(/\s*=>\s*/)
                    vars[from] = to
                end
                c += "___prev_vars = {}\n"
                vars.each do |from, to|
                    c += "___prev_vars[:#{from}] = #{from}\n"
                end
                vars.each do |from, to|
                    c += "#{from} = #{to}\n"
                end
            end
            c += "#{lambda_name}.call\n"
            if vars
                vars.each do |from, to|
                    c += "#{from} = ___prev_vars[:#{from}]\n"
                end
            end            
            return CompiledBlock.new(init, c)
        end
        
        
    end
    
    
end; end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-1.0.0 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.39 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.38 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.37 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.35 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.34 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.33 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.32 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.31 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.30 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.29 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.28 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.27 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.26 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.26.pre1 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.25 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.24 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.23 lib/spiderfw/templates/blocks/recurse.rb
spiderfw-0.6.22 lib/spiderfw/templates/blocks/recurse.rb