Class: Spider::TemplateBlocks::Comment

Inherits:
Block show all
Defined in:
lib/spiderfw/templates/blocks/comment.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
36
37
38
# File 'lib/spiderfw/templates/blocks/comment.rb', line 7

def compile(options={})
    init = nil
    c = ""
    str = nil
    mode = nil
    if (@el.content[0].chr == '-')
        mode = :internal
    elsif (@el.content[0].chr == '+')
        mode = :parse
    else
        mode = :verbatim
    end
    if (mode == :parse)
        str = ""
        rest = Spider::Template.scan_scene_vars(@el.to_s) do |type, val|
            case type
            when :plain
                str += escape_text(val)
            when :var
                str += "'+("+vars_to_scene(val)+").to_s+'"
            end
        end
        str += escape_text(rest)
    elsif (mode == :verbatim)
        str = escape_text(@el.to_s)
    else
        str = nil
    end
    c += "$out << '#{str}'\n" if str
    #c += "$out << '#{@el.to_s}'\n"
    return CompiledBlock.new(init, c)
end