root/trunk/radiant/app/models/page_context.rb

Revision 757, 1.0 kB (checked in by seancribbs, 4 months ago)

#610 Bubble up parsing exceptions in development mode. [jonleighton]

Line 
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 render_tag(name, attributes = {}, &block)
15     binding = @tag_binding_stack.last
16     locals = binding ? binding.locals : globals
17     set_process_variables(locals.page)
18     super
19   rescue Exception => e
20     raise e if raise_errors?
21     @tag_binding_stack.pop unless @tag_binding_stack.last == binding
22     render_error_message(e.message)
23   end
24  
25   def tag_missing(name, attributes = {}, &block)
26     super
27   rescue Radius::UndefinedTagError => e
28     raise StandardTags::TagError.new(e.message)
29   end
30  
31   private
32  
33     def render_error_message(message)
34       "<div><strong>#{message}</strong></div>"
35     end
36    
37     def set_process_variables(page)
38       page.request ||= @page.request
39       page.response ||= @page.response
40     end
41    
42     def raise_errors?
43       RAILS_ENV != 'production'
44     end
45    
46 end
Note: See TracBrowser for help on using the browser.