Class: Blacklight::System::FlashMessageComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/system/flash_message_component.rb

Instance Method Summary collapse

Methods inherited from Component

reset_compiler!, sidecar_files, upstream_sidecar_files

Constructor Details

#initialize(type:, message: nil) ⇒ FlashMessageComponent

Returns a new instance of FlashMessageComponent.



10
11
12
13
# File 'app/components/blacklight/system/flash_message_component.rb', line 10

def initialize(type:, message: nil)
  @message = message
  @classes = alert_class(type)
end

Instance Method Details

#alert_class(type) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'app/components/blacklight/system/flash_message_component.rb', line 19

def alert_class(type)
  case type.to_s
  when 'success' then "alert-success"
  when 'notice'  then "alert-info"
  when 'alert'   then "alert-warning"
  when 'error'   then "alert-danger"
  else "alert-#{type}"
  end
end

#before_renderObject



15
16
17
# File 'app/components/blacklight/system/flash_message_component.rb', line 15

def before_render
  with_message { @message } if @message
end