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