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.8.0.beta.3 app/components/coco/presented_component.rb
coveragebook_components-0.8.0.beta.2 app/components/coco/presented_component.rb
coveragebook_components-0.8.0.beta.1 app/components/coco/presented_component.rb
coveragebook_components-0.7.10 app/components/coco/presented_component.rb
coveragebook_components-0.7.9 app/components/coco/presented_component.rb
coveragebook_components-0.7.8 app/components/coco/presented_component.rb
coveragebook_components-0.7.7 app/components/coco/presented_component.rb
coveragebook_components-0.7.6 app/components/coco/presented_component.rb
coveragebook_components-0.7.5 app/components/coco/presented_component.rb
coveragebook_components-0.7.4 app/components/coco/presented_component.rb
coveragebook_components-0.7.3 app/components/coco/presented_component.rb
coveragebook_components-0.7.2 app/components/coco/presented_component.rb
coveragebook_components-0.7.1 app/components/coco/presented_component.rb
coveragebook_components-0.7.0 app/components/coco/presented_component.rb
coveragebook_components-0.6.5 app/components/coco/presented_component.rb
coveragebook_components-0.6.4 app/components/coco/presented_component.rb
coveragebook_components-0.6.3 app/components/coco/presented_component.rb
coveragebook_components-0.6.2 app/components/coco/presented_component.rb
coveragebook_components-0.6.1 app/components/coco/presented_component.rb
coveragebook_components-0.6.0 app/components/coco/presented_component.rb