Module: BroadcastMessagesHelper

Defined in:
app/helpers/broadcast_messages_helper.rb

Instance Method Summary collapse

Instance Method Details

#broadcast_message(message = BroadcastMessage.current) ⇒ Object


2
3
4
5
6
7
8
# File 'app/helpers/broadcast_messages_helper.rb', line 2

def broadcast_message(message = BroadcastMessage.current)
  return unless message.present?

   :div, class: 'broadcast-message', style: broadcast_message_style(message) do
    icon('bullhorn') << ' ' << render_broadcast_message(message.message)
  end
end

#broadcast_message_status(broadcast_message) ⇒ Object


25
26
27
28
29
30
31
32
33
# File 'app/helpers/broadcast_messages_helper.rb', line 25

def broadcast_message_status(broadcast_message)
  if broadcast_message.active?
    'Active'
  elsif broadcast_message.ended?
    'Expired'
  else
    'Pending'
  end
end

#broadcast_message_style(broadcast_message) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/broadcast_messages_helper.rb', line 10

def broadcast_message_style(broadcast_message)
  style = ''

  if broadcast_message.color.present?
    style << "background-color: #{broadcast_message.color}"
    style << '; ' if broadcast_message.font.present?
  end

  if broadcast_message.font.present?
    style << "color: #{broadcast_message.font}"
  end

  style
end

#render_broadcast_message(message) ⇒ Object


35
36
37
# File 'app/helpers/broadcast_messages_helper.rb', line 35

def render_broadcast_message(message)
  Banzai.render(message, pipeline: :broadcast_message).html_safe
end