Class: Spider::TemplateBlocks::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/spiderfw/templates/template_blocks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(el, template = nil, allowed_blocks = nil) ⇒ Block



93
94
95
96
97
98
# File 'lib/spiderfw/templates/template_blocks.rb', line 93

def initialize(el, template=nil, allowed_blocks=nil)
    @el = el
    @template = template
    @allowed_blocks = allowed_blocks
    @content_blocks = []
end

Instance Attribute Details

#allowed_blocksObject (readonly)

Returns the value of attribute allowed_blocks



90
91
92
# File 'lib/spiderfw/templates/template_blocks.rb', line 90

def allowed_blocks
  @allowed_blocks
end

#doctypeObject

Returns the value of attribute doctype



91
92
93
# File 'lib/spiderfw/templates/template_blocks.rb', line 91

def doctype
  @doctype
end

#elObject (readonly)

Returns the value of attribute el



90
91
92
# File 'lib/spiderfw/templates/template_blocks.rb', line 90

def el
  @el
end

#templateObject (readonly)

Returns the value of attribute template



90
91
92
# File 'lib/spiderfw/templates/template_blocks.rb', line 90

def template
  @template
end

Class Method Details

.var_to_scene(var, container = 'self') ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/spiderfw/templates/template_blocks.rb', line 163

def self.var_to_scene(var, container='self')
    first, rest = var.split('.', 2)
    if (first =~ /([^\[]+)(\[.+)/)
        var_name = $1
        array_rest = $2
    else
        var_name = first
    end
    if (var[0].chr == '@')
        scene_var = "#{container}[:#{var_name[1..-1]}]"
    else
        scene_var = var_name
    end
    scene_var += array_rest if (array_rest)
    scene_var += '.'+rest if (rest)
    return scene_var
end

.vars_to_scene(str, container = 'self') ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/spiderfw/templates/template_blocks.rb', line 120

def self.vars_to_scene(str, container='self')
    res = ""
    Spider::Template.scan_scene_vars(str) do |type, val|
        case type
        when :plain
            res += val
        when :var
            res += "#{container}[:#{val}]"
        end
    end
    res
end

Instance Method Details

#compile_content(c = '', init = '', options = {}) ⇒ Object



104
105
106
107
108
# File 'lib/spiderfw/templates/template_blocks.rb', line 104

def compile_content(c='', init='', options={})
    options[:allowed_blocks] ||= @allowed_blocks
    options[:template] ||= @template
    TemplateBlocks.compile_content(@el, c, init, options)
end

#compile_text(str) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/spiderfw/templates/template_blocks.rb', line 137

def compile_text(str)
    res = ""
    Spider::Template.scan_text(str) do |type, val, full|
        case type
        when :plain
            res += escape_text(val)
        when :escaped_expr
            res += "{ #{escape_text(val)} }"
        when :expr
            res += "'+("+vars_to_scene(val)+").to_s+'"
        when :gettext
            res += "'\n$out << _('#{escape_text(val[0])}')"
            if val[1]
                res += " #{vars_to_scene(val[1])}" 
            end
            res += "\n$out << '"
        end
    end
    res
end

#escape_text(text) ⇒ Object



114
115
116
117
118
# File 'lib/spiderfw/templates/template_blocks.rb', line 114

def escape_text(text)
    res = text.gsub(/_(\\*)\\\((.+?)\)/, '_\1(\2)') \
        .gsub('\\', '\\\\\\').gsub("'", "\\\\'")
    return res
end

#get_following(el) ⇒ Object



110
111
112
# File 'lib/spiderfw/templates/template_blocks.rb', line 110

def get_following(el)
    return false
end

#inspectObject



159
160
161
# File 'lib/spiderfw/templates/template_blocks.rb', line 159

def inspect
    @el
end

#parse_content(el) ⇒ Object



100
101
102
# File 'lib/spiderfw/templates/template_blocks.rb', line 100

def parse_content(el)
    TemplateBlocks.parse_content(el, @allowed_blocks, @template)
end

#var_to_scene(var, container = 'self') ⇒ Object



181
182
183
# File 'lib/spiderfw/templates/template_blocks.rb', line 181

def var_to_scene(var, container='self')
    self.class.var_to_scene(var, container)
end

#vars_to_scene(str, container = 'self') ⇒ Object



133
134
135
# File 'lib/spiderfw/templates/template_blocks.rb', line 133

def vars_to_scene(str, container='self')
    self.class.vars_to_scene(str, container)
end