Class: Toolsmith::Views::FlashDiv

Inherits:
Base
  • Object
show all
Defined in:
lib/toolsmith/views/flash_div.rb

Constant Summary collapse

LEVEL_MAPPING =
{
  error: :error,
  alert: :error,
  success: :success,
  notice: :info
}

Instance Attribute Summary collapse

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

#content_tag

Constructor Details

#initialize(context, level) ⇒ FlashDiv

Returns a new instance of FlashDiv.



14
15
16
17
18
# File 'lib/toolsmith/views/flash_div.rb', line 14

def initialize(context, level)
  super(context)
  @level = level
  @view_level = LEVEL_MAPPING[level]
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



11
12
13
# File 'lib/toolsmith/views/flash_div.rb', line 11

def level
  @level
end

#view_levelObject (readonly)

Returns the value of attribute view_level.



12
13
14
# File 'lib/toolsmith/views/flash_div.rb', line 12

def view_level
  @view_level
end

Instance Method Details



28
29
30
31
32
33
34
35
36
37
# File 'lib/toolsmith/views/flash_div.rb', line 28

def close_link
  context.link_to(
    close_link_text,
    "#",
    class: "close",
    data: {
      dismiss: "alert"
    }
  )
end


47
48
49
# File 'lib/toolsmith/views/flash_div.rb', line 47

def close_link_text
  context.raw("×")
end

#containerObject



39
40
41
42
43
44
45
# File 'lib/toolsmith/views/flash_div.rb', line 39

def container
  context.full_width_column do
     :div, class: "alert alert-#{view_level}" do
      yield
    end
  end
end

#to_sObject



20
21
22
23
24
25
26
# File 'lib/toolsmith/views/flash_div.rb', line 20

def to_s
  if context.flash[level].present?
    container do
      close_link + context.flash[level].html_safe
    end
  end
end