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 +++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 app/views/custom_templates/partials/_sidebar_title_only.html.erb (limited to 'app') 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 -- cgit v1.3