Module: HackathonManagerHelper

Defined in:
app/helpers/hackathon_manager_helper.rb

Instance Method Summary collapse

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

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, options = nil, html_options = nil, &block)
  # this is from Rails source - ignore rubocop
  # rubocop:disable Style/ParallelAssignment
  html_options, options, name = options, name, block if block_given?
  options ||= {}
  # rubocop:enable Style/ParallelAssignment

  html_options = convert_options_to_data_attributes(options, html_options)

  url = url_for(options)
  html_options["href".freeze] ||= url

  # Begin custom
  active_children = html_options.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 = html_options.delete('active_class') || 'active'
    existing_class = html_options['class'] || ''
    html_options['class'] = existing_class + ' ' + active_class
  end
  # End custom

  ("a".freeze, name || url, html_options, &block)
end

#asset_available?(logical_path) ⇒ Boolean

Returns:

  • (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


8
9
10
11
# File 'app/helpers/hackathon_manager_helper.rb', line 8

def btn_link_to(name, path, options = {})
  options[:class] ? options[:class] += " button" : options[:class] = "button"
  link_to(name, path, options)
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


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


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