From 8640f3567283eb3ecc65008a52b8ae4fdbeadf36 Mon Sep 17 00:00:00 2001 From: hukl Date: Fri, 11 Feb 2011 12:40:42 +0100 Subject: reject events with no corresponding page spaces --- app/helpers/content_helper.rb | 58 ++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'app/helpers') 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 @@ module ContentHelper - + def main_menu menu_items = MenuItem.all(:order => "position ASC") render( - :partial => 'content/main_navigation', + :partial => 'content/main_navigation', :locals => {:menu_items => menu_items} ) end - + def calendar occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) - + if occurrences.empty? occurrences = Occurrence.find_next end - + + occurrences = occurrences.reject { |o| o.node.head.nil? } + render( - :partial => 'content/front_page_calendar', + :partial => 'content/front_page_calendar', :locals => {:occurrences => occurrences} ) end - + def tags render :partial => 'content/tags' end - + def featured_articles @featured_articles = FeaturedArticle.all render :partial => 'content/featured_articles' end - + def headline_image @images = @page.assets.images - + unless @images.empty? render :partial => 'content/headline_image' end end - + # Returns the published_at attribute of a page if it is not nil, otherwise # it returns the auto-filled value of the created_at attribute def date_for_page page page.published_at.to_s(:db) rescue page.created_at.to_s(:db) end - + def author_for_page page page.user ? page.user.login : "Unknown author" end - + def page_title if @page.title && @page.title != "" "CCC | #{@page.title}" @@ -55,16 +57,16 @@ module ContentHelper "CCC | Chaos Computer Club" end end - + # This method is an output filter for templates. It accepts any kind of text - # and checks for an tag within it. If such a tag is found, its - # attributes are parsed and converted into parameters for the - # render_collection method. The tag will then be replaced + # and checks for an tag within it. If such a tag is found, its + # attributes are parsed and converted into parameters for the + # render_collection method. The tag will then be replaced # entirely with the output of the render_collection method. # # Syntax of the tag: # - # def aggregate? content options = {} - + begin if content =~ /]*)>/ tag = $~.to_s matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) - + matched_data.each do |data| splitted_data = data.split("=") options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") end - + options[:partial] = select_partial( options[:partial] ) sanitize( content.sub(tag, render_collection(options)) ) else sanitize( content ) end - + rescue sanitize( content ) end end - + # Takes the parameters from the aggregate? method and renders the collection # from Page.aggregate(options) with a given partial def render_collection options @content_collection = Page.aggregate(options, params[:page]) render( - :partial => options[:partial], + :partial => options[:partial], :collection => @content_collection, :as => :page ) end - + private - + # Either return a custom partial path if it exsits or default to the standard # partial def select_partial partial @@ -122,10 +124,10 @@ module ContentHelper # Check if a custom partial exists in the proper location def partial_exists? partial File.exist?( - File.join( + File.join( RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb" ) ) end - + end -- cgit v1.3