File: app/models/page_context.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: PageContext#1
inherits from
  Context ( Radius )
has properties
attribute: page [R] #3
method: initialize / 1 #5
method: dup #14
method: render_tag / 3 #21
method: tag_missing / 3 #32
method: render_error_message / 1 #40
method: set_process_variables / 1 #44
method: raise_errors? #49

Class Hierarchy

Object ( Builtin-Module )
Context ( Radius )
  PageContext    #1

Code

   1  class PageContext < Radius::Context
   2    
   3    attr_reader :page
   4    
   5    def initialize(page)
   6      super
   7      @page = page
   8      globals.page = @page
   9      page.tags.each do |name|
  10        define_tag(name) { |tag_binding| page.render_tag(name, tag_binding) }
  11      end
  12    end
  13    
  14    def dup
  15      rv = self.class.new(page)
  16      rv.globals = globals.dup
  17      rv.definitions = definitions.dup
  18      rv
  19    end
  20   
  21    def render_tag(name, attributes = {}, &block)
  22      binding = @tag_binding_stack.last
  23      locals = binding ? binding.locals : globals
  24      set_process_variables(locals.page)
  25      super
  26    rescue Exception => e
  27      raise e if raise_errors?
  28      @tag_binding_stack.pop unless @tag_binding_stack.last == binding
  29      render_error_message(e.message)
  30    end
  31    
  32    def tag_missing(name, attributes = {}, &block)
  33      super
  34    rescue Radius::UndefinedTagError => e
  35      raise StandardTags::TagError.new(e.message)
  36    end
  37    
  38    private
  39    
  40      def render_error_message(message)
  41        "<div><strong>#{message}</strong></div>"
  42      end
  43      
  44      def set_process_variables(page)
  45        page.request ||= @page.request
  46        page.response ||= @page.response
  47      end
  48      
  49      def raise_errors?
  50        RAILS_ENV != 'production'
  51      end
  52      
  53  end