Module: Trestle::TabHelper
- Defined in:
- app/helpers/trestle/tab_helper.rb
Instance Method Summary collapse
- #render_sidebar_as_tab? ⇒ Boolean
-
#sidebar(&block) ⇒ Object
Captures the given block (using ‘content_for`) as the sidebar content.
-
#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.
-
#tabs ⇒ Object
Returns a hash (name => Trestle::Tab) of the currently declared tabs.
Instance Method Details
#render_sidebar_as_tab? ⇒ Boolean
52 53 54 |
# File 'app/helpers/trestle/tab_helper.rb', line 52 def modal_request? && content_for?(:sidebar) end |
#sidebar(&block) ⇒ Object
Captures the given block (using ‘content_for`) as the sidebar content.
48 49 50 |
# File 'app/helpers/trestle/tab_helper.rb', line 48 def (&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, **) tabs[name] = tab = Tab.new(name, **) 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 [:partial] render partial: [:partial] else render partial: name.to_s end end end |
#tabs ⇒ Object
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 |