Class: Decidim::Snippets
- Inherits:
-
Object
- Object
- Decidim::Snippets
- Defined in:
- decidim-core/lib/decidim/snippets.rb
Overview
A utility for managing snippets that need to be registered during the view display and displayed in another part of the application. For example, maps can register their snippets when the map is displayed but they need to be added to the <head> section of the document.
Instance Method Summary collapse
- #add(category, *snippet) ⇒ Object
- #any?(category) ⇒ Boolean
- #display(category) ⇒ Object
- #for(category) ⇒ Object
-
#initialize ⇒ Snippets
constructor
A new instance of Snippets.
Constructor Details
#initialize ⇒ Snippets
Returns a new instance of Snippets.
9 10 11 |
# File 'decidim-core/lib/decidim/snippets.rb', line 9 def initialize @snippets = {} end |
Instance Method Details
#add(category, *snippet) ⇒ Object
13 14 15 16 |
# File 'decidim-core/lib/decidim/snippets.rb', line 13 def add(category, *snippet) @snippets[category] ||= [] @snippets[category].push(*snippet.flatten) end |
#any?(category) ⇒ Boolean
22 23 24 |
# File 'decidim-core/lib/decidim/snippets.rb', line 22 def any?(category) self.for(category).present? end |
#display(category) ⇒ Object
26 27 28 |
# File 'decidim-core/lib/decidim/snippets.rb', line 26 def display(category) self.for(category)&.join("\n")&.html_safe end |
#for(category) ⇒ Object
18 19 20 |
# File 'decidim-core/lib/decidim/snippets.rb', line 18 def for(category) @snippets[category] end |