Class: Gumdrop::RenderContext

Inherits:
Object
  • Object
show all
Includes:
Util::SiteAccess, Util::ViewHelpers
Defined in:
lib/gumdrop/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::ViewHelpers

#config, #data, #gumdrop_version, #hidden, #markdown, #textile

Methods included from Util::SiteAccess

#parent, #site

Methods included from Util::Loggable

#log

Methods included from Util::Eventable

#clear_events, #event_block, #fire

Constructor Details

#initialize(content, renderer, parent = nil) ⇒ RenderContext

Returns a new instance of RenderContext.



208
209
210
211
212
213
# File 'lib/gumdrop/renderer.rb', line 208

def initialize(content, renderer, parent=nil)
  @content= content
  @renderer= renderer
  @parent= parent
  @state= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



236
237
238
239
240
241
242
243
# File 'lib/gumdrop/renderer.rb', line 236

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

#contentObject (readonly)

Returns the value of attribute content.



206
207
208
# File 'lib/gumdrop/renderer.rb', line 206

def content
  @content
end

#stateObject (readonly)

Returns the value of attribute state.



206
207
208
# File 'lib/gumdrop/renderer.rb', line 206

def state
  @state
end

Instance Method Details

#get(key) ⇒ Object



222
223
224
# File 'lib/gumdrop/renderer.rb', line 222

def get(key)
  _get_from_state key.to_sym
end

#render(path = nil, opts = {}) ⇒ Object

Raises:

  • (StandardError)


215
216
217
218
219
220
# File 'lib/gumdrop/renderer.rb', line 215

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
  @renderer.draw content, opts
end

#set(key, value = nil) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'lib/gumdrop/renderer.rb', line 226

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