summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-11-15 14:31:52 +0100
committerhukl <contact@smyck.org>2009-11-15 14:31:52 +0100
commit1de97a5ac6f4621f8013d6f73c6c9edfae445b70 (patch)
treeee500916af41898ff2ecaf5c8567acf7cfd0f867
parent713f8f76e2ae1635bb938de6d8c74587d842790f (diff)
removed date and author from the standard template and introduced a dedicated update template which will get auto assigned if a node is created under updates/<year>/<slug>
Added tests and convenient method
-rw-r--r--app/models/node.rb6
-rw-r--r--app/models/page.rb15
-rw-r--r--app/views/custom/page_templates/public/standard_template.html.erb1
-rw-r--r--app/views/custom/page_templates/public/update.html.erb9
-rw-r--r--test/unit/node_test.rb13
-rw-r--r--test/unit/page_test.rb9
6 files changed, 46 insertions, 7 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 7e64fdd..e9d935a 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -123,7 +123,7 @@ class Node < ActiveRecord::Base
123 123
124 # returns an array with all parts of a unique_name rather than a string 124 # returns an array with all parts of a unique_name rather than a string
125 def unique_path 125 def unique_path
126 unique_name.split("/") rescue unique_name 126 unique_name.split("/") rescue [unique_name]
127 end 127 end
128 128
129 # returns array with pages up to root excluding root 129 # returns array with pages up to root excluding root
@@ -165,6 +165,10 @@ class Node < ActiveRecord::Base
165 head_id 165 head_id
166 end 166 end
167 167
168 def update?
169 unique_path.length == 3 && unique_path[0] == "updates"
170 end
171
168 # Returns immutable node id for all new nodes so that the atom feed entry ids 172 # Returns immutable node id for all new nodes so that the atom feed entry ids
169 # stay the same eventhough the slug or positions changes. 173 # stay the same eventhough the slug or positions changes.
170 # Can be removed after a year or so ;) 174 # Can be removed after a year or so ;)
diff --git a/app/models/page.rb b/app/models/page.rb
index b17c32b..22d2c69 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -37,6 +37,7 @@ class Page < ActiveRecord::Base
37 # Filter 37 # Filter
38 before_create :set_page_title 38 before_create :set_page_title
39 before_create :set_published_at 39 before_create :set_published_at
40 before_create :set_template
40 before_save :rewrite_links_in_body 41 before_save :rewrite_links_in_body
41 42
42 # Validations 43 # Validations
@@ -128,9 +129,9 @@ class Page < ActiveRecord::Base
128 self.reload 129 self.reload
129 130
130 # Clone untranslated attributes 131 # Clone untranslated attributes
131 self.tag_list = page.tag_list 132 self.tag_list = page.tag_list
132 self.template_name = page.template_name 133 self.template_name ||= page.template_name
133 self.published_at = page.published_at 134 self.published_at = page.published_at
134 135
135 # Getting rid of the auto-generated empty translations 136 # Getting rid of the auto-generated empty translations
136 self.globalize_translations.delete_all 137 self.globalize_translations.delete_all
@@ -206,6 +207,12 @@ class Page < ActiveRecord::Base
206 end 207 end
207 end 208 end
208 209
210 def set_template
211 if node && node.update?
212 self.template_name = "update"
213 end
214 end
215
209 def rewrite_links_in_body 216 def rewrite_links_in_body
210 begin 217 begin
211 if self.body 218 if self.body
@@ -220,8 +227,6 @@ class Page < ActiveRecord::Base
220 aggregate_tags[0].parent.replace_with aggregate_tags[0] 227 aggregate_tags[0].parent.replace_with aggregate_tags[0]
221 end 228 end
222 229
223
224
225 links.each do |link| 230 links.each do |link|
226 unless locales.include? link[:href].slice(1,2).to_sym 231 unless locales.include? link[:href].slice(1,2).to_sym
227 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") 232 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/")
diff --git a/app/views/custom/page_templates/public/standard_template.html.erb b/app/views/custom/page_templates/public/standard_template.html.erb
index 5ea277a..8000af5 100644
--- a/app/views/custom/page_templates/public/standard_template.html.erb
+++ b/app/views/custom/page_templates/public/standard_template.html.erb
@@ -1,6 +1,5 @@
1<div class="article"> 1<div class="article">
2 <h2 class="headline"><%= @page.title %></h2> 2 <h2 class="headline"><%= @page.title %></h2>
3 <div class="author_and_date"><%= date_for_page @page %>, <%= @page.user.try(:login) %></div>
4 <div class="abstract"><p><%= sanitize( @page.abstract )%></p></div> 3 <div class="abstract"><p><%= sanitize( @page.abstract )%></p></div>
5 <div id="headline_image"><%= headline_image %></div> 4 <div id="headline_image"><%= headline_image %></div>
6 <div class="body"><%= aggregate?(@page.body) %></div> 5 <div class="body"><%= aggregate?(@page.body) %></div>
diff --git a/app/views/custom/page_templates/public/update.html.erb b/app/views/custom/page_templates/public/update.html.erb
new file mode 100644
index 0000000..5ea277a
--- /dev/null
+++ b/app/views/custom/page_templates/public/update.html.erb
@@ -0,0 +1,9 @@
1<div class="article">
2 <h2 class="headline"><%= @page.title %></h2>
3 <div class="author_and_date"><%= date_for_page @page %>, <%= @page.user.try(:login) %></div>
4 <div class="abstract"><p><%= sanitize( @page.abstract )%></p></div>
5 <div id="headline_image"><%= headline_image %></div>
6 <div class="body"><%= aggregate?(@page.body) %></div>
7</div>
8
9<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb
index dd010cd..a106856 100644
--- a/test/unit/node_test.rb
+++ b/test/unit/node_test.rb
@@ -263,6 +263,19 @@ class NodeTest < ActiveSupport::TestCase
263 assert_equal "quentin", node.head.user.login 263 assert_equal "quentin", node.head.user.login
264 end 264 end
265 265
266
267 test "update?" do
268 Node.root.descendants.delete_all
269 updates = Node.root.children.create!( :slug => "updates" )
270 assert !updates.update?
271
272 updates2009 = updates.children.create!( :slug => "2009" )
273 assert !updates2009.update?
274
275 update = updates2009.children.create!( :slug => "my-first-update" )
276 assert update.update?
277 end
278
266 def create_revisions node, count 279 def create_revisions node, count
267 count.times do 280 count.times do
268 node.find_or_create_draft @user1 281 node.find_or_create_draft @user1
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb
index c2599e3..bb82da0 100644
--- a/test/unit/page_test.rb
+++ b/test/unit/page_test.rb
@@ -134,4 +134,13 @@ class PageTest < ActiveSupport::TestCase
134 assert_equal 1, Page.find_with_outdated_translations(:delta_time => 23.minutes).count 134 assert_equal 1, Page.find_with_outdated_translations(:delta_time => 23.minutes).count
135 assert_equal 2, Page.count 135 assert_equal 2, Page.count
136 end 136 end
137
138 test "pages under /updates node get the update template assigned" do
139 Node.root.descendants.delete_all
140 updates = Node.root.children.create!( :slug => "updates" )
141 updates2009 = updates.children.create!( :slug => "2009" )
142 update = updates2009.children.create!( :slug => "my-first-update" )
143 assert_equal "update", update.draft.template_name
144 end
145
137end 146end