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
radiant-0.9.0.rc2 app/models/page_context.rb
radiant-rc-0.9.0 app/models/page_context.rb
radiant-0.8.1 app/models/page_context.rb
radiant-0.6.5.1 app/models/page_context.rb
radiant-0.6.5 app/models/page_context.rb
radiant-0.6.7 app/models/page_context.rb
radiant-0.6.6 app/models/page_context.rb
radiant-0.6.8 app/models/page_context.rb
radiant-0.6.9 app/models/page_context.rb
radiant-0.7.0 app/models/page_context.rb
radiant-0.8.0 app/models/page_context.rb
radiant-0.7.1 app/models/page_context.rb