require 'uri'
module ApplicationHelper - ApplicationHelper has no descriptive comment
INDEXED_PAGES = [
%w[pages index],
%w[pages help],
%w[pages privacy],
%w[local_petitions index],
%w[local_petitions show],
%w[petitions index],
%w[petitions show],
%w[petitions new],
%w[archived/petitions index],
%w[archived/petitions show]
]
def increment(amount = 1)
@counter ||= 0
@counter += amount
end
def home_page?
params.values_at(:controller, :action) == %w[pages index]
end
def create_petition_page?
params[:controller] == 'petitions' && params[:action].in?(%w[check create new])
end
def petition_page?
params.values_at(:controller, :action) == %w[petitions show]
end
def open_petition_page?
petition_page? && @petition.open?
end
def archived_petition_page?
params[:controller] == 'archived/petitions' && params[:action] == 'show'
end
def back_url
referer_url || 'javascript:history.back()'
end
def noindex_page?
!params.values_at(:controller, :action).in?(INDEXED_PAGES)
end
def original_url
request.original_url.force_encoding('utf-8')
end
private
def referer_url - ApplicationHelper#referer_url has approx 6 statements
begin
uri = URI.parse(request.referer) -
%i[scheme host port].all?{ |k| uri.send(k) == request.send(k) } ? request.referer : nil -
- ApplicationHelper#referer_url has the variable name 'k'
rescue URI::InvalidURIError => e - ApplicationHelper#referer_url has the variable name 'e'
nil
end
end
end