1require 'uri' |
|
3module ApplicationHelper |
|
4 INDEXED_PAGES = [ |
|
5 %w[pages index], |
|
6 %w[pages help], |
|
7 %w[pages privacy], |
|
8 %w[local_petitions index], |
|
9 %w[local_petitions show], |
|
10 %w[petitions index], |
|
11 %w[petitions show], |
|
12 %w[petitions new], |
|
13 %w[archived/petitions index], |
|
14 %w[archived/petitions show] |
|
15 ]
|
|
|
17 def increment(amount = 1) |
18 @counter ||= 0 |
|
19 @counter += amount |
|
20 end |
|
|
22 def home_page? |
23 params.values_at(:controller, :action) == %w[pages index] |
|
24 end |
|
|
26 def create_petition_page? |
27 params[:controller] == 'petitions' && params[:action].in?(%w[check create new]) |
|
28 end |
|
|
30 def petition_page? |
31 params.values_at(:controller, :action) == %w[petitions show] |
|
32 end |
|
|
34 def open_petition_page? |
35 petition_page? && @petition.open? |
|
36 end |
|
|
38 def archived_petition_page? |
39 params[:controller] == 'archived/petitions' && params[:action] == 'show' |
|
40 end |
|
|
42 def back_url |
43 referer_url || 'javascript:history.back()' |
|
44 end |
|
|
46 def noindex_page? |
47 !params.values_at(:controller, :action).in?(INDEXED_PAGES) |
|
48 end |
|
|
50 def original_url |
51 request.original_url.force_encoding('utf-8') |
|
52 end |
|
54 private
|
|
|
56 def referer_url |
57 begin |
|
58 uri = URI.parse(request.referer) |
|
59 %i[scheme host port].all?{ |k| uri.send(k) == request.send(k) } ? request.referer : nil |
|
60 rescue URI::InvalidURIError => e |
|
61 nil |
|
62 end |
|
63 end |
|
64end |