summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-01 21:32:44 +0100
committerhukl <hukl@eight.local>2009-02-01 21:32:44 +0100
commitc1854b8b518bde82b80429636f73496a537c3ad5 (patch)
tree59492d905ba5edf4cb7f344ca68a98d8861ff3e0
parenta660a7ee62e44314c12440d376166ccb0cf60d80 (diff)
added first careful steps for aggregation
-rw-r--r--app/helpers/content_helper.rb23
-rw-r--r--app/models/page.rb35
-rw-r--r--app/views/content/_article.html.erb6
-rw-r--r--app/views/content/render_page.html.erb2
4 files changed, 64 insertions, 2 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 0e1df66..046a2db 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -1,8 +1,29 @@
1module ContentHelper 1module ContentHelper
2 2
3 #
4 def date_for_page page 3 def date_for_page page
5 page.published_at.to_s(:db) rescue page.created_at.to_s(:db) 4 page.published_at.to_s(:db) rescue page.created_at.to_s(:db)
6 end 5 end
7 6
7 def aggregate? content
8 options = {}
9
10 if content =~ /<aggregate([^<>]*)>/
11 tag = $~.to_s
12 matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/)
13
14 matched_data.each do |data|
15 splitted_data = data.split("=")
16 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "")
17 end
18 end
19
20 content.sub(tag, render_collection(options))
21 end
22
23 def render_collection options
24 render(
25 :partial => 'content/article',
26 :collection => Page.aggregate(options)
27 )
28 end
8end 29end
diff --git a/app/models/page.rb b/app/models/page.rb
index 0fcb4a8..3d02e9f 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -4,4 +4,39 @@ class Page < ActiveRecord::Base
4 4
5 acts_as_list :column => :revision, :scope => :node_id 5 acts_as_list :column => :revision, :scope => :node_id
6 6
7
8 # <aggregate
9 # flags="updates pressemitteilungen"
10 # path="updates/2009"
11 # limit="20"
12 # order_by="published_at"
13 # order_direction="DESC"
14 # />
15 def self.aggregate options
16
17 defaults = {
18 :flags => "",
19 :path => "",
20 :limit => 20,
21 :order_by => "id",
22 :order_direction => "ASC"
23 }
24
25 options = defaults.merge options
26
27 pages = Page.all(
28 :limit => options[:limit],
29 :order => "#{options[:order_by]} #{options[:order_direction]}"
30 )
31 end
7end 32end
33
34
35named_scope :flagged_as, lambda { |flags|
36 conditions = {}
37 flags.each do |flag|
38 conditions[flag] = true
39 end
40
41 { :conditions => conditions }
42} \ No newline at end of file
diff --git a/app/views/content/_article.html.erb b/app/views/content/_article.html.erb
new file mode 100644
index 0000000..1e06787
--- /dev/null
+++ b/app/views/content/_article.html.erb
@@ -0,0 +1,6 @@
1<div class="teaserruler">
2 <hr/>
3</div>
4<h2><%= article.title %></h2>
5<h3><%= date_for_page article %>, gregoa</h3>
6<p><%= article.abstract %></p> \ No newline at end of file
diff --git a/app/views/content/render_page.html.erb b/app/views/content/render_page.html.erb
index 311d61d..b70f90e 100644
--- a/app/views/content/render_page.html.erb
+++ b/app/views/content/render_page.html.erb
@@ -13,5 +13,5 @@
13 <h3><%= date_for_page @page %>, gregoa</h3> 13 <h3><%= date_for_page @page %>, gregoa</h3>
14 <hr class="subtitle" /> 14 <hr class="subtitle" />
15 <p><em><%= @page.abstract %></em></p> 15 <p><em><%= @page.abstract %></em></p>
16 <%= @page.body %> 16 <%= aggregate?(@page.body) %>
17</div> \ No newline at end of file 17</div> \ No newline at end of file