1 module ApplicationHelper
2 require "rexml/document"
3 include SocialShareButtonHelper
7 Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe
9 Rinku.auto_link(ERB::Util.h(text), :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe
13 def rss_link_to(args = {})
14 link_to image_tag("RSS.png", :size => "16x16", :class => "align-text-bottom"), args
17 def atom_link_to(args = {})
18 link_to image_tag("RSS.png", :size => "16x16", :class => "align-text-bottom"), args
23 dir == "rtl" ? "rtl" : "ltr"
29 def friendly_date(date)
30 tag.time(time_ago_in_words(date), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
33 def friendly_date_ago(date)
34 tag.time(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
38 if content_for? :body_class
39 content_for :body_class
41 "#{params[:controller]} #{params[:controller]}-#{params[:action]}"
45 def header_nav_link_class(path)
46 ["nav-link", current_page?(path) ? "text-secondary-emphasis" : "text-secondary"]
51 :locale => I18n.locale,
52 :preferred_editor => preferred_editor,
53 :preferred_languages => preferred_languages.expand.map(&:to_s)
57 data[:user] = current_user.id.to_json
59 data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon } if current_user.home_location?
62 data[:location] = session[:location] if session[:location]
63 data[:oauth_token] = oauth_token.token if oauth_token
68 # If the flash is a hash, then it will be a partial with a hash of locals, so we can call `render` on that
69 # This allows us to render html into a flash message in a safe manner.
70 def render_flash(flash)
72 render flash.with_indifferent_access
77 flash.inspect if Rails.env.development?
80 # Generates a set of social share buttons based on the specified options.
81 def render_social_share_buttons(opts = {})
82 sites = opts.fetch(:allow_sites, [])
83 valid_sites, invalid_sites = SocialShareButtonHelper.filter_allowed_sites(sites)
86 invalid_sites.each do |invalid_site|
87 Rails.logger.error("Invalid site or icon not configured: #{invalid_site}")
91 :class => "social-share-button d-flex gap-1 align-items-end flex-wrap mb-3"
93 valid_sites.map do |site|
95 :rel => ["nofollow", opts[:rel]].compact,
96 :class => "ssb-icon rounded-circle",
97 :title => I18n.t("application.share.#{site}.title"),
101 link_to SocialShareButtonHelper.generate_share_url(site, opts), link_options do
102 image_tag(SocialShareButtonHelper.icon_path(site), :alt => I18n.t("application.share.#{site}.alt"), :size => 28)