Class: Spider::TemplateBlocks::TagIf

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

- (Object) compile(options = {})



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spiderfw/templates/blocks/tag_if.rb', line 7

def compile(options={})
    init = ""
    cond = vars_to_scene(@el.get_attribute('sp:tag-if'))
    @el.remove_attribute('sp:tag-if')
    html = HTML.new(@el, @template)
    c = "if (#{cond})\n"
    c += html.get_start(options)
    c += "end\n"
    c, init = html.compile_content(c, init, options)
    tag_end = html.get_end(options)
    if (tag_end)
        c += "if (#{cond})\n"
        c += "  $out <<  '#{tag_end}'\n"
        c += "end\n"
    end
    return CompiledBlock.new(init, c)
end