Class: Coco::PresentedComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ComponentHelper
Defined in:
app/components/coco/presented_component.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ComponentHelper

#coco_component, #resolve_component

Methods included from AppHelper

#coco_button, #coco_button_group, #coco_color_picker_button, #coco_confirm_button, #coco_dropdown_button, #coco_fields, #coco_form_button, #coco_form_for, #coco_form_with, #coco_image_picker_button, #coco_layout_picker_button, #coco_link, #coco_menu_button, #coco_notice, #coco_seamless_textarea, #coco_snackbar, #coco_system_banner, #coco_toast, #coco_toolbar

Methods included from BookHelper

#coco_editable_slide, #coco_media_slide

Methods included from BaseHelper

#coco_embed, #coco_icon, #coco_image, #coco_placeholder, #coco_svg, #coco_tag

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



5
6
7
# File 'app/components/coco/presented_component.rb', line 5

def subject
  @subject
end

Class Method Details

.new(subject = :none, **kwargs) ⇒ Object

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)



18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/coco/presented_component.rb', line 18

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

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/components/coco/presented_component.rb', line 7

def render?
  !subject.nil?
end