Commit b9d985e250a978948def7d40880f465fac3ba817
1 parent
529702ad
Exists in
master
and in
28 other branches
ActionItem152: adding lightbox_button + refactoring
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1206 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
20 additions
and
5 deletions
Show diff stats
app/helpers/lightbox_helper.rb
... | ... | @@ -5,15 +5,24 @@ module LightboxHelper |
5 | 5 | end |
6 | 6 | |
7 | 7 | def lightbox_link_to(text, url, options = {}) |
8 | - the_class = 'lbOn' | |
9 | - the_class << " #{options[:class]}" if options.has_key?(:class) | |
10 | - link_to(text, url, options.merge(:class => the_class )) | |
8 | + link_to(text, url, lightbox_options(options)) | |
11 | 9 | end |
12 | 10 | |
13 | 11 | def lightbox_close(text, options = {}) |
14 | - the_class = 'lbAction' | |
12 | + link_to(text, '#', lightbox_options(options, 'lbAction').merge(:rel => 'deactivate')) | |
13 | + end | |
14 | + | |
15 | + def lightbox_button(type, label, url, options = {}) | |
16 | + button(type, label, url, lightbox_options(options)) | |
17 | + end | |
18 | + | |
19 | + # options must be an HTML options hash as passed to link_to etc. | |
20 | + # | |
21 | + # returns a new hash with lightbox class added. Keeps existing classes. | |
22 | + def lightbox_options(options, lightbox_type = 'lbOn') | |
23 | + the_class = lightbox_type | |
15 | 24 | the_class << " #{options[:class]}" if options.has_key?(:class) |
16 | - link_to(text, '#', options.merge({ :class => the_class, :rel => 'deactivate' })) | |
25 | + options.merge(:class => the_class) | |
17 | 26 | end |
18 | 27 | |
19 | 28 | end | ... | ... |
test/unit/lightbox_helper_text.rb
... | ... | @@ -38,4 +38,10 @@ class LightboxHelperTest < Test::Unit::TestCase |
38 | 38 | assert_equal '[close-lightbox]', lightbox_close('text', :class => 'my-class', :id => 'my-id' ) |
39 | 39 | end |
40 | 40 | |
41 | + should 'provide lightbox_button' do | |
42 | + expects(:button).with('type', 'label', { :action => 'popup'}, { :class => 'lbOn' }).returns('[button]') | |
43 | + | |
44 | + assert_equal '[button]', lightbox_button('type', 'label', { :action => 'popup'}) | |
45 | + end | |
46 | + | |
41 | 47 | end | ... | ... |