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`.
38 39 40 |
# File 'app/helpers/pistaa_helper.rb', line 38 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.
32 33 34 |
# File 'app/helpers/pistaa_helper.rb', line 32 def pistaa_hidden_items @pistaa_hidden_items ||= [] end |
#pistaa_slot_item_hidden?(slot, item) ⇒ Boolean
Check if a template is hidden.
43 44 45 |
# File 'app/helpers/pistaa_helper.rb', line 43 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.
25 26 27 |
# File 'app/helpers/pistaa_helper.rb', line 25 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 13 14 |
# File 'app/helpers/pistaa_helper.rb', line 6 def render_pistaa_slot(slot) capture do pistaa_slot_items(slot).map do |item| next if pistaa_slot_item_hidden?(slot, item) concat(render_pistaa_slot_item(slot, item)) end end 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.
19 20 21 22 |
# File 'app/helpers/pistaa_helper.rb', line 19 def render_pistaa_slot_item(slot, item) hide_pistaa_slot_item(slot, item) render partial: Pistaa[slot][item] end |