Sha256: 2ee34a62ccfd9ba42843b09a810b0346e3f430d0814b21e742e0af0bf667d178

Contents?: true

Size: 1.24 KB

Versions: 15

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # A helper to expose the comments component for a commentable
    module CommentsHelper
      # Render commentable comments inside the `expanded` template content.
      #
      # resource - A commentable resource
      def comments_for(resource, options = {})
        return unless resource.commentable?

        append_stylesheet_pack_tag "decidim_comments"
        # This script cannot be deferred, otherwise the DOMReady and turbo:load listeners are not
        # executed from a Turbo Frame call
        append_javascript_pack_tag "decidim_comments", defer: false

        inline_comments_for(resource, options)
      end

      # Creates a Comments component through the comments cell.
      #
      # resource - A commentable resource
      #
      # Returns the comments cell
      def inline_comments_for(resource, options = {})
        return unless resource.commentable?

        cell(
          "decidim/comments/comments",
          resource,
          machine_translations: machine_translations_toggled?,
          single_comment: params.fetch("commentId", nil),
          order: options[:order],
          polymorphic: options[:polymorphic]
        ).to_s
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-comments-0.29.2 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.5 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.1 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.4 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.0 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.3 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.0.rc4 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.0.rc3 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.0.rc2 lib/decidim/comments/comments_helper.rb
decidim-comments-0.29.0.rc1 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.2 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.1 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.0 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.0.rc5 lib/decidim/comments/comments_helper.rb
decidim-comments-0.28.0.rc4 lib/decidim/comments/comments_helper.rb