123456789_123456789_123456789_123456789_123456789_

Class: ActionText::TrixAttachment

Relationships & Source Files
Inherits: Object
Defined in: actiontext/lib/action_text/trix_attachment.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(node) ⇒ TrixAttachment

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 51

def initialize(node)
  @node = node
end

Class Method Details

.from_attributes(attributes)

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 19

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

Instance Attribute Details

#node (readonly)

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 49

attr_reader :node

Instance Method Details

#attributes

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 55

def attributes
  @attributes ||= attachment_attributes.merge(composed_attributes).slice(*ATTRIBUTES)
end

#to_html

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 59

def to_html
  ActionText::HtmlConversion.node_to_html(node)
end

#to_s

[ GitHub ]

  
# File 'actiontext/lib/action_text/trix_attachment.rb', line 63

def to_s
  to_html
end