Sha256: 975bf252309a3c3cc18a5d2113481bbb4c0f7e19dd81d9487de637b926eb770d

Contents?: true

Size: 736 Bytes

Versions: 58

Compression:

Stored size: 736 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # 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.
  class Snippets
    def initialize
      @snippets = {}
    end

    def add(category, *snippet)
      @snippets[category] ||= []
      @snippets[category].push(*snippet.flatten)
    end

    def for(category)
      @snippets[category]
    end

    def any?(category)
      self.for(category).present?
    end

    def display(category)
      self.for(category)&.join("\n")&.html_safe
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-core-0.29.1 lib/decidim/snippets.rb
decidim-core-0.28.4 lib/decidim/snippets.rb
decidim-core-0.27.9 lib/decidim/snippets.rb
decidim-core-0.29.0 lib/decidim/snippets.rb
decidim-core-0.28.3 lib/decidim/snippets.rb
decidim-core-0.27.8 lib/decidim/snippets.rb
decidim-core-0.29.0.rc4 lib/decidim/snippets.rb
decidim-core-0.29.0.rc3 lib/decidim/snippets.rb
decidim-core-0.29.0.rc2 lib/decidim/snippets.rb
decidim-core-0.29.0.rc1 lib/decidim/snippets.rb
decidim-core-0.28.2 lib/decidim/snippets.rb
decidim-core-0.27.7 lib/decidim/snippets.rb
decidim-core-0.28.1 lib/decidim/snippets.rb
decidim-core-0.27.6 lib/decidim/snippets.rb
decidim-core-0.26.10 lib/decidim/snippets.rb
decidim-core-0.26.9 lib/decidim/snippets.rb
decidim-core-0.28.0 lib/decidim/snippets.rb
decidim-core-0.27.5 lib/decidim/snippets.rb
decidim-core-0.28.0.rc5 lib/decidim/snippets.rb
decidim-core-0.28.0.rc4 lib/decidim/snippets.rb