Module: HackathonManagerHelper
- Defined in:
- app/helpers/hackathon_manager_helper.rb
Instance Method Summary collapse
- #acc_status_class(acc_status) ⇒ Object
-
#active_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
Same as link_to, but adds a special active class whenever the link matches the current page.
- #asset_available?(logical_path) ⇒ Boolean
- #bold(value) ⇒ Object
- #btn_link_to(name, path, options = {}) ⇒ Object
- #collection_or_text(model_value, collection) ⇒ Object
- #display_datetime(datetime, opts = {}) ⇒ Object
- #google_maps_link(*args) ⇒ Object
- #markdown(text) ⇒ Object
- #phone_link_to(phone_number) ⇒ Object
- #title(page_title) ⇒ Object
Instance Method Details
#acc_status_class(acc_status) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/hackathon_manager_helper.rb', line 75 def acc_status_class(acc_status) case acc_status when "denied" "danger" when "accepted" "success" when "waitlist" "info" when "late_waitlist" "secondary" when "pending" "secondary" when "rsvp_denied" "danger" when "rsvp_confirmed" "success" end end |
#active_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
Same as link_to, but adds a special active class whenever the link matches the current page. Only github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/url_helper.rb
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/hackathon_manager_helper.rb', line 36 def active_link_to(name = nil, = nil, = nil, &block) # this is from Rails source - ignore rubocop # rubocop:disable Style/ParallelAssignment , , name = , name, block if block_given? ||= {} # rubocop:enable Style/ParallelAssignment = (, ) url = url_for() ["href".freeze] ||= url # Begin custom active_children = .delete('active_children') active_children = true if active_children.nil? current_url = request.env['PATH_INFO'] if current_page?(url) || (active_children && current_url.include?(url)) active_class = .delete('active_class') || 'active' existing_class = ['class'] || '' ['class'] = existing_class + ' ' + active_class end # End custom content_tag("a".freeze, name || url, , &block) end |
#asset_available?(logical_path) ⇒ Boolean
63 64 65 66 67 68 69 |
# File 'app/helpers/hackathon_manager_helper.rb', line 63 def asset_available?(logical_path) if Rails.configuration.assets.compile Rails.application.precompiled_assets.include? logical_path else Rails.application.assets_manifest.assets[logical_path].present? end end |
#bold(value) ⇒ Object
29 30 31 |
# File 'app/helpers/hackathon_manager_helper.rb', line 29 def bold(value) "<strong>#{h(value)}</strong>".html_safe end |
#btn_link_to(name, path, options = {}) ⇒ Object
8 9 10 11 |
# File 'app/helpers/hackathon_manager_helper.rb', line 8 def btn_link_to(name, path, = {}) [:class] ? [:class] += " button" : [:class] = "button" link_to(name, path, ) end |
#collection_or_text(model_value, collection) ⇒ Object
71 72 73 |
# File 'app/helpers/hackathon_manager_helper.rb', line 71 def collection_or_text(model_value, collection) model_value.blank? || collection.include?(model_value) ? collection : nil end |
#display_datetime(datetime, opts = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/hackathon_manager_helper.rb', line 94 def display_datetime(datetime, opts = {}) formatted = "" if Time.now - datetime < 5.hours formatted << "#{time_ago_in_words(datetime, include_seconds: true)} ago" else format = datetime.year == Time.now.year ? "%b %-d <small>at %I:%M %P</span>" : "%b %-d, %Y <small>at %I:%M %P</small>" if Time.now - datetime > 6.months format = "%b %-d, %Y" end formatted << "on " if opts[:in_sentence] formatted << datetime.strftime(format) end "<span title=\"#{datetime}\">#{formatted}</span>".html_safe end |
#google_maps_link(*args) ⇒ Object
109 110 111 112 113 |
# File 'app/helpers/hackathon_manager_helper.rb', line 109 def google_maps_link(*args) query = args.reject(&:blank?).join('+') query = CGI.escape(query) "https://www.google.com/maps/search/?api=1&query=#{query}" end |
#markdown(text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/hackathon_manager_helper.rb', line 17 def markdown(text) markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true, fenced_code_blocks: true, disable_indented_code_blocks: true, autolink: true, tables: true, underline: true, hard_wrap: true) markdown.render(text).html_safe end |
#phone_link_to(phone_number) ⇒ Object
13 14 15 |
# File 'app/helpers/hackathon_manager_helper.rb', line 13 def phone_link_to(phone_number) link_to(phone_number, "tel:#{phone_number}") end |
#title(page_title) ⇒ Object
2 3 4 5 6 |
# File 'app/helpers/hackathon_manager_helper.rb', line 2 def title(page_title) content_for(:page_title) { page_title } content_for(:title) { page_title } page_title end |