1 # frozen_string_literal: true
3 module ApplicationHelper
4 require "rexml/document"
7 link_attr = 'rel="nofollow" dir="auto"'
9 Rinku.auto_link(text, :urls, link_attr).html_safe
11 Rinku.auto_link(ERB::Util.h(text), :urls, link_attr).html_safe
15 def rss_link_to(args = {})
16 link_to image_tag("RSS.png", :size => "16x16", :class => "align-text-bottom"), args
19 def atom_link_to(args = {})
20 link_to image_tag("RSS.png", :size => "16x16", :class => "align-text-bottom"), args
25 dir == "rtl" ? "rtl" : "ltr"
31 def friendly_date(date)
32 tag.time(time_ago_in_words(date), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
35 def friendly_date_ago(date)
36 tag.time(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
40 if content_for? :body_class
41 content_for :body_class
43 controller_part = params[:controller].tr("/", "-")
44 "#{controller_part} #{controller_part}-#{params[:action]}"
48 def header_nav_link_class(path)
49 ["nav-link", current_page?(path) ? "active text-secondary-emphasis" : "text-secondary"]
54 :locale => I18n.locale,
55 :preferred_editor => preferred_editor,
56 :preferred_languages => preferred_languages.expand.map(&:to_s)
60 data[:user] = current_user.id.to_json
62 data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon } if current_user.home_location?
65 data[:location] = session[:location] if session[:location]
66 data[:oauth_token] = oauth_token.token if oauth_token
71 # If the flash is a hash, then it will be a partial with a hash of locals, so we can call `render` on that
72 # This allows us to render html into a flash message in a safe manner.
73 def render_flash(flash)
75 render flash.with_indifferent_access
80 flash.inspect if Rails.env.development?