From 150b8c771fb236b13a8a5a7161fe4eb61ff6121b Mon Sep 17 00:00:00 2001 From: Matt Scilipoti Date: Tue, 22 Nov 2016 16:21:24 -0500 Subject: [PATCH] alert: add alert-dismissible class - per https://getbootstrap.com/components/#alerts-dismissible --- lib/bh/classes/alert_box.rb | 5 +++++ lib/bh/helpers/alert_box_helper.rb | 1 + spec/shared/alert_box_helper.rb | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/lib/bh/classes/alert_box.rb b/lib/bh/classes/alert_box.rb index ab9b4d1..8cc00a8 100644 --- a/lib/bh/classes/alert_box.rb +++ b/lib/bh/classes/alert_box.rb @@ -7,6 +7,11 @@ class AlertBox < Base def context_class AlertBox.contexts[@options.fetch :context, @options[:priority]] end + + # @return [#to_s] the css class which indicates this box is dimissible, to assign to the alert box. + def dismissible_class + 'alert-dismissible' if @options[:dismissible] + end # @return [#to_s] the HTML to show a dismissible button for the alert box. def dismissible_button diff --git a/lib/bh/helpers/alert_box_helper.rb b/lib/bh/helpers/alert_box_helper.rb index d5b0e43..7d10039 100644 --- a/lib/bh/helpers/alert_box_helper.rb +++ b/lib/bh/helpers/alert_box_helper.rb @@ -32,6 +32,7 @@ def alert_box(*args, &block) alert_box.append_class! :alert alert_box.append_class! alert_box.context_class + alert_box.append_class! alert_box.dismissible_class alert_box.merge! role: :alert alert_box.prepend_html! alert_box.dismissible_button alert_box.render_tag :div diff --git a/spec/shared/alert_box_helper.rb b/spec/shared/alert_box_helper.rb index badbf35..704b2ba 100644 --- a/spec/shared/alert_box_helper.rb +++ b/spec/shared/alert_box_helper.rb @@ -1,4 +1,5 @@ shared_examples_for 'the alert_box helper' do + # based on https://getbootstrap.com/components/#alerts all_tests_pass_with 'no alert options' all_tests_pass_with 'extra alert options' all_tests_pass_with 'the :context alert option' @@ -37,6 +38,11 @@ html = '' expect(alert_box: {dismissible: false}).to generate html end + + specify 'set to true, adds class alert-dismissible to the alert div' do + html = %r{