class Decidim::Snippets

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.

Public Class Methods

new() click to toggle source
# File lib/decidim/snippets.rb, line 9
def initialize
  @snippets = {}
end

Public Instance Methods

add(category, *snippet) click to toggle source
# File lib/decidim/snippets.rb, line 13
def add(category, *snippet)
  @snippets[category] ||= []
  @snippets[category].push(*snippet.flatten)
end
any?(category) click to toggle source
# File lib/decidim/snippets.rb, line 22
def any?(category)
  self.for(category).present?
end
display(category) click to toggle source
# File lib/decidim/snippets.rb, line 26
def display(category)
  self.for(category)&.join("\n")&.html_safe
end
for(category) click to toggle source
# File lib/decidim/snippets.rb, line 18
def for(category)
  @snippets[category]
end