Class: Spider::TemplateBlocks::Run

Inherits:
Block show all
Defined in:
lib/spiderfw/templates/blocks/run.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



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/spiderfw/templates/blocks/run.rb', line 11

def compile(options={})
    c = ""
    init = ""
    runtime_contents = @el.children ? @el.children_of_type('tpl:runtime-content') : []
    run_attributes = @el.attributes.to_hash
    if @el.has_attribute?('obj')
        scene_obj = var_to_scene(run_attributes.delete('obj'))
        widget_id = run_attributes.delete('widget')
        if widget_id
            runtime_content_obj = "@widgets[#{widget_id}]" 
        else
            runtime_content_obj = scene_obj
        end
        # runtime_contents.each do |rc|
        #     content = escape_runtime_content(rc.innerHTML)
        #     condition = ""
        #     if (rc.has_attribute?('for'))
        #         condition = " if #{runtime_content_obj}.local_id.to_s == '#{rc.get_attribute('for')}'"
        #     end
        #     parse_runtime = "#{runtime_content_obj}.parse_runtime_content_xml('<sp:widget-content>#{content}</sp:widget-content>')#{condition}\n"
        #     if widget_id
        #         init += parse_runtime
        #     else
        #         c += parse_runtime
        #     end
        #     @el.children.delete(rc)
        # end
        # unless @el.innerHTML.strip.empty?
        #     content = escape_runtime_content(@el.innerHTML)
        #     parse_runtime = "#{runtime_content_obj}.parse_runtime_content_xml('<sp:widget-content>#{content}</sp:widget-content>')\n"
        #     if widget_id
        #         init += parse_runtime
        #     else
        #         c += parse_runtime
        #     end
        # end
        if widget_id && @el.children
            attributes = @el.children_of_type('sp:attribute')
            init += "@owner.widget_attributes[#{widget_id}] ||= {}\n" if attributes.length > 0
            attributes.each do |at|
                attr_name = at.get_attribute('name').gsub("'", "\\\\'")
                attr_value = at.get_attribute('value').gsub("'", "\\\\'")

                init += "@owner.widget_attributes[#{widget_id}][:\"#{attr_name}\"] = '#{attr_value}'\n"
            end
        end
        @el.innerHTML = ''
        c += "#{scene_obj}.render if (#{scene_obj})\n"
    end
    return CompiledBlock.new(init, c)
end

#escape_runtime_content(html) ⇒ Object



7
8
9
# File 'lib/spiderfw/templates/blocks/run.rb', line 7

def escape_runtime_content(html)
    html.strip.gsub("'", "\\\\'")
end