Class: ActionText::Attachment
Overview
Action Text Attachment
Attachments serialize attachables to HTML or plain text.
class Person < ApplicationRecord
include ActionText::Attachable
end
attachable = Person.create! name: "Javan"
attachment = ActionText::Attachment.from_attachable(attachable)
attachment.to_html
Constant Summary
collapse
- ATTRIBUTES =
%w( sgid content-type url href filename filesize width height previewable presentation caption content )
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#to_trix_attachment
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
#cache_key
Constructor Details
#initialize(node, attachable) ⇒ Attachment
Returns a new instance of Attachment.
66
67
68
69
|
# File 'actiontext/lib/action_text/attachment.rb', line 66
def initialize(node, attachable)
@node = node
@attachable = attachable
end
|
Instance Attribute Details
#attachable ⇒ Object
Returns the value of attribute attachable.
61
62
63
|
# File 'actiontext/lib/action_text/attachment.rb', line 61
def attachable
@attachable
end
|
Returns the value of attribute node.
61
62
63
|
# File 'actiontext/lib/action_text/attachment.rb', line 61
def node
@node
end
|
Class Method Details
.fragment_by_canonicalizing_attachments(content) ⇒ Object
25
26
27
|
# File 'actiontext/lib/action_text/attachment.rb', line 25
def fragment_by_canonicalizing_attachments(content)
fragment_by_minifying_attachments(fragment_by_converting_trix_attachments(content))
end
|
.from_attachable(attachable, attributes = {}) ⇒ Object
37
38
39
40
41
|
# File 'actiontext/lib/action_text/attachment.rb', line 37
def from_attachable(attachable, attributes = {})
if node = node_from_attributes(attachable.to_rich_text_attributes(attributes))
new(node, attachable)
end
end
|
.from_attachables(attachables) ⇒ Object
33
34
35
|
# File 'actiontext/lib/action_text/attachment.rb', line 33
def from_attachables(attachables)
Array(attachables).filter_map { |attachable| from_attachable(attachable) }
end
|
.from_attributes(attributes, attachable = nil) ⇒ Object
43
44
45
46
47
|
# File 'actiontext/lib/action_text/attachment.rb', line 43
def from_attributes(attributes, attachable = nil)
if node = node_from_attributes(attributes)
from_node(node, attachable)
end
end
|
.from_node(node, attachable = nil) ⇒ Object
29
30
31
|
# File 'actiontext/lib/action_text/attachment.rb', line 29
def from_node(node, attachable = nil)
new(node, attachable || ActionText::Attachable.from_node(node))
end
|
Instance Method Details
71
72
73
|
# File 'actiontext/lib/action_text/attachment.rb', line 71
def caption
node_attributes["caption"].presence
end
|
#full_attributes ⇒ Object
75
76
77
|
# File 'actiontext/lib/action_text/attachment.rb', line 75
def full_attributes
node_attributes.merge(attachable_attributes).merge(sgid_attributes)
end
|
129
130
131
|
# File 'actiontext/lib/action_text/attachment.rb', line 129
def inspect
"#<#{self.class.name} attachable=#{attachable.inspect}>"
end
|
#to_plain_text ⇒ Object
108
109
110
111
112
113
114
|
# File 'actiontext/lib/action_text/attachment.rb', line 108
def to_plain_text
if respond_to?(:attachable_plain_text_representation)
attachable_plain_text_representation(caption)
else
caption.to_s
end
end
|
125
126
127
|
# File 'actiontext/lib/action_text/attachment.rb', line 125
def to_s
to_html
end
|
#with_full_attributes ⇒ Object
79
80
81
|
# File 'actiontext/lib/action_text/attachment.rb', line 79
def with_full_attributes
self.class.from_attributes(full_attributes, attachable)
end
|