Module: ArticlesHelper
- Defined in:
- app/helpers/articles_helper.rb
Instance Method Summary collapse
- #article_region(node) ⇒ Object
- #articles_rss_feed(node) ⇒ Object
- #articles_rss_feed_auto_discovery ⇒ Object
- #articles_rss_feed_link(text, options = {}) ⇒ Object
- #articles_rss_feed_url ⇒ Object
- #author ⇒ Object
- #authors ⇒ Object
- #link_for_filter_text(text, node, current_filter) ⇒ Object
- #link_for_month_filter(node, year, month, count) ⇒ Object
- #link_for_year_filter(node, year) ⇒ Object
- #link_to_next_article(label = 'Next') ⇒ Object
- #link_to_previous_article(label = 'Previous') ⇒ Object
- #paginated_articles(pagination_options = {}, &block) ⇒ Object
- #selected_filter(filter) ⇒ Object
Instance Method Details
#article_region(node) ⇒ Object
92 93 94 |
# File 'app/helpers/articles_helper.rb', line 92 def article_region(node) node.regions.blank? ? "All Regions" : node.regions end |
#articles_rss_feed(node) ⇒ Object
35 36 37 |
# File 'app/helpers/articles_helper.rb', line 35 def articles_rss_feed(node) node.articles.all(build_query_from_params) end |
#articles_rss_feed_auto_discovery ⇒ Object
49 50 51 |
# File 'app/helpers/articles_helper.rb', line 49 def articles_rss_feed_auto_discovery auto_discovery_link_tag(:rss, articles_rss_feed_url, :title => "Articles RSS Feed") end |
#articles_rss_feed_link(text, options = {}) ⇒ Object
39 40 41 |
# File 'app/helpers/articles_helper.rb', line 39 def articles_rss_feed_link(text, = {}) link_to(text, articles_rss_feed_url, ) end |
#articles_rss_feed_url ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/articles_helper.rb', line 43 def articles_rss_feed_url querystring = build_querystring querystring[:format] = :rss node_path(@node.list, querystring) end |
#author ⇒ Object
100 101 102 |
# File 'app/helpers/articles_helper.rb', line 100 def User.first(permalink: params[:author]) if valid_filter?(params[:author]) end |
#authors ⇒ Object
96 97 98 |
# File 'app/helpers/articles_helper.rb', line 96 def User.where(tags: 'authors') end |
#link_for_filter_text(text, node, current_filter) ⇒ Object
69 70 71 72 73 74 |
# File 'app/helpers/articles_helper.rb', line 69 def link_for_filter_text(text, node, current_filter) querystring = build_querystring(current_filter) content_tag(:li) do link_to(text, node_path(node.list, querystring)) end end |
#link_for_month_filter(node, year, month, count) ⇒ Object
81 82 83 84 85 86 |
# File 'app/helpers/articles_helper.rb', line 81 def link_for_month_filter(node, year, month, count) querystring = build_querystring(:year => year.year, :month => month + 1) content_tag(:li, link_to("#{t(:'date.month_names')[month+1]} <span>(#{count})</span>".html_safe, node_path(node.list, querystring)) ) unless count.zero? end |
#link_for_year_filter(node, year) ⇒ Object
76 77 78 79 |
# File 'app/helpers/articles_helper.rb', line 76 def link_for_year_filter(node, year) querystring = build_querystring(:year => year.year) link_to("#{year.year} <span>(#{year.total})</span>".html_safe, node_path(node.list, querystring)) end |
#link_to_next_article(label = 'Next') ⇒ Object
53 54 55 56 57 58 59 |
# File 'app/helpers/articles_helper.rb', line 53 def link_to_next_article(label = 'Next') if next_article = @node.articles.where(:position.gt => @node.position).first link_to label, node_path(next_article), class: 'next_page' else content_tag :span, label, class: 'next_page disabled' end end |
#link_to_previous_article(label = 'Previous') ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/helpers/articles_helper.rb', line 61 def link_to_previous_article(label = 'Previous') if previous_article = @node.articles.where(:position.lt => @node.position).order('position DESC').first link_to label, node_path(previous_article), class: 'previous_page' else content_tag :span, label, class: 'previous_page disabled' end end |
#paginated_articles(pagination_options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/articles_helper.rb', line 4 def paginated_articles( = {}, &block) = { :per_page => 10, :page => params[:page] } # Add search filters .merge!(build_query_from_params) if params[:year] if params[:month] time = Time.zone.local(params[:year].to_i, params[:month].to_i, 1) [:published_at] = { :$gt => time.beginning_of_month, :$lt => time.end_of_month } else time = Time.zone.local(params[:year].to_i, 1, 1) [:published_at] = { :$gt => time.beginning_of_year, :$lt => time.end_of_year } end end articles = @node.articles.paginate() # Set default will_paginate options = { :renderer => Noodall::Articles::CustomLinkRenderer, :next_label => "Next", :previous_label => "Previous", :first_label => "First", :last_label => "Last" } # Override any options passed in .merge!() paginated_section(articles, ) { yield(articles) }.html_safe unless articles.empty? end |
#selected_filter(filter) ⇒ Object
88 89 90 |
# File 'app/helpers/articles_helper.rb', line 88 def selected_filter(filter) params[filter.downcase] || filter end |