Class: Gumdrop::RenderContext
Instance Attribute Summary collapse
Instance Method Summary
collapse
#cache_bust, #checksum_for, #config, #data, #gumdrop_version, #hidden, #markdown, #textile, #uri_fresh, #urlencode
#parent, #site
#log
#clear_events, #event_block, #fire
Constructor Details
#initialize(content, opts, renderer, parent = nil) ⇒ RenderContext
Returns a new instance of RenderContext.
262
263
264
265
266
267
268
269
|
# File 'lib/gumdrop/renderer.rb', line 262
def initialize(content, opts, renderer, parent=nil)
@content= content
@renderer= renderer
@parent= parent
@opts= opts
@state= {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
346
347
348
349
350
351
352
353
|
# File 'lib/gumdrop/renderer.rb', line 346
def method_missing(sym, *args, &block)
if sym.to_s.ends_with? '='
key= sym.to_s.chop
set key, args[0]
else
get(sym)
end
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
260
261
262
|
# File 'lib/gumdrop/renderer.rb', line 260
def content
@content
end
|
#opts ⇒ Object
Returns the value of attribute opts.
260
261
262
|
# File 'lib/gumdrop/renderer.rb', line 260
def opts
@opts
end
|
#state ⇒ Object
Returns the value of attribute state.
260
261
262
|
# File 'lib/gumdrop/renderer.rb', line 260
def state
@state
end
|
Instance Method Details
#_setup(content, opts) ⇒ Object
271
272
273
274
275
276
277
|
# File 'lib/gumdrop/renderer.rb', line 271
def _setup(content, opts)
@content= content
@opts= opts
@state.clear()
end
|
#capture(&block) ⇒ Object
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/gumdrop/renderer.rb', line 328
def capture(&block)
erbout = eval('_erbout', block.binding) rescue nil
unless erbout.nil?
erbout_length = erbout.length
block.call
content = erbout[erbout_length..-1]
erbout[erbout_length..-1] = ''
else
content= block.call
end
content
end
|
#content_for(key, &block) ⇒ Object
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
# File 'lib/gumdrop/renderer.rb', line 312
def content_for(key, &block)
keyname= "_content_#{key}"
if block_given?
content= capture &block
@state[keyname]= content nil
else
if @state.has_key?(keyname)
@state[keyname]
else
nil
end
end
end
|
#content_for?(key) ⇒ Boolean
341
342
343
344
|
# File 'lib/gumdrop/renderer.rb', line 341
def content_for?(key)
keyname= "_content_#{key}"
@state.has_key?(keyname)
end
|
#get(key) ⇒ Object
294
295
296
|
# File 'lib/gumdrop/renderer.rb', line 294
def get(key)
_get_from_state key.to_sym
end
|
#page ⇒ Object
308
309
310
|
# File 'lib/gumdrop/renderer.rb', line 308
def page
@renderer.ctx_pool.root
end
|
#render(path = nil, opts = {}) ⇒ Object
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/gumdrop/renderer.rb', line 279
def render(path=nil, opts={})
content= site.resolve path, opts
raise StandardError, "Content or Partial cannot be found at: #{path} (#{opts})" if content.nil?
opts[:force_partial]= true
opts[:calling_page]= self
return @renderer.draw content, opts if opts[:cache] == false
if @renderer.cache.has_key? content.source_path
@renderer.cache[content.source_path]
else
output= @renderer.draw content, opts
@renderer.cache[content.source_path]= output if opts[:cache]
output
end
end
|
#set(key, value = nil) ⇒ Object
298
299
300
301
302
303
304
305
306
|
# File 'lib/gumdrop/renderer.rb', line 298
def set(key, value=nil)
if key.is_a? Hash
key.each do |k,v|
@state[k.to_s.to_sym]= v
end
else
@state[key.to_s.to_sym]= value
end
end
|