Sha256: c2ba65cbc5fc6506afbbb5b8041531ce2f711a3301cb57ca73eb434666de0cef

Contents?: true

Size: 1.4 KB

Versions: 50

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This module includes helpers to show moderation in admin
    module ModerationsHelper
      # Public: Renders an extract of the content reported in a text format.
      def reported_content_excerpt_for(reportable, options = {})
        I18n.with_locale(options.fetch(:locale, I18n.locale)) do
          reportable_content = reportable.reported_attributes.map do |attribute_name|
            attribute_value = reportable.attributes.with_indifferent_access[attribute_name]
            next translated_attribute(attribute_value) if attribute_value.is_a? Hash

            attribute_value
          end
          reportable_content.filter(&:present?).join(". ").truncate(options.fetch(:limit, 100))
        end
      end

      # Public: Finds the type and name of the participatory space the given
      # `reportable` object is associated to.
      #
      # Returns a String, or `nil` if the space is not found.
      def participatory_space_title_for(reportable, options = {})
        space = reportable.try(:participatory_space)
        return unless space

        I18n.with_locale(options.fetch(:locale, I18n.locale)) do
          title = translated_attribute(space.try(:title) || space.try(:name))
          type = space.class.model_name.human
          [type, title].compact.join(": ").truncate(options.fetch(:limit, 100))
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.4 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.27.9 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.29.0 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.3 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.27.8 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.29.0.rc4 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.29.0.rc3 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.29.0.rc2 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.29.0.rc1 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.2 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.27.7 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.1 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.27.6 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.26.10 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.26.9 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.0 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.27.5 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.0.rc5 app/helpers/decidim/admin/moderations_helper.rb
decidim-admin-0.28.0.rc4 app/helpers/decidim/admin/moderations_helper.rb