Module: Spyro::ActionViewExtension::TabsHelper

Included in:
WidgetsHelper
Defined in:
lib/spyro/helpers/action_view_extension.rb

Instance Method Summary collapse

Instance Method Details

#tab(name, options = {}, &block) ⇒ Object



151
152
153
# File 'lib/spyro/helpers/action_view_extension.rb', line 151

def tab name, options = {}, &block
  @tabs[name] = options.merge :content => capture(&block)
end

#tabsObject



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/spyro/helpers/action_view_extension.rb', line 148

def tabs
  @tabs = {}

  def tab name, options = {}, &block
    @tabs[name] = options.merge :content => capture(&block)
  end

  yield

  capture_haml do
    haml_tag :ul, :class => "nav nav-tabs nav-justified", role: "tablist" do
      @tabs.keys.each_with_index do |name, index|
        haml_tag :li, :class => (index == 0 ? "active" : "") do
          haml_concat link_to(name, "##{name}", "data-toggle" => "tab")
        end
      end
    end

    haml_tag :div, :class => "tab-content" do
      @tabs.each_with_index do |(name, values), index|
        haml_tag :div, :id => name, :class => ["tab-pane", (index == 0 ? "active" : "")] do
          haml_concat values[:content]
        end
      end
    end
  end
end