Module: Adva::View::Form::Tabs

Included in:
Adva::View::Form
Defined in:
lib/adva/view/form/tabs.rb

Instance Method Summary collapse

Instance Method Details

#form_for(*args, &block) ⇒ Object


5
6
7
# File 'lib/adva/view/form/tabs.rb', line 5

def form_for(*args, &block)
  super(*args, &with_tabs(block))
end

#simple_form_for(*args, &block) ⇒ Object


9
10
11
# File 'lib/adva/view/form/tabs.rb', line 9

def simple_form_for(*args, &block)
  super(*args, &with_tabs(block))
end

#tab(*args, &block) ⇒ Object

should store the tabs on the form builder object instead of the controller


40
41
42
# File 'lib/adva/view/form/tabs.rb', line 40

def tab(*args, &block)
  controller.tabs.tab(*args, &block)
end

#with_tabs(block) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/adva/view/form/tabs.rb', line 13

def with_tabs(block)
  if respond_to?(:sidebar)
    lambda do |*args|
      block.call(*args)
      sidebar

      div :class => :tabs do
        ul do
          controller.tabs.each do |tab|
            li(:class => tab.active? ? :active : '') do
              link_to(:"admin.tabs.#{tab.name}", "##{tab.name}")
            end
          end
        end
        controller.tabs.each do |tab|
          div :id => "tab_#{tab.name}", :class => "tab #{tab.active? ? :active : ''}" do
            tab.blocks.each { |block| block.call }
          end
        end
      end
    end
  else
    block
  end
end