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 ++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'app/models') 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}/") -- cgit v1.3