From de4beec0ab648204b4b8ec6974eb7a6525d3962e Mon Sep 17 00:00:00 2001 From: juan david pastas Date: Wed, 11 Jul 2012 11:22:38 -0500 Subject: [PATCH 1/2] Added buttons helpers, usage: btn 'A text', a_path_helper, class: 'my-class', ... btn_primary 'A text', a_path_helper, class: 'my-class', ... btn_danger 'A text', a_path_helper, class: 'my-class', ... ... is intended for additional options --- lib/bootstrap_helper/helper.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/bootstrap_helper/helper.rb b/lib/bootstrap_helper/helper.rb index 3621482..6d6f6d2 100644 --- a/lib/bootstrap_helper/helper.rb +++ b/lib/bootstrap_helper/helper.rb @@ -145,6 +145,17 @@ def render_list(list=[], options={}) return ul.to_s end + + def btn(text, path, type = '', options={}) + css = options.delete(:class) || options.delete('class') + link_to text, path, {class: 'btn ' + type + ' ' + css}.merge(options) + end + + %w(primary info success warning danger inverse).each do |type| + define_method 'btn_' + type do |text, path, options = {}| + btn text, path, 'btn-' + type, options + end + end # Composite pattern class TagNode From 1eb0e5bdebc78f7796c9da902e25ca627701ce63 Mon Sep 17 00:00:00 2001 From: juan david pastas Date: Wed, 11 Jul 2012 11:28:01 -0500 Subject: [PATCH 2/2] fixed when options[:class] is nil --- lib/bootstrap_helper/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bootstrap_helper/helper.rb b/lib/bootstrap_helper/helper.rb index 6d6f6d2..e817b68 100644 --- a/lib/bootstrap_helper/helper.rb +++ b/lib/bootstrap_helper/helper.rb @@ -147,7 +147,7 @@ def render_list(list=[], options={}) end def btn(text, path, type = '', options={}) - css = options.delete(:class) || options.delete('class') + css = (options.delete(:class) || options.delete('class')).to_s link_to text, path, {class: 'btn ' + type + ' ' + css}.merge(options) end