From bd9067272e1bd5a8651c5b9fa66881782406c54c Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 28 Feb 2009 13:34:23 +0100 Subject: added custom partials to aggregators, added test and refactored some methods --- app/helpers/content_helper.rb | 29 ++++++++++++++++++++-- app/views/content/_article.html.erb | 6 ++--- .../partials/_sidebar_title_only.html.erb | 3 +++ test/functional/content_controller_test.rb | 16 ++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 app/views/custom_templates/partials/_sidebar_title_only.html.erb diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 9800471..7747609 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -33,6 +33,8 @@ module ContentHelper options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") end + options[:partial] = select_partial( options[:partial] ) + content.sub(tag, render_collection(options)) else content @@ -47,8 +49,31 @@ module ContentHelper # from Page.aggregate(options) with a given partial def render_collection options render( - :partial => 'content/article', - :collection => Page.aggregate(options) + :partial => options[:partial], + :collection => Page.aggregate(options), + :as => :page + ) + end + + private + + # Either return a custom partial path if it exsits or default to the standard + # partial + def select_partial partial + if partial && partial_exists?( partial ) + return "custom_templates/partials/#{partial}" + else + return 'content/article' + end + end + + # Check if a custom partial exists in the proper location + def partial_exists? partial + File.exist?( + File.join( + RAILS_ROOT, 'app', 'views', 'custom_templates', 'partials', "_#{partial}.html.erb" + ) ) end + end diff --git a/app/views/content/_article.html.erb b/app/views/content/_article.html.erb index 009d639..e2f2877 100644 --- a/app/views/content/_article.html.erb +++ b/app/views/content/_article.html.erb @@ -1,6 +1,6 @@

-

<%= article.title %>

-

<%= date_for_page article %>, <%= @page.user.login %>

-

<%= article.abstract %>

\ No newline at end of file +

<%= page.title %>

+

<%= date_for_page page %>, <%= page.user.login %>

+

<%= page.abstract %>

\ No newline at end of file diff --git a/app/views/custom_templates/partials/_sidebar_title_only.html.erb b/app/views/custom_templates/partials/_sidebar_title_only.html.erb new file mode 100644 index 0000000..819d9ae --- /dev/null +++ b/app/views/custom_templates/partials/_sidebar_title_only.html.erb @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb index cb6ad04..c374a83 100644 --- a/test/functional/content_controller_test.rb +++ b/test/functional/content_controller_test.rb @@ -51,6 +51,22 @@ class ContentControllerTest < ActionController::TestCase assert_select("h2", "two") end + def test_page_containing_aggregator_with_custom_template + fill_pages_with_content + + new_node = create_node_under_root "fnord" + draft = new_node.find_or_create_draft @user1 + draft.body = '' + draft.save + new_node.publish_draft! + + get :render_page, :locale => 'de', :page_path => ["fnord"] + assert_response :success + + assert_select(".sidebar_headline", "one") + assert_select(".sidebar_headline", "two") + end + protected -- cgit v1.3