Sha256: ecb5c65b1e440bf9ae72d089c380efa9405f3cecaf35541dfd1cfb56aae04473

Contents?: true

Size: 1.46 KB

Versions: 21

Compression:

Stored size: 1.46 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(translated_attribute(model.additional_info))
        text.gsub!(/^<p>/, "<p>#{render :badge}")
        html_truncate(text, length: 100)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-sortitions-0.18.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.17.2 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.18.0 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.17.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.16.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.17.0 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.16.0 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.15.2 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.15.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.15.0 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.14.4 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.14.3 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.14.2 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.14.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.13.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.12.2 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.13.0 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.12.1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.13.0.pre1 app/cells/decidim/sortitions/sortition_m_cell.rb
decidim-sortitions-0.12.0 app/cells/decidim/sortitions/sortition_m_cell.rb