Skip to content

Commit 2dd2e12

Browse files
author
CodeOfficer
committed
boom
1 parent 09727cd commit 2dd2e12

File tree

9 files changed

+89
-281
lines changed

9 files changed

+89
-281
lines changed

helpers/accordions_helper.rb

Lines changed: 0 additions & 56 deletions
This file was deleted.

helpers/tabs_helper.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

lib/helpers/tabs_helper.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def initialize( options={}, &block )
2121

2222
def create( tab_id, tab_text, options={}, &block )
2323
raise "Block needed for TabsRenderer#CREATE" unless block_given?
24-
@tabs << [ tab_id, tab_text, options, block ]
24+
@tabs << [ tab_id, tab_text, options, block, {:ajax => false} ]
25+
end
26+
27+
def create_ajax( link, tab_text, options={})
28+
@tabs << [ link, tab_text, options, nil, {:ajax => true} ]
2529
end
2630

2731
def render
@@ -33,15 +37,23 @@ def render
3337
def render_tabs
3438
content_tag :ul do
3539
result = @tabs.collect do |tab|
36-
content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) )
40+
if tab[4][:ajax]
41+
content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "#{tab[0]}" ) )
42+
else
43+
content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) )
44+
end
3745
end.join
3846
raw(result)
3947
end
4048
end
4149

4250
def render_bodies
4351
@tabs.collect do |tab|
44-
content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) )
52+
if tab[4][:ajax]
53+
# there are no divs for ajaxed tabs
54+
else
55+
content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) )
56+
end
4557
end.join.to_s
4658
end
4759

notes/accordion.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

notes/misc.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

notes/notes.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

notes/tab.rb

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'test_helper'
2+
3+
class AccordionsHelperTest < ActionView::TestCase
4+
5+
context "creating accordions without a block syntax" do
6+
should 'raises an exception' do
7+
assert_raise ArgumentError do
8+
@accordions = accordions_for
9+
end
10+
end
11+
end
12+
13+
context "creating one set of accordions" do
14+
setup do
15+
@accordions = accordions_for do |accordion|
16+
accordion.create('accordion_one', 'One') { "Accordion One." }
17+
accordion.create('accordion_two', 'Two') { "Accordion Two." }
18+
end
19+
end
20+
21+
should 'have proper dom structure' do
22+
render :text => @accordions
23+
assert_select "div[id='accordions']", 1
24+
assert_select "div[id='accordions'] h3[id='accordion_one']", 1
25+
assert_select "div[id='accordions'] h3[id='accordion_one'] a", {:count => 1, :text => "One"}
26+
assert_select "div[id='accordions'] h3[id='accordion_two']", 1
27+
assert_select "div[id='accordions'] h3[id='accordion_two'] a", {:count => 1, :text => "Two"}
28+
assert_select "div[id='accordions'] div", 2
29+
end
30+
end
31+
32+
end
33+
34+
# <div id="accordions">
35+
# <h3 id="accordion_one"><a href="#">One</a></h3>
36+
# <div>Accordion Two.</div>
37+
# <h3 id="accordion_two"><a href="#">Two</a></h3>
38+
# <div>Accordion One.</div>
39+
# </div>

0 commit comments

Comments
 (0)