Sha256: ce0e3f1f5da883d75a7d6c34fd16961fd3b9668eef84768c7967c5040321cbe4

Contents?: true

Size: 1.05 KB

Versions: 32

Compression:

Stored size: 1.05 KB

Contents

class PageContext < Radius::Context
  
  attr_reader :page
  
  def initialize(page)
    super()
    @page = page
    globals.page = @page
    page.tags.each do |name|
      define_tag(name) { |tag_binding| page.render_tag(name, tag_binding) }
    end
  end
 
  def render_tag(name, attributes = {}, &block)
    binding = @tag_binding_stack.last
    locals = binding ? binding.locals : globals
    set_process_variables(locals.page)
    super
  rescue Exception => e
    raise e if raise_errors?
    @tag_binding_stack.pop unless @tag_binding_stack.last == binding
    render_error_message(e.message)
  end
  
  def tag_missing(name, attributes = {}, &block)
    super
  rescue Radius::UndefinedTagError => e
    raise StandardTags::TagError.new(e.message)
  end
  
  private
  
    def render_error_message(message)
      "<div><strong>#{message}</strong></div>"
    end
    
    def set_process_variables(page)
      page.request ||= @page.request
      page.response ||= @page.response
    end
    
    def raise_errors?
      RAILS_ENV != 'production'
    end
    
end

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
kajam-1.0.3.rc2 app/models/page_context.rb
radiant-1.0.0.rc2 app/models/page_context.rb
radiant-1.0.0.rc1 app/models/page_context.rb
radiantcms-couchrest_model-0.2.4 app/models/page_context.rb
radiantcms-couchrest_model-0.2.2 app/models/page_context.rb
radiantcms-couchrest_model-0.2.1 app/models/page_context.rb
radiantcms-couchrest_model-0.2 app/models/page_context.rb
radiantcms-couchrest_model-0.1.9 app/models/page_context.rb
radiantcms-couchrest_model-0.1.8 app/models/page_context.rb
radiantcms-couchrest_model-0.1.7 app/models/page_context.rb
radiantcms-couchrest_model-0.1.6 app/models/page_context.rb
radiantcms-couchrest_model-0.1.5 app/models/page_context.rb
radiantcms-couchrest_model-0.1.4 app/models/page_context.rb
radiantcms-couchrest_model-0.1.3 app/models/page_context.rb
radiantcms-couchrest_model-0.1.2 app/models/page_context.rb
radiantcms-couchrest_model-0.1.1 app/models/page_context.rb
radiantcms-couchrest_model-0.1 app/models/page_context.rb
radiant-0.7.2 app/models/page_context.rb
radiant-0.9.1 app/models/page_context.rb
radiant-0.8.2 app/models/page_context.rb