Class: Ffp::Presenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers
Defined in:
lib/ffp/presenter.rb

Constant Summary collapse

ALERT_TYPES =
%w(success warning info alert secondary)

Instance Method Summary collapse

Constructor Details

#initialize(flash) ⇒ Presenter

Returns a new instance of Presenter.



7
8
9
# File 'lib/ffp/presenter.rb', line 7

def initialize(flash)
  @flash = flash
end

Instance Method Details

#for_foundationObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ffp/presenter.rb', line 12

def for_foundation
  flash_messages = Array.new

  @flash.each do |type, message|
    next if message.blank?

    type = "success" if type == "notice"
    next unless ALERT_TYPES.include?(type)

    Array(message).each do |msg|
      flash_messages << (
        :div,
        msg.html_safe + (:a, raw("&times;"), :class => 'close'),
        :class => css_classes_for_type(type),
        :'data-alert' => true
      )
    end
  end

  flash_messages.join("\n").html_safe
end