Class: Decidim::TabPanelsCell
- Inherits:
-
ViewModel
- Object
- ViewModel
- Decidim::TabPanelsCell
- Defined in:
- app/cells/decidim/tab_panels_cell.rb
Overview
This cell renders tabs and panels based on an items array wich contains hashes with items required to render them. Each item represent a panel and a tab and has the following keys:
- enabled: Whether the tab has to be displayed
- id: Suffix used to generate the id of each tab and panel
- text: Text of the panel
- icon: Icon key of the panel
- method: The method to render the panel content (for example, :cell or :render)
- args: The arguments to be passed to the method to render the panel content
The model is expected to be a resource with HasAttachments concern
Instance Method Summary collapse
- #items ⇒ Object
- #panels ⇒ Object
- #selected?(tab, index) ⇒ Boolean
- #selected_tab ⇒ Object
- #show ⇒ Object
- #tabs ⇒ Object
Instance Method Details
#items ⇒ Object
26 27 28 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 26 def items @items ||= model.select { |item| item[:enabled] } end |
#panels ⇒ Object
34 35 36 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 34 def panels @panels ||= items.map { |item| item.slice(:id, :method, :args) } end |
#selected?(tab, index) ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 42 def selected?(tab, index) if selected_tab tab[:id] == selected_tab[:id] else index.zero? end end |
#selected_tab ⇒ Object
38 39 40 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 38 def selected_tab @selected_tab ||= items.find { |item| item[:selected] } end |
#show ⇒ Object
20 21 22 23 24 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 20 def show return if model.blank? render :show end |
#tabs ⇒ Object
30 31 32 |
# File 'app/cells/decidim/tab_panels_cell.rb', line 30 def tabs @tabs ||= items.map { |item| item.slice(:id, :text, :icon) } end |