From 77263f7188f832f44d45982d812aeb12d33ccf6b Mon Sep 17 00:00:00 2001 From: choonkeat Date: Wed, 5 Nov 2014 12:27:02 +0800 Subject: [PATCH] Add button_html and button_class options for "flash_messages" --- lib/rails_utils.rb | 2 +- test/rails_utils_test.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rails_utils.rb b/lib/rails_utils.rb index 91dbbcb..bbac10c 100644 --- a/lib/rails_utils.rb +++ b/lib/rails_utils.rb @@ -37,7 +37,7 @@ def flash_messages(options = {}) flash.collect do |key, message| next if message.blank? - content_tag(:div, content_tag(:button, "x", type: "button", class: "close", "data-dismiss" => "alert") + message, class: "#{flash_class(key)} fade in #{options[:class]}") + content_tag(:div, content_tag(:button, options[:button_html] || "x", type: "button", class: options[:button_class] || "close", "data-dismiss" => "alert") + message, class: "#{flash_class(key)} fade in #{options[:class]}") end.join("\n").html_safe end diff --git a/test/rails_utils_test.rb b/test/rails_utils_test.rb index 2dc0e8c..0f7240d 100644 --- a/test/rails_utils_test.rb +++ b/test/rails_utils_test.rb @@ -191,5 +191,20 @@ def set_flash(key, message) view.flash_messages.must_match /data-dismiss=.*alert/ end end + + describe "options" do + it "can allow override of button content (default 'x')" do + set_flash :alert, "not important" + view.flash_messages.must_match %r{>x} + view.flash_messages(button_html: '').must_match %r{button class="close"} + end + + it "can allow override of button css class (default 'close')" do + set_flash :alert, "not important" + view.flash_messages.must_match %r{>x} + view.flash_messages(button_class: 'abc def').must_match %r{button class="abc def"} + end + end + end end