Permalink
Browse files

add `extend_region` helper for extension partials to more easily add …

…to regions

Example:

  - extend_region :thead do |thead|
    - include_stylesheet 'admin/extra_styles'
    - thead.custom_header do
      %th.custom Custom

As before, this requires that the partial (and "custom_header" section from
this example) is added to the corresponding parts of the admin UI in the
`#activate` method of the extension.
  • Loading branch information...
1 parent d1235bb commit c43bbcfdfc896059ef16f9d64d470951d07e92b0 @mislav committed Feb 25, 2010
Showing with 17 additions and 0 deletions.
  1. +17 −0 app/helpers/admin/regions_helper.rb
@@ -7,6 +7,9 @@ def render_region(region, options={}, &block)
block.call(default_partials)
options[:locals][:defaults] = default_partials
end
+ @current_region_name = options[:locals][:region_name]
+ @current_region_partials = default_partials
+
output = @region_set[region].compact.map do |partial|
begin
render options.merge(:partial => partial)
@@ -16,8 +19,22 @@ def render_region(region, options={}, &block)
raise e
end
end.join
+ @current_region_name = @current_region_partials = nil
block_given? ? concat(output) : output
end
+
+ # helper for extension partials to add to regions
+ #
+ # Example:
+ # - extend_region :thead do |thead|
+ # - include_stylesheet 'admin/extra_styles'
+ # - thead.custom_header do
+ # %th.custom Custom
+ def extend_region(region, &block)
+ if region.to_sym == @current_region_name
+ block.call(@current_region_partials)
+ end
+ end
def lazy_initialize_region_set
unless @region_set

0 comments on commit c43bbcf

Please sign in to comment.