1 module Admin::RegionsHelper
2 def render_region(region, options={}, &block)
3 lazy_initialize_region_set
4 default_partials = Radiant::AdminUI::RegionPartials.new(self)
5 if block_given?
6 block.call(default_partials)
7 (options[:locals] ||= {}).merge!(:defaults => default_partials)
8 end
9 output = @region_set[region].compact.map do |partial|
10 begin
11 render options.merge(:partial => partial)
12 rescue ::ActionView::MissingTemplate # couldn't find template
13 default_partials[partial]
14 rescue ::ActionView::TemplateError => e # error in template
15 raise e
16 end
17 end.join
18 block_given? ? concat(output) : output
19 end
20
21 def lazy_initialize_region_set
22 unless @region_set
23 @controller_name ||= @controller.controller_name
24 @template_name ||= @controller.template_name
25 @region_set = admin.send(@controller_name).send(@template_name)
26 end
27 end
28 en