class Gumdrop::RenderContext

Attributes

content[R]
opts[R]
state[R]

Public Class Methods

new(content, opts, renderer, parent=nil) click to toggle source
# File lib/gumdrop/renderer.rb, line 262
def initialize(content, opts, renderer, parent=nil)
  # @content_page= nil
  @content= content
  @renderer= renderer
  @parent= parent
  @opts= opts
  @state= {}
end

Public Instance Methods

_setup(content, opts) click to toggle source
# File lib/gumdrop/renderer.rb, line 271
def _setup(content, opts)
  # @content_page= nil
  @content= content
  @opts= opts
  # @state= {}
  @state.clear()
end
capture(&block) click to toggle source
# 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) click to toggle source
# File lib/gumdrop/renderer.rb, line 312
def content_for(key, &block)
  keyname= "_content_#{key}"
  if block_given?
    content= capture &block
    @state[keyname]= content #block
    nil
  else
    if @state.has_key?(keyname)
      # @state[keyname].call
      @state[keyname]
    else
      nil
    end
  end
end
content_for?(key) click to toggle source
# File lib/gumdrop/renderer.rb, line 341
def content_for?(key)
  keyname= "_content_#{key}"
  @state.has_key?(keyname)
end
get(key) click to toggle source
# File lib/gumdrop/renderer.rb, line 294
def get(key)
  _get_from_state key.to_sym
end
method_missing(sym, *args, &block) click to toggle source
# 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
page() click to toggle source
# File lib/gumdrop/renderer.rb, line 308
def page
  @renderer.ctx_pool.root
end
render(path=nil, opts={}) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

_get_from_content(key) click to toggle source
# File lib/gumdrop/renderer.rb, line 373
def _get_from_content(key)
  return nil if @content.nil?
  return @content.send(key.to_sym) if @content.respond_to?(key.to_sym)
  return @content.params[key] if @content.params.has_key?(key)
  nil
end
_get_from_parent(key) click to toggle source
# File lib/gumdrop/renderer.rb, line 365
def _get_from_parent(key)
  if @parent.nil? or !@parent.has_key?(key)
    _get_from_content key 
  else
    @parent.get key
  end
end
_get_from_state(key) click to toggle source
# File lib/gumdrop/renderer.rb, line 357
def _get_from_state(key)
  if @state.has_key? key
    @state[key]
  else
    _get_from_parent key
  end
end