diff options
| author | hukl <hukl@eight.intern.artcom.de> | 2009-02-03 16:47:43 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.intern.artcom.de> | 2009-02-03 16:47:43 +0100 |
| commit | 1902c4bf975a5c1decd199a5190b04d08a2e4760 (patch) | |
| tree | 11a6983e98567f6894abb7c353e39ea30da458bb /app | |
| parent | 91b6089337e59d0c30a0112a5689f476d3c2f013 (diff) | |
added lots of comments to describe what the
methods are doing. this will get
everyone a better start. I hope
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/content_controller.rb | 7 | ||||
| -rw-r--r-- | app/helpers/content_helper.rb | 18 | ||||
| -rw-r--r-- | app/models/node.rb | 1 | ||||
| -rw-r--r-- | app/models/page.rb | 14 |
4 files changed, 32 insertions, 8 deletions
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 278c5ab..0fa9832 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | class ContentController < ApplicationController | 1 | class ContentController < ApplicationController |
| 2 | 2 | ||
| 3 | # This is the method that renders most of the the public content. It recieves | ||
| 4 | # a :locale and a :page_path parameter through the params hash. It looks up | ||
| 5 | # the node with the corresponding unique_name attribute. The method doesn't | ||
| 6 | # return a node though, the node is really a proxy object for pages. It | ||
| 7 | # returns the most recent page associated to this node instead. | ||
| 3 | def render_page | 8 | def render_page |
| 4 | path = params[:page_path].join('/') | 9 | path = params[:page_path].join('/') |
| 5 | 10 | ||
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 385bca0..9800471 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -1,9 +1,25 @@ | |||
| 1 | module ContentHelper | 1 | module ContentHelper |
| 2 | 2 | ||
| 3 | # Returns the published_at attribute of a page if it is not nil, otherwise | ||
| 4 | # it returns the auto-filled value of the created_at attribute | ||
| 3 | def date_for_page page | 5 | def date_for_page page |
| 4 | page.published_at.to_s(:db) rescue page.created_at.to_s(:db) | 6 | page.published_at.to_s(:db) rescue page.created_at.to_s(:db) |
| 5 | end | 7 | end |
| 6 | 8 | ||
| 9 | # This method is an output filter for templates. It accepts any kind of text | ||
| 10 | # and checks for an <aggregate /> tag within it. If such a tag is found, its | ||
| 11 | # attributes are parsed and converted into parameters for the | ||
| 12 | # render_collection method. The <aggregate /> tag will then be replaced | ||
| 13 | # entirely with the output of the render_collection method. | ||
| 14 | # | ||
| 15 | # Syntax of the <aggregate /> tag: | ||
| 16 | # | ||
| 17 | # <aggregate | ||
| 18 | # flags="update, pressemitteilung" | ||
| 19 | # limit="20" | ||
| 20 | # order_by="published_at" | ||
| 21 | # order_direction="DESC" | ||
| 22 | # /> | ||
| 7 | def aggregate? content | 23 | def aggregate? content |
| 8 | options = {} | 24 | options = {} |
| 9 | 25 | ||
| @@ -27,6 +43,8 @@ module ContentHelper | |||
| 27 | end | 43 | end |
| 28 | end | 44 | end |
| 29 | 45 | ||
| 46 | # Takes the parameters from the aggregate? method and renders the collection | ||
| 47 | # from Page.aggregate(options) with a given partial | ||
| 30 | def render_collection options | 48 | def render_collection options |
| 31 | render( | 49 | render( |
| 32 | :partial => 'content/article', | 50 | :partial => 'content/article', |
diff --git a/app/models/node.rb b/app/models/node.rb index 3564ce4..0aa28b9 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -40,5 +40,6 @@ class Node < ActiveRecord::Base | |||
| 40 | def update_unique_name | 40 | def update_unique_name |
| 41 | path = self.path_to_root[1..-1] | 41 | path = self.path_to_root[1..-1] |
| 42 | self.unique_name = path.join("/") | 42 | self.unique_name = path.join("/") |
| 43 | self.save | ||
| 43 | end | 44 | end |
| 44 | end | 45 | end |
diff --git a/app/models/page.rb b/app/models/page.rb index f6c5ef2..d33e11b 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -4,13 +4,13 @@ class Page < ActiveRecord::Base | |||
| 4 | 4 | ||
| 5 | acts_as_taggable | 5 | acts_as_taggable |
| 6 | acts_as_list :column => :revision, :scope => :node_id | 6 | acts_as_list :column => :revision, :scope => :node_id |
| 7 | 7 | ||
| 8 | # <aggregate | 8 | # This method is most likely called from the ContentHelper.render_collection |
| 9 | # flags="update, pressemitteilung" | 9 | # method which aggregates pages into a collection, based on parameters it |
| 10 | # limit="20" | 10 | # recieves. This method then calls Page.aggregate with these parameters. |
| 11 | # order_by="published_at" | 11 | # The Page.aggregate method comes with a defaults hash. These options are |
| 12 | # order_direction="DESC" | 12 | # partially or entirely overwritten by the options hash. Afterwards the merged |
| 13 | # /> | 13 | # parameters are used to query the DB for Pages matching these parameters. |
| 14 | def self.aggregate options | 14 | def self.aggregate options |
| 15 | 15 | ||
| 16 | defaults = { | 16 | defaults = { |
