Module: NitroRails::ApplicationHelper

Defined in:
app/helpers/nitro_rails/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#alert_message(message, threat = :notice) ⇒ Object



3
4
5
# File 'app/helpers/nitro_rails/application_helper.rb', line 3

def alert_message(message, threat=:notice) 
  (:div, message, class: "alert #{threat}")
end

#android_app?Boolean



41
42
43
# File 'app/helpers/nitro_rails/application_helper.rb', line 41

def android_app?
  request.user_agent&.include?("Android")
end

#back_path(default = root_path) ⇒ Object



11
12
13
# File 'app/helpers/nitro_rails/application_helper.rb', line 11

def back_path(default = root_path)
  params[:referrer] || default # Should we add in :back?
end

#contextual_day_format(date, offset: 0) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/nitro_rails/application_helper.rb', line 19

def contextual_day_format(date, offset: 0) 
  relative_date = Time.current.in_time_zone(offset).to_date
  case (relative_date - date).to_i 
  when 0...1
    "Today"
  when 1...2
    "Yesterday"
  when 2...7
    date.to_fs(:weekday)
  else 
    if (relative_date.year == date.year)
      date.to_fs(:month_and_day)
    else 
      date.to_fs(:month_day_and_year)
    end
  end
end

#current_color_schemeObject



7
8
9
# File 'app/helpers/nitro_rails/application_helper.rb', line 7

def current_color_scheme
  current_user && current_user.respond_to?(:settings) && current_user.settings.dark_mode? ? "dark-mode" : "light-mode"
end

#ios_app?Boolean



37
38
39
# File 'app/helpers/nitro_rails/application_helper.rb', line 37

def ios_app?
  request.user_agent&.include?("iOS")
end

#polymorphize(record, polymorphic_type) ⇒ Object



15
16
17
# File 'app/helpers/nitro_rails/application_helper.rb', line 15

def polymorphize(record, polymorphic_type)
  { "#{polymorphic_type}_id": record.id, "#{polymorphic_type}_type": record.class.name }
end