Class: BootstrapBuilders::Flash
- Inherits:
-
Object
- Object
- BootstrapBuilders::Flash
- Defined in:
- lib/bootstrap_builders/flash.rb
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(args) ⇒ Flash
constructor
A new instance of Flash.
Constructor Details
#initialize(args) ⇒ Flash
Returns a new instance of Flash.
2 3 4 5 6 |
# File 'lib/bootstrap_builders/flash.rb', line 2 def initialize(args) @class = args[:class] @alert_types = [:success, :info, :warning, :danger] @context = args.fetch(:context) end |
Instance Method Details
#html ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bootstrap_builders/flash.rb', line 8 def html = [] @context.flash.each do |type, | # Skip empty messages, e.g. for devise messages set to nothing in a locale file. next if .blank? type = type.to_sym type = :success if type == :notice type = :danger if type == :alert type = :danger if type == :error next unless @alert_types.include?(type) = @context.content_tag(:button, @context.raw("×"), type: "button", class: "close", "data-dismiss" => "alert") Array().each do |msg| text = @context.content_tag(:div, + msg, class: classes(type)) << text if msg end end @context.flash.clear .join("\n").html_safe # rubocop:disable Rails/OutputSafety end |