Class: Maglev::Content::CollectionItem

Inherits:
Base
  • Object
show all
Defined in:
app/components/maglev/content/collection_item.rb

Instance Attribute Summary

Attributes inherited from Base

#content, #scope, #setting

Instance Method Summary collapse

Methods inherited from Base

#asset_host, #dom_data, #initialize, #tag_data, #tag_id

Constructor Details

This class inherits a constructor from Maglev::Content::Base

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/components/maglev/content/collection_item.rb', line 6

def exists?
  item.present?
end

#itemObject



14
15
16
# File 'app/components/maglev/content/collection_item.rb', line 14

def item
  (content || {})[:item]
end

#tag(view_context, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/components/maglev/content/collection_item.rb', line 18

def tag(view_context, options = {}, &block)
  return unless item && block_given?

  view_context.tag.public_send(
    options.delete(:html_tag)&.to_sym || :div,
    view_context.capture(item, &block),
    **{ data: (options.delete(:data) || {}).merge(tag_data) }.merge(options)
  )
end

#to_sObject



10
11
12
# File 'app/components/maglev/content/collection_item.rb', line 10

def to_s
  item.inspect
end