summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/helpers/content_helper.rb28
-rw-r--r--app/models/flag.rb3
-rw-r--r--app/models/page.rb51
-rw-r--r--app/views/content/_article.html.erb6
-rw-r--r--app/views/content/render_page.html.erb2
5 files changed, 87 insertions, 3 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 0e1df66..3cf3488 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -1,8 +1,34 @@
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 begin
11 if content =~ /<aggregate([^<>]*)>/
12 tag = $~.to_s
13 matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/)
14
15 matched_data.each do |data|
16 splitted_data = data.split("=")
17 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "")
18 end
19
20 content.sub(tag, render_collection(options))
21 end
22
23 rescue
24 content
25 end
26 end
27
28 def render_collection options
29 render(
30 :partial => 'content/article',
31 :collection => Page.aggregate(options)
32 )
33 end
8end 34end
diff --git a/app/models/flag.rb b/app/models/flag.rb
new file mode 100644
index 0000000..6d67377
--- /dev/null
+++ b/app/models/flag.rb
@@ -0,0 +1,3 @@
1class Flag < ActiveRecord::Base
2 has_and_belongs_to_many :pages
3end
diff --git a/app/models/page.rb b/app/models/page.rb
index 0fcb4a8..fee20a8 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,7 +1,56 @@
1class Page < ActiveRecord::Base 1class Page < ActiveRecord::Base
2 2
3 belongs_to :node 3 belongs_to :node
4 has_and_belongs_to_many :flags
4 5
5 acts_as_list :column => :revision, :scope => :node_id 6 acts_as_list :column => :revision, :scope => :node_id
6 7
7end 8 # Alternativ Queries with one or two inner joins. Loading the Flags themselves
9 # would be another query. Could be faster on larger data sets.
10 #
11 # Single Join:
12 #
13 # Page.find(
14 # :all,
15 # :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id',
16 # :include => :flags,
17 # :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
18 # )
19 # Two inner joins:
20 #
21 # Page.find(
22 # :all,
23 # :joins => :flags_pages,
24 # :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
25 # )
26 named_scope :with_flags, lambda {|flag_names|
27 if (flags = Flag.find_all_by_name(flag_names)).empty?
28 {}
29 else
30 {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] }
31 end
32 }
33
34 # <aggregate
35 # flags="updates pressemitteilungen"
36 # limit="20"
37 # order_by="published_at"
38 # order_direction="DESC"
39 # />
40 def self.aggregate options
41
42 defaults = {
43 :flags => "",
44 :limit => 20,
45 :order_by => "id",
46 :order_direction => "ASC"
47 }
48
49 options = defaults.merge options
50
51 pages = Page.with_flags(options[:flags].split(/\s/)).all(
52 :limit => options[:limit],
53 :order => "#{options[:order_by]} #{options[:order_direction]}"
54 )
55 end
56end \ 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