Sha256: 87f00b5120e0ae4b283721d58ea73ec6d15f24e23e29cd1b31ea7b19769ea899

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require "cell/partial"

module Decidim
  module Sortitions
    # This cell renders a sortition with its M-size card.
    class SortitionMCell < Decidim::CardMCell
      include Decidim::Sortitions::Engine.routes.url_helpers

      private

      def has_author?
        false
      end

      def has_state?
        true
      end

      # Even though we need to render the badge, we can't do it in the normal
      # way, because the paragraph comes from a user input and contains HTML.
      # This causes the badge and the paragraph to appear in different lines.
      # In order to fix it, check the `description` method.
      def has_badge?
        false
      end

      def badge_name
        return t("filters.cancelled", scope: "decidim.sortitions.sortitions") if model.cancelled?

        t("filters.active", scope: "decidim.sortitions.sortitions")
      end

      def state_classes
        return ["muted"] if model.cancelled?

        ["success"]
      end

      def proposals_count
        @proposals_count = model.proposals.count
      end

      # In order to render the badge inline with the paragraph text we need to
      # find the opening `<p>` tag and include the badge right after it. This
      # makes the layout look good.
      def description
        text = decidim_sanitize_editor(translated_attribute(model.additional_info), strip_tags: true)
        text.sub!(/<p>/, "<p>#{render :badge}")
        html_truncate(text, length: 100)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-sortitions-0.27.9 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.8 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.7 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.6 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.26.10 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.26.9 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.5 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.26.8 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.4 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.27.3 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.26.7 app/cells/decidim/sortitions/sortition_m_cell.rb