Sha256: bb3dd8d06a7e1ff7dceba04eca5075598bdb26d8a434219714579dcb6a0a1e5c

Contents?: true

Size: 1.24 KB

Versions: 45

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Templates
    module Admin
      module Concerns
        module Templatable
          # Common logic to load template-related resources in controller
          extend ActiveSupport::Concern

          included do
            helper_method :templates, :choose_template?

            def templates
              @templates = current_organization.templates.where(templatable_type: templatable_type)
              @templates = @templates.where.not(id: params[:id]) if templates_path?
              @templates
            end

            def templates_path?
              controller_path.match?("^decidim/templates/.*")
            end

            def choose_template?
              return false if templatable.is_a? Decidim::Templates::Template

              templates.any? && templatable.pristine?
            end

            protected

            def templatable
              raise NotImplementedError, "Please set the templatable resource in your controller"
            end

            def templatable_type
              raise NotImplementedError, "The templatable type is needed to load resources"
            end
          end
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
decidim-templates-0.23.3 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.23.2 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.23.1 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.23.1.rc1 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.23.0 app/controllers/decidim/templates/admin/concerns/templatable.rb