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

Returns a new instance of Block.



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

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.



88
89
90
# File 'lib/spiderfw/templates/template_blocks.rb', line 88

def allowed_blocks
  @allowed_blocks
end

#doctypeObject

Returns the value of attribute doctype.



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

def doctype
  @doctype
end

#elObject (readonly)

Returns the value of attribute el.



88
89
90
# File 'lib/spiderfw/templates/template_blocks.rb', line 88

def el
  @el
end

#templateObject (readonly)

Returns the value of attribute template.



88
89
90
# File 'lib/spiderfw/templates/template_blocks.rb', line 88

def template
  @template
end

Class Method Details

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



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

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



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

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



102
103
104
105
106
# File 'lib/spiderfw/templates/template_blocks.rb', line 102

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



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

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 += "{ #{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



112
113
114
115
116
# File 'lib/spiderfw/templates/template_blocks.rb', line 112

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

#get_following(el) ⇒ Object



108
109
110
# File 'lib/spiderfw/templates/template_blocks.rb', line 108

def get_following(el)
    return false
end

#inspectObject



157
158
159
# File 'lib/spiderfw/templates/template_blocks.rb', line 157

def inspect
    @el
end

#parse_content(el) ⇒ Object



98
99
100
# File 'lib/spiderfw/templates/template_blocks.rb', line 98

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

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



179
180
181
# File 'lib/spiderfw/templates/template_blocks.rb', line 179

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

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



131
132
133
# File 'lib/spiderfw/templates/template_blocks.rb', line 131

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