Sha256: de734657cb27d7848984d58343783913e4dcb891f41221d0f0233e0f57827ed5

Contents?: true

Size: 899 Bytes

Versions: 17

Compression:

Stored size: 899 Bytes

Contents

module Coco
  class PresentedComponent < ViewComponent::Base
    include Coco::ComponentsHelper

    attr_accessor :subject

    def render?
      !subject.nil?
    end

    class << self
      # Allow initializing PresentedComponent instances by
      # optionally passing the subject as the first argument.
      # Ensures presented components can still be rendered using
      # ViewComponent's `.with_collection` method.
      #
      # Example.new(example_model, **opts)
      def new(subject = :none, **kwargs)
        if subject == :none
          subject = kwargs.fetch(collection_parameter.to_sym) do
            raise ArgumentError, "Presented components require a subject to be provided when initializing"
          end
        end

        instance = kwargs.any? ? super(subject, **kwargs) : super(subject)
        instance.subject = subject
        instance
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
coveragebook_components-0.19.0 app/components/coco/presented_component.rb
coveragebook_components-0.18.8 app/components/coco/presented_component.rb
coveragebook_components-0.18.7 app/components/coco/presented_component.rb
coveragebook_components-0.18.0 app/components/coco/presented_component.rb
coveragebook_components-0.17.7 app/components/coco/presented_component.rb
coveragebook_components-0.17.6 app/components/coco/presented_component.rb
coveragebook_components-0.17.5 app/components/coco/presented_component.rb
coveragebook_components-0.17.4 app/components/coco/presented_component.rb
coveragebook_components-0.17.3 app/components/coco/presented_component.rb
coveragebook_components-0.17.2 app/components/coco/presented_component.rb
coveragebook_components-0.17.1 app/components/coco/presented_component.rb
coveragebook_components-0.17.0 app/components/coco/presented_component.rb
coveragebook_components-0.16.0 app/components/coco/presented_component.rb
coveragebook_components-0.15.0 app/components/coco/presented_component.rb
coveragebook_components-0.14.0 app/components/coco/presented_component.rb
coveragebook_components-0.13.1 app/components/coco/presented_component.rb
coveragebook_components-0.13.0 app/components/coco/presented_component.rb