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.27.9 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.8 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.7 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.6 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.10 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.9 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.5 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.8 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.4 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.3 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.7 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.5 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.2 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.1 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.4 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.0 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.3 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.0.rc2 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.27.0.rc1 app/controllers/decidim/templates/admin/concerns/templatable.rb
decidim-templates-0.26.2 app/controllers/decidim/templates/admin/concerns/templatable.rb