Module: Trestle::TabHelper

Defined in:
app/helpers/trestle/tab_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_sidebar_as_tab?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/helpers/trestle/tab_helper.rb', line 52

def render_sidebar_as_tab?
  modal_request? && content_for?(:sidebar)
end

Captures the given block (using ‘content_for`) as the sidebar content.



48
49
50
# File 'app/helpers/trestle/tab_helper.rb', line 48

def sidebar(&block)
  content_for(:sidebar, &block)
end

#tab(name, **options) ⇒ Object

Creates a tab pane using content via the given block, :partial option or partial template automatically inferred from the tab name.

It also appends a Trestle::Tab object to the list of declared tabs that is accessible via the #tabs helper (e.g. for rendering the tab links).

name - (Symbol) Internal name for the tab options - Hash of options (default: {}):

:label - Optional tab label. If not provided, will be inferred by the
         admin-translated tab name (`admin.tabs.{name}` i18n scope)
:badge - Optional badge to show next to the tab label (e.g. a counter)
:partial - Optional partial template name to use when a block is not provided

Examples

<%= tab :details %>
=> Automatically renders the 'details' partial (e.g. "_details.html.erb") as the tab content

<%= tab :metadata, partial: "meta" %>
=> Renders the 'meta' partial (e.g. "_meta.html.erb") as the tab content

<%= tab :comments do %> ...
=> Renders the given block as the tab content

Returns a HTML-safe String.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/trestle/tab_helper.rb', line 28

def tab(name, **options)
  tabs[name] = tab = Tab.new(name, **options)

  tag.div(id: tab.id(("modal" if modal_request?)), class: ["tab-pane", ('active' if name == tabs.keys.first)], role: "tabpanel") do
    if block_given?
      yield
    elsif options[:partial]
      render partial: options[:partial]
    else
      render partial: name.to_s
    end
  end
end

#tabsObject

Returns a hash (name => Trestle::Tab) of the currently declared tabs.



43
44
45
# File 'app/helpers/trestle/tab_helper.rb', line 43

def tabs
  @_trestle_tabs ||= {}
end