Class: Spider::TemplateBlocks::Recurse

Inherits:
Block show all
Defined in:
lib/spiderfw/templates/blocks/recurse.rb

Instance Attribute Summary

Attributes inherited from Block

#allowed_blocks, #doctype, #el, #template

Instance Method Summary collapse

Methods inherited from Block

#compile_content, #compile_text, #escape_text, #get_following, #initialize, #inspect, #parse_content, var_to_scene, #var_to_scene, #vars_to_scene, vars_to_scene

Constructor Details

This class inherits a constructor from Spider::TemplateBlocks::Block

Instance Method Details

#compile(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spiderfw/templates/blocks/recurse.rb', line 7

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