Sha256: e80c5206c51ae83ff923319917cfedcebcc4a303d8bf6f4d4cd02a53a3997134

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module Decidim
  module EnhancedTextwork
    # Custom helpers, scoped to the paragraphs engine.
    #
    module ParagraphCellsHelper
      include Decidim::EnhancedTextwork::ApplicationHelper
      include Decidim::EnhancedTextwork::Engine.routes.url_helpers
      include Decidim::LayoutHelper
      include Decidim::ApplicationHelper
      include Decidim::TranslationsHelper
      include Decidim::ResourceReferenceHelper
      include Decidim::TranslatableAttributes
      include Decidim::CardHelper

      delegate :title, :state, :published_state?, :withdrawn?, :amendable?, :emendation?, to: :model

      def has_actions?
        return context[:has_actions] if context[:has_actions].present?

        paragraphs_controller? && index_action? && current_settings.votes_enabled? && !model.draft?
      end

      def has_footer?
        return context[:has_footer] if context[:has_footer].present?

        paragraphs_controller? && index_action? && current_settings.votes_enabled? && !model.draft?
      end

      def paragraphs_controller?
        context[:controller].class.to_s == "Decidim::EnhancedTextwork::ParagraphsController"
      end

      def index_action?
        context[:controller].action_name == "index"
      end

      def current_settings
        model.component.current_settings
      end

      def component_settings
        model.component.settings
      end

      def current_component
        model.component
      end

      def from_context
        @options[:from]
      end

      def badge_name
        humanize_paragraph_state state
      end

      def state_classes
        case state
        when "accepted"
          ["success"]
        when "rejected"
          ["alert"]
        when "evaluating"
          ["warning"]
        when "withdrawn"
          ["alert"]
        else
          ["muted"]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb
decidim-enhanced_textwork-1.0.4 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb
decidim-enhanced_textwork-1.0.3 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb
decidim-enhanced_textwork-1.0.2 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb
decidim-enhanced_textwork-1.0.1 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb
decidim-enhanced_textwork-1.0.0 app/helpers/decidim/enhanced_textwork/paragraph_cells_helper.rb