Module: Sincerely::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#event_timestamp(event) ⇒ Object



36
37
38
# File 'app/helpers/sincerely/application_helper.rb', line 36

def event_timestamp(event)
  event.timestamp || event.created_at
end

#event_type_badge_class(event_type) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/sincerely/application_helper.rb', line 48

def event_type_badge_class(event_type)
  case event_type.to_s.downcase
  when 'delivery', 'send' then 'badge-delivered'
  when 'open' then 'badge-opened'
  when 'click' then 'badge-clicked'
  when 'bounce', 'hard_bounce', 'soft_bounce' then 'badge-bounced'
  when 'complaint', 'spam_complaint' then 'badge-complained'
  when 'reject' then 'badge-rejected'
  when 'delay' then 'badge-delayed'
  else 'badge-default'
  end
end

#format_event_options(options) ⇒ Object



40
41
42
43
44
45
46
# File 'app/helpers/sincerely/application_helper.rb', line 40

def format_event_options(options)
  return nil if options.blank?

  JSON.pretty_generate(options)
rescue JSON::GeneratorError
  options.to_s
end

#format_timestamp(time) ⇒ Object



30
31
32
33
34
# File 'app/helpers/sincerely/application_helper.rb', line 30

def format_timestamp(time)
  return '-' unless time

  time.strftime('%b %d, %Y %H:%M:%S')
end

#inline_svg(name) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/helpers/sincerely/application_helper.rb', line 20

def inline_svg(name)
  return '' unless name.match?(%r{\A[a-z0-9_\-/]+\z}i) && name.exclude?('..')

  base = Sincerely::Engine.root.join('app', 'assets', 'images')
  path = base.join("#{name}.svg")
  return '' unless path.to_s.start_with?(base.to_s) && path.exist?

  raw path.read # rubocop:disable Rails/OutputSafety -- SVGs are read from the engine's own assets, not user input
end

#state_badge_class(state) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/sincerely/application_helper.rb', line 5

def state_badge_class(state)
  case state.to_s
  when 'draft' then 'badge-draft'
  when 'accepted' then 'badge-accepted'
  when 'delivered' then 'badge-delivered'
  when 'opened' then 'badge-opened'
  when 'clicked' then 'badge-clicked'
  when 'bounced' then 'badge-bounced'
  when 'complained' then 'badge-complained'
  when 'rejected' then 'badge-rejected'
  when 'delayed' then 'badge-delayed'
  else 'badge-default'
  end
end