|
2 | 2 | # module JqueryUiRailsHelpers
|
3 | 3 |
|
4 | 4 | module TabsHelper
|
5 |
| - def tabs_for( *options, &block ) |
6 |
| - raise ArgumentError, "Missing block" unless block_given? |
7 |
| - raw TabsHelper::TabsRenderer.new( *options, &block ).render |
8 |
| - end |
| 5 | + def tabs_for( *options, &block ) |
| 6 | + raise ArgumentError, "Missing block" unless block_given? |
| 7 | + raw TabsHelper::TabsRenderer.new( *options, &block ).render |
| 8 | + end |
9 | 9 |
|
10 |
| - class TabsRenderer |
| 10 | + class TabsRenderer |
11 | 11 |
|
12 |
| - def initialize( options={}, &block ) |
13 |
| - raise ArgumentError, "Missing block" unless block_given? |
| 12 | + def initialize( options={}, &block ) |
| 13 | + raise ArgumentError, "Missing block" unless block_given? |
14 | 14 |
|
15 |
| - @template = eval( 'self', block.binding ) |
16 |
| - @options = options |
17 |
| - @tabs = [] |
| 15 | + @template = eval( 'self', block.binding ) |
| 16 | + @options = options |
| 17 | + @tabs = [] |
18 | 18 |
|
19 |
| - yield self |
20 |
| - end |
| 19 | + yield self |
| 20 | + end |
21 | 21 |
|
22 |
| - def create( tab_id, tab_text, options={}, &block ) |
23 |
| - raise "Block needed for TabsRenderer#CREATE" unless block_given? |
24 |
| - @tabs << [ tab_id, tab_text, options, block, {:ajax => false} ] |
25 |
| - end |
| 22 | + def create( tab_id, tab_text, options={}, &block ) |
| 23 | + raise "Block needed for TabsRenderer#CREATE" unless block_given? |
| 24 | + @tabs << [ tab_id, tab_text, options, block, {:ajax => false} ] |
| 25 | + end |
26 | 26 |
|
27 |
| - def create_ajax( link, tab_text, options={}) |
28 |
| - @tabs << [ link, tab_text, options, nil, {:ajax => true} ] |
29 |
| - end |
| 27 | + def create_ajax( link, tab_text, options={}) |
| 28 | + @tabs << [ link, tab_text, options, nil, {:ajax => true} ] |
| 29 | + end |
30 | 30 |
|
31 |
| - def render |
32 |
| - content_tag( :div, raw([render_tabs, render_bodies].join), { :id => :tabs }.merge( @options ) ) |
33 |
| - end |
| 31 | + def render |
| 32 | + content_tag( :div, raw([render_tabs, render_bodies].join), { :id => :tabs }.merge( @options ) ) |
| 33 | + end |
34 | 34 |
|
35 |
| - private # --------------------------------------------------------------------------- |
| 35 | + private # --------------------------------------------------------------------------- |
36 | 36 |
|
37 |
| - def render_tabs |
38 |
| - content_tag :ul do |
39 |
| - result = @tabs.collect do |tab| |
| 37 | + def render_tabs |
| 38 | + content_tag :ul do |
| 39 | + result = @tabs.collect do |tab| |
40 | 40 | if tab[4][:ajax]
|
41 |
| - content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "#{tab[0]}" ) ) |
| 41 | + content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "#{tab[0]}" ) ) |
42 | 42 | else
|
43 |
| - content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) ) |
| 43 | + content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) ) |
44 | 44 | end
|
45 |
| - end.join |
| 45 | + end.join |
46 | 46 | raw(result)
|
47 |
| - end |
48 |
| - end |
| 47 | + end |
| 48 | + end |
49 | 49 |
|
50 |
| - def render_bodies |
51 |
| - @tabs.collect do |tab| |
| 50 | + def render_bodies |
| 51 | + @tabs.collect do |tab| |
52 | 52 | if tab[4][:ajax]
|
53 |
| - # there are no divs for ajaxed tabs |
| 53 | + # there are no divs for ajaxed tabs |
54 | 54 | else
|
55 |
| - content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) ) |
| 55 | + content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) ) |
56 | 56 | end
|
57 |
| - end.join.to_s |
58 |
| - end |
| 57 | + end.join.to_s |
| 58 | + end |
59 | 59 |
|
60 |
| - def method_missing( *args, &block ) |
61 |
| - @template.send( *args, &block ) |
62 |
| - end |
| 60 | + def method_missing( *args, &block ) |
| 61 | + @template.send( *args, &block ) |
| 62 | + end |
63 | 63 |
|
64 |
| - end |
| 64 | + end |
65 | 65 | end
|
0 commit comments