Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianoleittes/db6b05af8ce9b5c26037 to your computer and use it in GitHub Desktop.
Save fabianoleittes/db6b05af8ce9b5c26037 to your computer and use it in GitHub Desktop.
module ApplicationHelper
def tenant_name
tenant_configuration.tenant_name
end
def full_title(page_title)
base_title = "#{app_display_name} Dashboard"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}".html_safe
end
end
def app_display_name
tenant_configuration.display_name
end
def participant_login_link
tenant_configuration.disc_url
end
def analytics
render("layouts/analytics") if Rails.env.production?
end
def display_header?
projects_index? || allowed_view?
end
def time_from(date)
from_time = DateTime.parse(date)
distance_of_time_in_words(from_time, DateTime.now) << " ago"
end
def support_email_link
link_to(t("support"), "mailto:#{support_email}")
end
def terms_link
link_to(t("terms"), page_path("terms"))
end
def website_link
link_to(website_link_text, website_url, target: "_blank")
end
def copyright
copy = "&copy; #{t("copyright")} #{copyright_agencies} #{copyright_period}"
copy.html_safe
end
def complete_on_device
t("task.complete_on_device",
app_name: app_display_name,
ios: ios_link,
android: android_link
).html_safe
end
def current_language_flag
language = Language.all.select { |l| l.code == I18n.locale.to_s }.first
if language.try(:flag_state) == "finished"
image_tag(language.flag, alt: language.label)
end
end
def render_masthead
render("layouts/masthead") if display_header?
end
private
def projects_index?
controller_name == "projects" && action_name != "show"
end
def allowed_view?
white_list.include?(controller_name)
end
def white_list
%w(sessions users passwords pages joins)
end
def website_link_text
strip_www(URI.parse(website_url).host)
end
def strip_www(host)
host.start_with?("www.") ? host[4..-1] : host
end
def website_url
tenant_configuration.website
end
def support_email
tenant_configuration.support_email
end
def copyright_agencies
tenant_configuration.copyright
end
def copyright_period
"2012-#{Time.now.year}"
end
def ios_link
link_to("iOS", tenant_configuration.ios_url, target: "_blank")
end
def android_link
link_to("Android", tenant_configuration.android_url, target: "_blank")
end
def tenant_configuration
Hashie::Mash.new(Crowdlab.tenants[Crowdlab.tenant])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment