Class: Toolsmith::Views::FlashDiv

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

Constant Summary collapse

LEVEL_MAPPING =
{
  error: :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.



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

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.



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

def level
  @level
end

#view_levelObject (readonly)

Returns the value of attribute view_level.



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

def view_level
  @view_level
end

Instance Method Details



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

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


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

def close_link_text
  context.raw("×")
end

#containerObject



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

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

#to_sObject



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

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