adjusting ViewHooks

Oleg committed Jan 28, 2011
commit caec7455dea68862221afdcbec12109a5d1e3231
Showing 3 changed files with 18 additions and 3 deletions
comfortable_mexican_sofa/view_hooks.rb b/lib/comfortable_mexican_sofa/view_hooks.rb +6 -3
@@ @@ -7,16 +7,19 @@ module ComfortableMexicanSofa::ViewHooks
# Renders hook content
def self.render(name, template, options = {})
- if self.hooks[name.to_sym]
- template.render({:partial => self.hooks[name.to_sym]}.merge(options))
+ out = ''
+ (self.hooks[name.to_sym] || []).each do |path|
+ out += template.render({:partial => path}.merge(options))
end
+ return out
end
# Will declare a partial that will be rendered for this hook
# Example:
# ComfortableMexicanSofa::ViewHooks.add(:navigation, 'shared/navigation')
def self.add(name, partial_path)
- self.hooks[name.to_sym] = partial_path
+ self.hooks[name.to_sym] ||= []
+ self.hooks[name.to_sym] << partial_path
end
# Removing previously declared hook
test/fixtures/views/_nav_hook_2.html.erb +1 -0
@@ @@ -0,0 +1 @@
+ hook_content_2
\ No newline at end of file
test/integration/view_hooks_test.rb +11 -0
@@ @@ -11,6 +11,17 @@ class ViewHooksTest < ActionDispatch::IntegrationTest
assert_match /hook_content/, response.body
end
+ def test_hooks_rendering_with_multiples
+ CmsAdmin::SitesController.append_view_path(File.expand_path('../fixtures/views', File.dirname(__FILE__)))
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, '/nav_hook')
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, '/nav_hook_2')
+
+ http_auth :get, cms_admin_sites_path
+ assert_response :success
+ assert_match /hook_content/, response.body
+ assert_match /hook_content_2/, response.body
+ end
+
def test_hooks_rendering_with_no_hook
ComfortableMexicanSofa::ViewHooks.remove(:navigation)