Sha256: 338f0cb9b5125196c550c291a31eb7e653d5bf6ec75d054178e511b63947a42b

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

module Plutonium
  module Core
    module Controllers
      module Presentable
        extend ActiveSupport::Concern

        included do
          helper_method :presentable_attributes
        end

        private

        def resource_presenter(resource_class, resource_record)
          raise NotImplementedError, "#{self.class}#resource_presenter"
        end

        def current_presenter
          resource_presenter resource_class, @resource_record
        end

        def presentable_attributes
          @presentable_attributes ||= begin
            presentable_attributes = permitted_attributes
            presentable_attributes -= [scoped_entity_param_key, :"#{scoped_entity_param_key}_id"] if scoped_to_entity?
            presentable_attributes -= [parent_input_param, :"#{parent_input_param}_id"] if current_parent.present?
            presentable_attributes
          end
        end

        def build_collection
          Plutonium::Core::UI::Collection.new(
            resource_class:,
            records: @resource_records,
            fields: current_presenter.defined_renderers_for(presentable_attributes),
            actions: current_presenter.actions,
            pagination: @pagy,
            search_object: @ransack,
            search_field: current_presenter.search_field
          )
        end

        def build_detail
          Plutonium::Core::UI::Detail.new(
            resource_class:,
            record: resource_record,
            fields: current_presenter.defined_renderers_for(presentable_attributes),
            actions: current_presenter.actions
          )
        end

        def build_form
          Plutonium::Core::UI::Form.new(
            record: resource_record,
            inputs: current_presenter.defined_inputs_for(presentable_attributes)
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plutonium-0.6.2 lib/plutonium/core/controllers/presentable.rb
plutonium-0.6.1 lib/plutonium/core/controllers/presentable.rb
plutonium-0.6.0 lib/plutonium/core/controllers/presentable.rb