2023-04-26 16:21:32 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ReactComponentHelper
|
|
|
|
def react_component(name, props = {}, &block)
|
|
|
|
data = { component: name.to_s.camelcase, props: Oj.dump(props) }
|
|
|
|
if block.nil?
|
|
|
|
div_tag_with_data(data)
|
|
|
|
else
|
|
|
|
content_tag(:div, data: data, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def react_admin_component(name, props = {})
|
2023-06-02 13:00:27 +00:00
|
|
|
data = { 'admin-component': name.to_s.camelcase, props: Oj.dump(props) }
|
2023-04-26 16:21:32 +00:00
|
|
|
div_tag_with_data(data)
|
|
|
|
end
|
|
|
|
|
2024-02-06 13:18:37 +00:00
|
|
|
def serialized_media_attachments(media_attachments)
|
|
|
|
media_attachments.map { |attachment| serialized_attachment(attachment) }
|
|
|
|
end
|
|
|
|
|
2023-04-26 16:21:32 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def div_tag_with_data(data)
|
|
|
|
content_tag(:div, nil, data: data)
|
|
|
|
end
|
2024-02-06 13:18:37 +00:00
|
|
|
|
|
|
|
def serialized_attachment(attachment)
|
|
|
|
ActiveModelSerializers::SerializableResource.new(
|
|
|
|
attachment,
|
|
|
|
serializer: REST::MediaAttachmentSerializer
|
|
|
|
).as_json
|
|
|
|
end
|
2023-04-26 16:21:32 +00:00
|
|
|
end
|