Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose region_name to partials which hook into multiple regions
An extension can hook its view partial to multiple points in the admin UI:

  ## in MyExtension#activate
  admin.user.index[:thead].unshift 'users/index_extras'
  admin.user.index.add :thead, 'created_at_header', :after => 'roles_header'
  admin.user.index[:tbody].unshift 'users/index_extras'
  admin.user.index.add :tbody, 'created_at_cell', :after => 'roles_cell'

Knowing the region name, the partial can adjust its output depending on
the context. Here the extension changes user names to be displayed in
uppercase caps and adds another column to the users overview table. It
also pushes a custom stylesheet onto the stylesheets stack.

  ## in views/users/_index_extras.html.haml
  - if :thead == region_name
    - include_stylesheet 'admin/my_extension_extras'
    - defaults.created_at_header do
      %th.created_at Created at

  - elsif :tbody == region_name
    - defaults.title_cell do
      %td.user
        = link_to user.name.upcase, edit_admin_user_url(user)

    - defaults.created_at_cell do
      %td.created_at
        %time{ :datetime => user.created_at.xmlschema }
          &== #{time_ago_in_words(user.created_at)} ago
  • Loading branch information
mislav committed Feb 25, 2010
1 parent 7f87e60 commit d1235bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,7 @@

=== Edge

* Expose `region_name` to partials which hook into multiple regions [Mislav Marohnić]
* Exposed important view locals for partials that hook into the admin UI [Mislav Marohnić]
* Refactored Sass to separate out common styles [Jim Gay]
* Upgraded to HAML 2.2.19 [Jim Gay]
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/admin/regions_helper.rb
@@ -1,10 +1,11 @@
module Admin::RegionsHelper
def render_region(region, options={}, &block)
lazy_initialize_region_set
(options[:locals] ||= {}).update(:region_name => region.to_sym)
default_partials = Radiant::AdminUI::RegionPartials.new(self)
if block_given?
block.call(default_partials)
(options[:locals] ||= {}).merge!(:defaults => default_partials)
options[:locals][:defaults] = default_partials
end
output = @region_set[region].compact.map do |partial|
begin
Expand Down

0 comments on commit d1235bb

Please sign in to comment.