Method: ActionText::TrixAttachment.from_attributes

Defined in:
actiontext/lib/action_text/trix_attachment.rb

.from_attributes(attributes) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'actiontext/lib/action_text/trix_attachment.rb', line 21

def from_attributes(attributes)
  attributes = process_attributes(attributes)

  trix_attachment_attributes = attributes.except(*COMPOSED_ATTRIBUTES)
  trix_attributes = attributes.slice(*COMPOSED_ATTRIBUTES)

  node = ActionText::HtmlConversion.create_element(TAG_NAME)
  node["data-trix-attachment"] = JSON.generate(trix_attachment_attributes)
  node["data-trix-attributes"] = JSON.generate(trix_attributes) if trix_attributes.any?

  new(node)
end