Class: Coco::PresentedComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Coco::PresentedComponent
- Includes:
- ComponentsHelper
- Defined in:
- app/components/coco/presented_component.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
-
.new(subject = :none, **kwargs) ⇒ Object
Allow initializing PresentedComponent instances by optionally passing the subject as the first argument.
Instance Method Summary collapse
Methods included from ComponentsHelper
#coco_avatar, #coco_badge, #coco_button, #coco_button_group, #coco_button_to, #coco_color_picker_button, #coco_component, #coco_confirm_button, #coco_dropdown, #coco_embed, #coco_fields, #coco_form_for, #coco_form_with, #coco_icon, #coco_image, #coco_image_picker_button, #coco_layout_picker_button, #coco_link, #coco_link_to, #coco_menu, #coco_menu_button, #coco_menu_item, #coco_modal, #coco_modal_canvas, #coco_modal_dialog, #coco_modal_lightbox, #coco_notice, #coco_option_bar, #coco_page, #coco_pager_button, #coco_panel, #coco_placeholder, #coco_popover, #coco_prose, #coco_seamless_textarea, #coco_snackbar, #coco_spacer, #coco_stack, #coco_stamp, #coco_svg, #coco_system_banner, #coco_tabs, #coco_tag, #coco_toast, #coco_toolbar, #coco_tooltip, #resolve_component
Instance Attribute Details
#subject ⇒ Object
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 : super(subject) instance.subject = subject instance end |
Instance Method Details
#render? ⇒ Boolean
7 8 9 |
# File 'app/components/coco/presented_component.rb', line 7 def render? !subject.nil? end |