Sha256: 8fdf63a679e0623ba4691f782ec8a77aa986320f14466ee7548d1caff4508470

Contents?: true

Size: 898 Bytes

Versions: 48

Compression:

Stored size: 898 Bytes

Contents

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

    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

48 entries across 48 versions & 1 rubygems

Version Path
coveragebook_components-0.12.2 app/components/coco/presented_component.rb
coveragebook_components-0.12.1 app/components/coco/presented_component.rb
coveragebook_components-0.12.0 app/components/coco/presented_component.rb
coveragebook_components-0.11.0 app/components/coco/presented_component.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/presented_component.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/presented_component.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/presented_component.rb
coveragebook_components-0.10.0 app/components/coco/presented_component.rb
coveragebook_components-0.9.1 app/components/coco/presented_component.rb
coveragebook_components-0.9.0 app/components/coco/presented_component.rb
coveragebook_components-0.8.9 app/components/coco/presented_component.rb
coveragebook_components-0.8.8 app/components/coco/presented_component.rb
coveragebook_components-0.8.7 app/components/coco/presented_component.rb
coveragebook_components-0.8.6 app/components/coco/presented_component.rb
coveragebook_components-0.8.5 app/components/coco/presented_component.rb
coveragebook_components-0.8.4 app/components/coco/presented_component.rb
coveragebook_components-0.8.3 app/components/coco/presented_component.rb
coveragebook_components-0.8.2 app/components/coco/presented_component.rb
coveragebook_components-0.8.1 app/components/coco/presented_component.rb
coveragebook_components-0.8.0 app/components/coco/presented_component.rb