Sha256: a98bc2769ffcc3296450d552e99a46b986162a7fdd0a37c4a578eacd1d21aa79

Contents?: true

Size: 1.38 KB

Versions: 18

Compression:

Stored size: 1.38 KB

Contents

# Extends the view to support rendering inline comatose pages...
ActionView::Base.class_eval do
  alias_method :render_otherwise, :render
  
  def render(options = {}, old_local_assigns = {}, &block) #:nodoc:
    if options.is_a?(Hash) && page_name = options.delete(:comatose)
      render_comatose(page_name, options[:params] || options)
    else
      render_otherwise(options, old_local_assigns, &block)
    end
  end
  
  def render_comatose(page_path, params = {})
    params = {
      :silent => false,
      :use_cache => true,
      :locals => {}
    }.merge(params)
    if params[:use_cache] and params[:locals].empty?
      render_cached_comatose_page(page_path, params)
    else
      render_comatose_page(page_path, params)
    end
  end
  
protected
  
  def render_cached_comatose_page(page_path, params)
    key = page_path.gsub(/\//, '+')
    unless html = controller.read_fragment(key)
      html = render_comatose_page( page_path, params )
      controller.write_fragment(key, html) unless Comatose.config.disable_caching
    end
    html
  end
  
  def render_comatose_page(page_path, params)
    if page = ComatosePage.find_by_path(page_path)
      # Add the request params to the context...
      params[:locals]['params'] = controller.params
      html = page.to_html( params[:locals] )
    else
      html = params[:silent] ? '' : "<p><tt>#{page_path}</tt> not found</p>"
    end
  end
  
end

Version data entries

18 entries across 18 versions & 6 rubygems

Version Path
aslakjo-aslakjo-comatose-2.0.5.1 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.2 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.3 lib/support/inline_rendering.rb
darthapo-comatose-2.0.3 lib/support/inline_rendering.rb
darthapo-comatose-2.0.4 lib/support/inline_rendering.rb
darthapo-comatose-2.0.5 lib/support/inline_rendering.rb
darthapo-comatose-2.0 lib/support/inline_rendering.rb
jcnetdev-comatose-2.0.1 lib/support/inline_rendering.rb
staugaard-comatose-2.0.2 lib/support/inline_rendering.rb
staugaard-comatose-2.0.3 lib/support/inline_rendering.rb
comatose-2.0.5 lib/support/inline_rendering.rb
comatose-2.0.1 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.12 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.11 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.10 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.9 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.8 lib/support/inline_rendering.rb
aslakjo-comatose-2.0.5.7 lib/support/inline_rendering.rb