Class: Spider::TemplateBlocks::Block
- Inherits:
-
Object
- Object
- Spider::TemplateBlocks::Block
- Defined in:
- lib/spiderfw/templates/template_blocks.rb
Instance Attribute Summary (collapse)
-
- (Object) allowed_blocks
readonly
Returns the value of attribute allowed_blocks.
-
- (Object) doctype
Returns the value of attribute doctype.
-
- (Object) el
readonly
Returns the value of attribute el.
-
- (Object) template
readonly
Returns the value of attribute template.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) compile_content(c = '', init = '', options = {})
- - (Object) compile_text(str)
- - (Object) escape_text(text)
- - (Object) get_following(el)
-
- (Block) initialize(el, template = nil, allowed_blocks = nil)
constructor
A new instance of Block.
- - (Object) inspect
- - (Object) parse_content(el)
- - (Object) var_to_scene(var, container = 'self')
- - (Object) vars_to_scene(str, container = 'self')
Constructor Details
- (Block) initialize(el, template = nil, allowed_blocks = nil)
A new instance of 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
- (Object) allowed_blocks (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 |
- (Object) doctype
Returns the value of attribute doctype
91 92 93 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 91 def doctype @doctype end |
- (Object) el (readonly)
Returns the value of attribute el
90 91 92 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 90 def el @el end |
- (Object) template (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
+ (Object) var_to_scene(var, container = 'self')
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 |
+ (Object) vars_to_scene(str, container = 'self')
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
- (Object) compile_content(c = '', init = '', options = {})
104 105 106 107 108 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 104 def compile_content(c='', init='', ={}) [:allowed_blocks] ||= @allowed_blocks [:template] ||= @template TemplateBlocks.compile_content(@el, c, init, ) end |
- (Object) compile_text(str)
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 |
- (Object) escape_text(text)
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 |
- (Object) get_following(el)
110 111 112 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 110 def get_following(el) return false end |
- (Object) inspect
159 160 161 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 159 def inspect @el end |
- (Object) parse_content(el)
100 101 102 |
# File 'lib/spiderfw/templates/template_blocks.rb', line 100 def parse_content(el) TemplateBlocks.parse_content(el, @allowed_blocks, @template) end |
- (Object) var_to_scene(var, container = 'self')
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 |
- (Object) vars_to_scene(str, container = 'self')
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 |