From 1de97a5ac6f4621f8013d6f73c6c9edfae445b70 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 15 Nov 2009 14:31:52 +0100 Subject: 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// Added tests and convenient method --- app/models/node.rb | 6 +++++- app/models/page.rb | 15 ++++++++++----- .../page_templates/public/standard_template.html.erb | 1 - app/views/custom/page_templates/public/update.html.erb | 9 +++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 app/views/custom/page_templates/public/update.html.erb (limited to 'app') 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 # returns an array with all parts of a unique_name rather than a string def unique_path - unique_name.split("/") rescue unique_name + unique_name.split("/") rescue [unique_name] end # returns array with pages up to root excluding root @@ -165,6 +165,10 @@ class Node < ActiveRecord::Base head_id end + def update? + unique_path.length == 3 && unique_path[0] == "updates" + end + # Returns immutable node id for all new nodes so that the atom feed entry ids # stay the same eventhough the slug or positions changes. # 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 # Filter before_create :set_page_title before_create :set_published_at + before_create :set_template before_save :rewrite_links_in_body # Validations @@ -128,9 +129,9 @@ class Page < ActiveRecord::Base self.reload # Clone untranslated attributes - self.tag_list = page.tag_list - self.template_name = page.template_name - self.published_at = page.published_at + self.tag_list = page.tag_list + self.template_name ||= page.template_name + self.published_at = page.published_at # Getting rid of the auto-generated empty translations self.globalize_translations.delete_all @@ -206,6 +207,12 @@ class Page < ActiveRecord::Base end end + def set_template + if node && node.update? + self.template_name = "update" + end + end + def rewrite_links_in_body begin if self.body @@ -220,8 +227,6 @@ class Page < ActiveRecord::Base aggregate_tags[0].parent.replace_with aggregate_tags[0] end - - links.each do |link| unless locales.include? link[:href].slice(1,2).to_sym 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 @@

<%= @page.title %>

-
<%= date_for_page @page %>, <%= @page.user.try(:login) %>

<%= sanitize( @page.abstract )%>

<%= headline_image %>
<%= aggregate?(@page.body) %>
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 @@ +
+

<%= @page.title %>

+
<%= date_for_page @page %>, <%= @page.user.try(:login) %>
+

<%= sanitize( @page.abstract )%>

+
<%= headline_image %>
+
<%= aggregate?(@page.body) %>
+
+ +<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file -- cgit v1.3