summaryrefslogtreecommitdiff
path: root/app/helpers/broadcast_messages_helper.rb
blob: 0a15c29cfb5841fa67d7eeae063a2f15621b11fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module BroadcastMessagesHelper
  def broadcast_message(message)
    return unless message.present?

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

  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

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

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