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