Permalink
Browse files

Merge pull request #6 from inigral/add_html_options

Adding support for html_options
  • Loading branch information...
2 parents 9d5f70a + 1980944 commit 46451d639836e77c291dd2f1f86ce33f874c3d7a @pusewicz committed Apr 26, 2012
@@ -8,7 +8,7 @@ def initialize(message, options = {})
end
def to_s
- output_buffer << content_tag(:div, :class => build_class) do
+ output_buffer << content_tag(:div, build_div_options) do
html = ""
html << build_close_tag.html_safe if options[:close]
html << build_heading_tag.html_safe if options[:heading]
@@ -21,12 +21,13 @@ def to_s
private
def default_options
{
- :class => "alert",
- :block => false,
- :close => true,
- :heading => nil,
- :dismiss => true,
- :type => nil,
+ :class => "alert",
+ :block => false,
+ :close => true,
+ :heading => nil,
+ :dismiss => true,
+ :type => nil,
+ :html_options => {}
}
end
@@ -52,6 +53,11 @@ def close_tag_options
opts
end
+ def build_div_options
+ opts = { :class => build_class }
+ opts.reverse_merge(options[:html_options])
+ end
+
def build_class
classes = %w(alert)
classes << "alert-block" if options[:block]
@@ -21,12 +21,13 @@ def to_s
private
def default_options
{
- :class => "btn",
- :type => [],
- :disabled => false,
- :icon_white => false,
- :dropdown => false,
- :id => nil
+ :class => "btn",
+ :type => [],
+ :disabled => false,
+ :icon_white => false,
+ :dropdown => false,
+ :id => nil,
+ :html_options => {}
}
end
@@ -59,8 +60,7 @@ def build_tag_options
ops = {:href => @link, :class => build_class}
ops[:"data-toggle"] = 'dropdown' if options[:dropdown]
ops[:id] = options[:id] if options[:id]
- ops
+ ops.reverse_merge(options[:html_options])
end
end
-end
-
+end
@@ -8,15 +8,16 @@ def initialize(message, options = {})
end
def to_s
- output_buffer << content_tag(:span, message, :class => build_class).html_safe
+ output_buffer << content_tag(:span, message, build_tag_options).html_safe
super
end
private
def default_options
{
- :class => "label",
- :type => nil
+ :class => "label",
+ :type => nil,
+ :html_options => {}
}
end
@@ -25,6 +26,11 @@ def build_class
classes << options[:type] if options[:type]
classes.join(" ")
end
+
+ def build_tag_options
+ ops = {:class => build_class}
+ ops.reverse_merge(options[:html_options])
+ end
end
end
@@ -6,11 +6,12 @@ module AlertHelpers
#
# @param [String] message message to be displayed
# @param [Hash] options hash containing options (default: {}):
- # :block - The Boolean whether to display as a block (optional)
- # :close - The Boolean whether to render close button
- # :heading - The String heading message to render
- # :dismiss - The Boolean whether to add dismiss attribute
- # :type - The String type of alert to display: error, success or info
+ # :block - The Boolean whether to display as a block (optional)
+ # :close - The Boolean whether to render close button
+ # :heading - The String heading message to render
+ # :dismiss - The Boolean whether to add dismiss attribute
+ # :type - The String type of alert to display: error, success or info
+ # :html_options - Any additional HTML options desired on the alert DIV.
#
# Examples
#
@@ -7,12 +7,14 @@ module ButtonHelpers
# @param [String] text for the button face
# @param [String] link for the button href
# @param [Hash] options hash containing options (default: {}):
- # :type - Additional button type(s). For one, just specify a string, but
- # you can also pass an array (of sym or str) for multiple classes
- # :disabled - Will disable the button if set to true
- # :icon - Specify an icon class from bootstrap to prepend
- # :icon_white - Specify true if you want the icon to be white
- # :id - Assign an ID to the button
+ # :type - Additional button type(s). For one, just specify a string, but
+ # you can also pass an array (of sym or str) for multiple classes
+ # :disabled - Will disable the button if set to true
+ # :icon - Specify an icon class from bootstrap to prepend
+ # :icon_white - Specify true if you want the icon to be white
+ # :id - Assign an ID to the button
+ # :html_options - Any additional options you'd like to pass to the content_tag that will be created
+ # for this button's a tag (for instance :target can be specified in :html_options).
#
# Examples
#
@@ -5,7 +5,9 @@ module InlineLabelHelpers
#
# @param [String] message message to be displayed
# @param [Hash] options hash containing options (default: {}):
- # :type - The String type of alert to display: success warning important notice
+ # :type - The String type of alert to display: success warning important notice
+ # :html_options - Any additional options you'd like to pass to the span tag that will be created
+ # for this label (for instance :"data-whatever" can be specified in :html_options).
#
# Examples
#
@@ -49,6 +49,11 @@
concat bootstrap_alert_tag("Message", :heading => "Heading1", :block => false)
output_buffer.should have_tag('div strong', /Heading1/)
end
+
+ it "should add html_options to the resulting DIV tag when specified" do
+ concat bootstrap_alert_tag("Message", :html_options => {:"data-test" => "42"})
+ output_buffer.should have_tag("div[data-test='42']")
+ end
end
%w(error success info).each do |type|
@@ -56,6 +56,11 @@
concat bootstrap_button("Text", "#", :id => "foo")
output_buffer.should have_tag("a#foo")
end
+
+ it "should add html_options to the resulting a tag when specified" do
+ concat bootstrap_button("Text", "#", :html_options => {:target => "_top"})
+ output_buffer.should have_tag("a[target='_top']")
+ end
end
@@ -17,6 +17,11 @@
concat bootstrap_inline_label_tag("Hi There")
output_buffer.should have_tag("span", "Hi There")
end
+
+ it "should add html_options to the resulting SPAN tag when specified" do
+ concat bootstrap_inline_label_tag("Testing", :html_options => {:"data-test" => "42"})
+ output_buffer.should have_tag("span[data-test='42']")
+ end
end
%w(success warning important notice).each do |type|

0 comments on commit 46451d6

Please sign in to comment.