Module: ArticlesHelper

Defined in:
app/helpers/articles_helper.rb

Instance Method Summary collapse

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_discoveryObject



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


39
40
41
# File 'app/helpers/articles_helper.rb', line 39

def articles_rss_feed_link(text, options = {})
  link_to(text, articles_rss_feed_url, options)
end

#articles_rss_feed_urlObject



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

#authorObject



100
101
102
# File 'app/helpers/articles_helper.rb', line 100

def author
  User.first(permalink: params[:author]) if valid_filter?(params[:author])
end

#authorsObject



96
97
98
# File 'app/helpers/articles_helper.rb', line 96

def authors
  User.where(tags: 'authors')
end


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)
  (:li) do
    link_to(text, node_path(node.list, querystring))
  end
end


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)
  (:li,
    link_to("#{t(:'date.month_names')[month+1]} <span>(#{count})</span>".html_safe, node_path(node.list, querystring))
  ) unless count.zero?
end


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
     :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
     :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(pagination_options = {}, &block)
  options = { :per_page => 10, :page => params[:page] }

  # Add search filters
  options.merge!(build_query_from_params)

  if params[:year]
    if params[:month]
      time = Time.zone.local(params[:year].to_i, params[:month].to_i, 1)
      options[:published_at] = { :$gt => time.beginning_of_month, :$lt => time.end_of_month }
    else
      time = Time.zone.local(params[:year].to_i, 1, 1)
      options[:published_at] = { :$gt => time.beginning_of_year, :$lt => time.end_of_year }
    end
  end
  articles = @node.articles.paginate(options)

  # Set default will_paginate options
  paginated_section_options = {
    :renderer => Noodall::Articles::CustomLinkRenderer,
    :next_label => "Next",
    :previous_label => "Previous",
    :first_label => "First",
    :last_label => "Last"
  }

  # Override any options passed in
  paginated_section_options.merge!(pagination_options)
  paginated_section(articles, paginated_section_options) { 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