diff options
Diffstat (limited to 'app/helpers/content_helper.rb')
| -rw-r--r-- | app/helpers/content_helper.rb | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index d6c96f1..21cc579 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | module ContentHelper | 1 | module ContentHelper |
| 2 | 2 | ||
| 3 | def main_menu | 3 | def main_menu |
| 4 | menu_items = MenuItem.all(:order => "position ASC") | 4 | menu_items = MenuItem.order("position ASC").all |
| 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} |
| @@ -9,13 +9,13 @@ module ContentHelper | |||
| 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+6.weeks)) |
| 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? } | 18 | occurrences = occurrences.reject { |o| o.node.nil? || o.node.head.nil? } |
| 19 | 19 | ||
| 20 | render( | 20 | render( |
| 21 | :partial => 'content/front_page_calendar', | 21 | :partial => 'content/front_page_calendar', |
| @@ -43,7 +43,7 @@ module ContentHelper | |||
| 43 | # 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 |
| 44 | # it returns the auto-filled value of the created_at attribute | 44 | # it returns the auto-filled value of the created_at attribute |
| 45 | def date_for_page page | 45 | def date_for_page page |
| 46 | page.published_at.to_s(:db) rescue page.created_at.to_s(:db) | 46 | I18n.l(page.published_at, :format => :ccc) rescue I18n.l(page.created_at, :format => :ccc) |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | def author_for_page page | 49 | def author_for_page page |
| @@ -51,7 +51,7 @@ module ContentHelper | |||
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | def page_title | 53 | def page_title |
| 54 | if @page.title && @page.title != "" | 54 | if @page && @page.title && @page.title != "" |
| 55 | "CCC | #{@page.title}" | 55 | "CCC | #{@page.title}" |
| 56 | else | 56 | else |
| 57 | "CCC | Chaos Computer Club" | 57 | "CCC | Chaos Computer Club" |
| @@ -59,41 +59,43 @@ module ContentHelper | |||
| 59 | end | 59 | end |
| 60 | 60 | ||
| 61 | # 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 |
| 62 | # and checks for an <aggregate /> tag within it. If such a tag is found, its | 62 | # and checks for an [aggregate short code within it. If such a code is found, |
| 63 | # attributes are parsed and converted into parameters for the | 63 | # its # attributes are parsed and converted into parameters for the |
| 64 | # render_collection method. The <aggregate /> tag will then be replaced | 64 | # render_collection method. The [aggregate ] short code will then be replaced |
| 65 | # entirely with the output of the render_collection method. | 65 | # entirely with the output of the render_collection method. |
| 66 | # | 66 | # |
| 67 | # Syntax of the <aggregate /> tag: | 67 | # Syntax of the [aggregate ] short code: |
| 68 | # | 68 | # |
| 69 | # <aggregate | 69 | # [aggregate |
| 70 | # flags="update, pressemitteilung" | 70 | # flags="update, pressemitteilung" |
| 71 | # limit="20" | 71 | # limit="20" |
| 72 | # order_by="published_at" | 72 | # order_by="published_at" |
| 73 | # order_direction="DESC" | 73 | # order_direction="DESC" |
| 74 | # /> | 74 | # ] |
| 75 | def aggregate? content | 75 | def aggregate? content |
| 76 | options = {} | 76 | options = {} |
| 77 | 77 | ||
| 78 | cccms_attributes = ActionView::Base.sanitized_allowed_attributes + ['lang'] | ||
| 79 | |||
| 78 | begin | 80 | begin |
| 79 | if content =~ /<aggregate([^<>]*)>/ | 81 | if content =~ /\[aggregate([^\]]*)\]/ |
| 80 | tag = $~.to_s | 82 | tag = $~.to_s |
| 81 | matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) | 83 | matched_data = $1.scan(/\w+\="[a-zA-Z\s\/_\d,.=]*"/) |
| 82 | 84 | ||
| 83 | matched_data.each do |data| | 85 | matched_data.each do |data| |
| 84 | splitted_data = data.split("=") | 86 | splitted_data = data.split("=", 2) |
| 85 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") | 87 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/"/, "") |
| 86 | end | 88 | end |
| 87 | 89 | ||
| 88 | options[:partial] = select_partial( options[:partial] ) | 90 | options[:partial] = select_partial(options[:partial]) |
| 89 | 91 | ||
| 90 | sanitize( content.sub(tag, render_collection(options)) ) | 92 | sanitize(content.sub(tag, render_collection(options)), :attributes => cccms_attributes) |
| 91 | else | 93 | else |
| 92 | sanitize( content ) | 94 | sanitize(content, :attributes => cccms_attributes) |
| 93 | end | 95 | end |
| 94 | 96 | ||
| 95 | rescue | 97 | rescue |
| 96 | sanitize( content ) | 98 | sanitize(content, :attributes => cccms_attributes) |
| 97 | end | 99 | end |
| 98 | end | 100 | end |
| 99 | 101 | ||
| @@ -124,9 +126,7 @@ module ContentHelper | |||
| 124 | # Check if a custom partial exists in the proper location | 126 | # Check if a custom partial exists in the proper location |
| 125 | def partial_exists? partial | 127 | def partial_exists? partial |
| 126 | File.exist?( | 128 | File.exist?( |
| 127 | File.join( | 129 | Rails.root.join('app', 'views', 'custom', 'partials', "_#{partial}.html.erb") |
| 128 | RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb" | ||
| 129 | ) | ||
| 130 | ) | 130 | ) |
| 131 | end | 131 | end |
| 132 | 132 | ||
