Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

Global view helpers.

Constant Summary collapse

SORT_LABELS =
{
  created_at_asc: 'Least recently created',
  created_at_desc: 'Most recently created',
  updated_at_asc: 'Least recently updated',
  updated_at_desc: 'Most recently updated'
}

Instance Method Summary collapse

Instance Method Details

#friendly_timestamp(record) ⇒ Object


14
15
16
17
18
19
20
# File 'app/helpers/application_helper.rb', line 14

def friendly_timestamp(record)
  if record.updated_at == record.created_at
    time_tag record.created_at, "Created #{time_ago_in_words(record.created_at)} ago"
  else
    time_tag record.updated_at, "Updated #{time_ago_in_words(record.updated_at)} ago"
  end
end

#render_markdown(text) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/application_helper.rb', line 22

def render_markdown(text)
  pipeline = HTML::Pipeline.new(
    [
      HTML::Pipeline::MarkdownFilter,
      HTML::Pipeline::SanitizationFilter
    ],
    gfm: true
  )
  raw(pipeline.to_html(text))
end

#render_sanitized(text) ⇒ Object


33
34
35
36
# File 'app/helpers/application_helper.rb', line 33

def render_sanitized(text)
  pipeline = HTML::Pipeline.new([HTML::Pipeline::SanitizationFilter])
  raw(pipeline.to_html(text))
end

#sort_label_for(key, direction) ⇒ Object


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

def sort_label_for(key, direction)
  SORT_LABELS[:"#{key}_#{direction}"]
end