summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-02-28 13:34:23 +0100
committerhukl <contact@smyck.org>2009-02-28 13:34:23 +0100
commitbd9067272e1bd5a8651c5b9fa66881782406c54c (patch)
treecb9bb1961ab4b376636eb6b3e76312991b125c89
parentcc74db30d930b0eaaf0ac29b19ddd452ea0c1462 (diff)
added custom partials to aggregators, added test and refactored some methods
-rw-r--r--app/helpers/content_helper.rb29
-rw-r--r--app/views/content/_article.html.erb6
-rw-r--r--app/views/custom_templates/partials/_sidebar_title_only.html.erb3
-rw-r--r--test/functional/content_controller_test.rb16
4 files changed, 49 insertions, 5 deletions
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
33 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") 33 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "")
34 end 34 end
35 35
36 options[:partial] = select_partial( options[:partial] )
37
36 content.sub(tag, render_collection(options)) 38 content.sub(tag, render_collection(options))
37 else 39 else
38 content 40 content
@@ -47,8 +49,31 @@ module ContentHelper
47 # from Page.aggregate(options) with a given partial 49 # from Page.aggregate(options) with a given partial
48 def render_collection options 50 def render_collection options
49 render( 51 render(
50 :partial => 'content/article', 52 :partial => options[:partial],
51 :collection => Page.aggregate(options) 53 :collection => Page.aggregate(options),
54 :as => :page
55 )
56 end
57
58 private
59
60 # Either return a custom partial path if it exsits or default to the standard
61 # partial
62 def select_partial partial
63 if partial && partial_exists?( partial )
64 return "custom_templates/partials/#{partial}"
65 else
66 return 'content/article'
67 end
68 end
69
70 # Check if a custom partial exists in the proper location
71 def partial_exists? partial
72 File.exist?(
73 File.join(
74 RAILS_ROOT, 'app', 'views', 'custom_templates', 'partials', "_#{partial}.html.erb"
75 )
52 ) 76 )
53 end 77 end
78
54end 79end
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 @@
1<div class="teaserruler"> 1<div class="teaserruler">
2 <hr/> 2 <hr/>
3</div> 3</div>
4<h2><%= article.title %></h2> 4<h2><%= page.title %></h2>
5<h3><%= date_for_page article %>, <%= @page.user.login %></h3> 5<h3><%= date_for_page page %>, <%= page.user.login %></h3>
6<p><%= article.abstract %></p> \ No newline at end of file 6<p><%= page.abstract %></p> \ 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 @@
1<h2 class="sidebar_headline">
2 <%= page.title %>
3</h2> \ 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
51 assert_select("h2", "two") 51 assert_select("h2", "two")
52 end 52 end
53 53
54 def test_page_containing_aggregator_with_custom_template
55 fill_pages_with_content
56
57 new_node = create_node_under_root "fnord"
58 draft = new_node.find_or_create_draft @user1
59 draft.body = '<aggregate tags="update" limit="20" partial="sidebar_title_only" />'
60 draft.save
61 new_node.publish_draft!
62
63 get :render_page, :locale => 'de', :page_path => ["fnord"]
64 assert_response :success
65
66 assert_select(".sidebar_headline", "one")
67 assert_select(".sidebar_headline", "two")
68 end
69
54 70
55 71
56 protected 72 protected