Skip to content

Commit

Permalink
Add button_html and button_class options for "flash_messages"
Browse files Browse the repository at this point in the history
  • Loading branch information
choonkeat committed Nov 5, 2014
1 parent 3b58118 commit 77263f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/rails_utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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</button>}
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</button>}
view.flash_messages(button_class: 'abc def').must_match %r{button class="abc def"}
end
end

end
end

0 comments on commit 77263f7

Please sign in to comment.