Sha256: 553c689c5173c02f2ebace00b3593019691834c3fb818d788a5ee15c20b54925

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Decidim
  # This module contains all the logic needed for a controller to render a participatory space
  # public layout.
  #
  module ParticipatorySpaceContext
    extend ActiveSupport::Concern

    class_methods do
      # Public: Called on a controller, it sets up all the surrounding methods to render a
      # participatory space's template. It expects the method `current_participatory_space` to be
      # defined, from which it will extract the participatory manifest.
      #
      # options - A hash used to modify the behavior of the layout. :only: - An array of actions on
      #           which the layout will be applied.
      #
      # Returns nothing.
      def participatory_space_layout(options = {})
        layout :layout, options
        before_action :authorize_participatory_space, options
      end
    end

    included do
      include Decidim::NeedsOrganization

      helper ParticipatorySpaceHelpers, IconHelper
      helper_method :current_participatory_space
      helper_method :current_participatory_space_manifest
      helper_method :current_participatory_space_context

      delegate :manifest, to: :current_participatory_space, prefix: true
    end

    private

    def current_participatory_space_context
      :public
    end

    def current_participatory_space
      raise NotImplementedError
    end

    def authorize_participatory_space
      authorize! :read, current_participatory_space
    end

    def ability_context
      super.merge(
        current_participatory_space: current_participatory_space
      )
    end

    def layout
      current_participatory_space_manifest.context(current_participatory_space_context).layout
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.10.1 app/controllers/concerns/decidim/participatory_space_context.rb
decidim-core-0.10.0 app/controllers/concerns/decidim/participatory_space_context.rb
decidim-core-0.9.3 app/controllers/concerns/decidim/participatory_space_context.rb
decidim-core-0.9.2 app/controllers/concerns/decidim/participatory_space_context.rb
decidim-core-0.9.1 app/controllers/concerns/decidim/participatory_space_context.rb
decidim-core-0.9.0 app/controllers/concerns/decidim/participatory_space_context.rb