diff options
| author | hukl <contact@smyck.org> | 2009-11-15 14:31:52 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-11-15 14:31:52 +0100 |
| commit | 1de97a5ac6f4621f8013d6f73c6c9edfae445b70 (patch) | |
| tree | ee500916af41898ff2ecaf5c8567acf7cfd0f867 /app | |
| parent | 713f8f76e2ae1635bb938de6d8c74587d842790f (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
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/node.rb | 6 | ||||
| -rw-r--r-- | app/models/page.rb | 15 | ||||
| -rw-r--r-- | app/views/custom/page_templates/public/standard_template.html.erb | 1 | ||||
| -rw-r--r-- | app/views/custom/page_templates/public/update.html.erb | 9 |
4 files changed, 24 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 | ||
