Module: PistaaHelper
- Defined in:
- app/helpers/pistaa_helper.rb
Instance Method Summary collapse
-
#hide_pistaa_slot_item(slot, item) ⇒ Object
Register a template as hidden, so it won’t be rendered with ‘render_pistaa_slot`.
-
#pistaa_hidden_items ⇒ Object
Helper to access the hidden items.
-
#pistaa_slot_item_hidden?(slot, item) ⇒ Boolean
Check if a template is hidden.
-
#pistaa_slot_items(slot) ⇒ Object
List all the keys of the items in the slot.
-
#render_pistaa_slot(slot) ⇒ Object
Render all templates in the slot, but skip the items that are registered as hidden.
-
#render_pistaa_slot_item(slot, item) ⇒ Object
Render a specific template from a slot (regardless of it was hidden), and register it as hidden, so it won’t be rendered if ‘render_pistaa_slot` is called.
Instance Method Details
#hide_pistaa_slot_item(slot, item) ⇒ Object
Register a template as hidden, so it won’t be rendered with ‘render_pistaa_slot`.
36 37 38 |
# File 'app/helpers/pistaa_helper.rb', line 36 def hide_pistaa_slot_item(slot, item) pistaa_hidden_items << [slot, item] end |
#pistaa_hidden_items ⇒ Object
Helper to access the hidden items. You shouldn’t need to access this helper from the template. Use ‘pistaa_slot_item_hidden?` and { }`hide_pistaa_slot_item` instead.
30 31 32 |
# File 'app/helpers/pistaa_helper.rb', line 30 def pistaa_hidden_items @pistaa_hidden_items ||= [] end |
#pistaa_slot_item_hidden?(slot, item) ⇒ Boolean
Check if a template is hidden.
41 42 43 |
# File 'app/helpers/pistaa_helper.rb', line 41 def pistaa_slot_item_hidden?(slot, item) pistaa_hidden_items.include? [slot, item] end |
#pistaa_slot_items(slot) ⇒ Object
List all the keys of the items in the slot.
23 24 25 |
# File 'app/helpers/pistaa_helper.rb', line 23 def pistaa_slot_items(slot) Pistaa[slot].item_keys end |
#render_pistaa_slot(slot) ⇒ Object
Render all templates in the slot, but skip the items that are registered as hidden. It repeatedly calls ‘render_pistaa_slot_item`, so the rendered templates will be registered as hidden.
6 7 8 9 10 11 12 |
# File 'app/helpers/pistaa_helper.rb', line 6 def render_pistaa_slot(slot) pistaa_slot_items(slot).map do |item| next if pistaa_slot_item_hidden?(slot, item) render_pistaa_slot_item(slot, item) end.join("\n").html_safe end |
#render_pistaa_slot_item(slot, item) ⇒ Object
Render a specific template from a slot (regardless of it was hidden), and register it as hidden, so it won’t be rendered if ‘render_pistaa_slot` is called.
17 18 19 20 |
# File 'app/helpers/pistaa_helper.rb', line 17 def render_pistaa_slot_item(slot, item) hide_pistaa_slot_item(slot, item) render partial: Pistaa[slot][item] end |