diff --git a/app/helpers/lightbox_helper.rb b/app/helpers/lightbox_helper.rb index f61361f..a31ab8a 100644 --- a/app/helpers/lightbox_helper.rb +++ b/app/helpers/lightbox_helper.rb @@ -5,15 +5,24 @@ module LightboxHelper end def lightbox_link_to(text, url, options = {}) - the_class = 'lbOn' - the_class << " #{options[:class]}" if options.has_key?(:class) - link_to(text, url, options.merge(:class => the_class )) + link_to(text, url, lightbox_options(options)) end def lightbox_close(text, options = {}) - the_class = 'lbAction' + link_to(text, '#', lightbox_options(options, 'lbAction').merge(:rel => 'deactivate')) + end + + def lightbox_button(type, label, url, options = {}) + button(type, label, url, lightbox_options(options)) + end + + # options must be an HTML options hash as passed to link_to etc. + # + # returns a new hash with lightbox class added. Keeps existing classes. + def lightbox_options(options, lightbox_type = 'lbOn') + the_class = lightbox_type the_class << " #{options[:class]}" if options.has_key?(:class) - link_to(text, '#', options.merge({ :class => the_class, :rel => 'deactivate' })) + options.merge(:class => the_class) end end diff --git a/test/unit/lightbox_helper_text.rb b/test/unit/lightbox_helper_text.rb index 9085a5d..6a3b2d4 100644 --- a/test/unit/lightbox_helper_text.rb +++ b/test/unit/lightbox_helper_text.rb @@ -38,4 +38,10 @@ class LightboxHelperTest < Test::Unit::TestCase assert_equal '[close-lightbox]', lightbox_close('text', :class => 'my-class', :id => 'my-id' ) end + should 'provide lightbox_button' do + expects(:button).with('type', 'label', { :action => 'popup'}, { :class => 'lbOn' }).returns('[button]') + + assert_equal '[button]', lightbox_button('type', 'label', { :action => 'popup'}) + end + end -- libgit2 0.21.2