summaryrefslogtreecommitdiff
path: root/app/helpers/content_helper.rb
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2011-02-11 12:40:42 +0100
committerhukl <contact@smyck.org>2011-02-11 12:40:42 +0100
commit8640f3567283eb3ecc65008a52b8ae4fdbeadf36 (patch)
treeb517c1945d343682771cfaeab825564bb2ccbdb6 /app/helpers/content_helper.rb
parent384b187e9e067ddf2bb4d5fad0c2deaf96f69c89 (diff)
reject events with no corresponding page
spaces
Diffstat (limited to 'app/helpers/content_helper.rb')
-rw-r--r--app/helpers/content_helper.rb58
1 files changed, 30 insertions, 28 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 1e56488..d6c96f1 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -1,53 +1,55 @@
1module ContentHelper 1module ContentHelper
2 2
3 def main_menu 3 def main_menu
4 menu_items = MenuItem.all(:order => "position ASC") 4 menu_items = MenuItem.all(:order => "position ASC")
5 render( 5 render(
6 :partial => 'content/main_navigation', 6 :partial => 'content/main_navigation',
7 :locals => {:menu_items => menu_items} 7 :locals => {:menu_items => menu_items}
8 ) 8 )
9 end 9 end
10 10
11 def calendar 11 def calendar
12 occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) 12 occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days))
13 13
14 if occurrences.empty? 14 if occurrences.empty?
15 occurrences = Occurrence.find_next 15 occurrences = Occurrence.find_next
16 end 16 end
17 17
18 occurrences = occurrences.reject { |o| o.node.head.nil? }
19
18 render( 20 render(
19 :partial => 'content/front_page_calendar', 21 :partial => 'content/front_page_calendar',
20 :locals => {:occurrences => occurrences} 22 :locals => {:occurrences => occurrences}
21 ) 23 )
22 end 24 end
23 25
24 def tags 26 def tags
25 render :partial => 'content/tags' 27 render :partial => 'content/tags'
26 end 28 end
27 29
28 def featured_articles 30 def featured_articles
29 @featured_articles = FeaturedArticle.all 31 @featured_articles = FeaturedArticle.all
30 render :partial => 'content/featured_articles' 32 render :partial => 'content/featured_articles'
31 end 33 end
32 34
33 def headline_image 35 def headline_image
34 @images = @page.assets.images 36 @images = @page.assets.images
35 37
36 unless @images.empty? 38 unless @images.empty?
37 render :partial => 'content/headline_image' 39 render :partial => 'content/headline_image'
38 end 40 end
39 end 41 end
40 42
41 # Returns the published_at attribute of a page if it is not nil, otherwise 43 # Returns the published_at attribute of a page if it is not nil, otherwise
42 # it returns the auto-filled value of the created_at attribute 44 # it returns the auto-filled value of the created_at attribute
43 def date_for_page page 45 def date_for_page page
44 page.published_at.to_s(:db) rescue page.created_at.to_s(:db) 46 page.published_at.to_s(:db) rescue page.created_at.to_s(:db)
45 end 47 end
46 48
47 def author_for_page page 49 def author_for_page page
48 page.user ? page.user.login : "Unknown author" 50 page.user ? page.user.login : "Unknown author"
49 end 51 end
50 52
51 def page_title 53 def page_title
52 if @page.title && @page.title != "" 54 if @page.title && @page.title != ""
53 "CCC | #{@page.title}" 55 "CCC | #{@page.title}"
@@ -55,16 +57,16 @@ module ContentHelper
55 "CCC | Chaos Computer Club" 57 "CCC | Chaos Computer Club"
56 end 58 end
57 end 59 end
58 60
59 # This method is an output filter for templates. It accepts any kind of text 61 # This method is an output filter for templates. It accepts any kind of text
60 # and checks for an <aggregate /> tag within it. If such a tag is found, its 62 # and checks for an <aggregate /> tag within it. If such a tag is found, its
61 # attributes are parsed and converted into parameters for the 63 # attributes are parsed and converted into parameters for the
62 # render_collection method. The <aggregate /> tag will then be replaced 64 # render_collection method. The <aggregate /> tag will then be replaced
63 # entirely with the output of the render_collection method. 65 # entirely with the output of the render_collection method.
64 # 66 #
65 # Syntax of the <aggregate /> tag: 67 # Syntax of the <aggregate /> tag:
66 # 68 #
67 # <aggregate 69 # <aggregate
68 # flags="update, pressemitteilung" 70 # flags="update, pressemitteilung"
69 # limit="20" 71 # limit="20"
70 # order_by="published_at" 72 # order_by="published_at"
@@ -72,43 +74,43 @@ module ContentHelper
72 # /> 74 # />
73 def aggregate? content 75 def aggregate? content
74 options = {} 76 options = {}
75 77
76 begin 78 begin
77 if content =~ /<aggregate([^<>]*)>/ 79 if content =~ /<aggregate([^<>]*)>/
78 tag = $~.to_s 80 tag = $~.to_s
79 matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) 81 matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/)
80 82
81 matched_data.each do |data| 83 matched_data.each do |data|
82 splitted_data = data.split("=") 84 splitted_data = data.split("=")
83 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") 85 options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "")
84 end 86 end
85 87
86 options[:partial] = select_partial( options[:partial] ) 88 options[:partial] = select_partial( options[:partial] )
87 89
88 sanitize( content.sub(tag, render_collection(options)) ) 90 sanitize( content.sub(tag, render_collection(options)) )
89 else 91 else
90 sanitize( content ) 92 sanitize( content )
91 end 93 end
92 94
93 rescue 95 rescue
94 sanitize( content ) 96 sanitize( content )
95 end 97 end
96 end 98 end
97 99
98 # Takes the parameters from the aggregate? method and renders the collection 100 # Takes the parameters from the aggregate? method and renders the collection
99 # from Page.aggregate(options) with a given partial 101 # from Page.aggregate(options) with a given partial
100 def render_collection options 102 def render_collection options
101 @content_collection = Page.aggregate(options, params[:page]) 103 @content_collection = Page.aggregate(options, params[:page])
102 104
103 render( 105 render(
104 :partial => options[:partial], 106 :partial => options[:partial],
105 :collection => @content_collection, 107 :collection => @content_collection,
106 :as => :page 108 :as => :page
107 ) 109 )
108 end 110 end
109 111
110 private 112 private
111 113
112 # Either return a custom partial path if it exsits or default to the standard 114 # Either return a custom partial path if it exsits or default to the standard
113 # partial 115 # partial
114 def select_partial partial 116 def select_partial partial
@@ -122,10 +124,10 @@ module ContentHelper
122 # Check if a custom partial exists in the proper location 124 # Check if a custom partial exists in the proper location
123 def partial_exists? partial 125 def partial_exists? partial
124 File.exist?( 126 File.exist?(
125 File.join( 127 File.join(
126 RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb" 128 RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb"
127 ) 129 )
128 ) 130 )
129 end 131 end
130 132
131end 133end