11module AccordionsHelper
2-
32 def accordions_for ( *options , &block )
43 raise ArgumentError , "Missing block" unless block_given?
5-
6- accordions = AccordionsHelper ::AccordionsRenderer . new ( *options , &block )
7- accordions_html = accordions . render
8- concat accordions_html
4+ raw AccordionsHelper ::AccordionsRenderer . new ( *options , &block ) . render
95 end
10-
6+
117 class AccordionsRenderer
12-
8+
139 def initialize ( options = { } , &block )
1410 raise ArgumentError , "Missing block" unless block_given?
1511
@@ -19,38 +15,33 @@ def initialize( options={}, &block )
1915
2016 yield self
2117 end
22-
18+
2319 def create ( accordion_id , accordion_text , options = { } , &block )
2420 raise "Block needed for AccordionsRenderer#CREATE" unless block_given?
2521 @accordions << [ accordion_id , accordion_text , options , block ]
2622 end
27-
28- def render
29- content_tag :div , { :id => :accordions } . merge ( @options ) do
30- @accordions . collect do |accordion |
31- accordion_head ( accordion ) + accordion_body ( accordion )
32- end . join
33- end
23+
24+ def render
25+ content = @accordions . collect do |accordion |
26+ accordion_head ( accordion ) << accordion_body ( accordion )
27+ end . join
28+ content_tag ( :div , raw ( content ) , { :id => :accordions } . merge ( @options ) )
3429 end
35-
36- private # ---------------------------------------------------------------------------
37-
30+
31+ private # ---------------------------------------------------------------------------
32+
3833 def accordion_head ( accordion )
39- content_tag :h3 , :id => accordion [ 0 ] do
40- link_to accordion [ 1 ] , '#'
41- end
34+ content_tag :h3 , link_to ( accordion [ 1 ] , '#' ) , :id => accordion [ 0 ]
4235 end
43-
36+
4437 def accordion_body ( accordion )
45- content_tag :div do
46- capture ( &accordion [ 3 ] )
47- end
38+ content_tag :div , capture ( &accordion [ 3 ] )
4839 end
49-
40+
5041 def method_missing ( *args , &block )
5142 @template . send ( *args , &block )
5243 end
53-
54- end
5544
45+ end
5646end
47+
0 commit comments