Class: ActionMosaico::Attachment
- Inherits:
-
Object
- Object
- ActionMosaico::Attachment
- Includes:
- ActionMosaico::Attachments::Caching, ActionMosaico::Attachments::Minification, ActionMosaico::Attachments::TrixConversion
- Defined in:
- lib/action_mosaico/attachment.rb
Constant Summary collapse
- ATTRIBUTES =
%w[sgid content-type url href filename filesize width height previewable presentation caption].freeze
Instance Attribute Summary collapse
-
#attachable ⇒ Object
readonly
Returns the value of attribute attachable.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
- .fragment_by_canonicalizing_attachments(content) ⇒ Object
- .from_attachable(attachable, attributes = {}) ⇒ Object
- .from_attachables(attachables) ⇒ Object
- .from_attributes(attributes, attachable = nil) ⇒ Object
- .from_node(node, attachable = nil) ⇒ Object
Instance Method Summary collapse
- #caption ⇒ Object
- #full_attributes ⇒ Object
-
#initialize(node, attachable) ⇒ Attachment
constructor
A new instance of Attachment.
- #inspect ⇒ Object
- #to_html ⇒ Object
- #to_plain_text ⇒ Object
- #to_s ⇒ Object
- #with_full_attributes ⇒ Object
Methods included from ActionMosaico::Attachments::TrixConversion
Methods included from ActionMosaico::Attachments::Caching
Constructor Details
#initialize(node, attachable) ⇒ Attachment
Returns a new instance of Attachment.
58 59 60 61 |
# File 'lib/action_mosaico/attachment.rb', line 58 def initialize(node, attachable) @node = node @attachable = attachable end |
Instance Attribute Details
#attachable ⇒ Object (readonly)
Returns the value of attribute attachable.
53 54 55 |
# File 'lib/action_mosaico/attachment.rb', line 53 def attachable @attachable end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
53 54 55 |
# File 'lib/action_mosaico/attachment.rb', line 53 def node @node end |
Class Method Details
.fragment_by_canonicalizing_attachments(content) ⇒ Object
16 17 18 |
# File 'lib/action_mosaico/attachment.rb', line 16 def (content) ((content)) end |
.from_attachable(attachable, attributes = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/action_mosaico/attachment.rb', line 28 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
24 25 26 |
# File 'lib/action_mosaico/attachment.rb', line 24 def from_attachables(attachables) Array(attachables).filter_map { |attachable| from_attachable(attachable) } end |
.from_attributes(attributes, attachable = nil) ⇒ Object
34 35 36 37 38 |
# File 'lib/action_mosaico/attachment.rb', line 34 def from_attributes(attributes, attachable = nil) if node = node_from_attributes(attributes) from_node(node, attachable) end end |
.from_node(node, attachable = nil) ⇒ Object
20 21 22 |
# File 'lib/action_mosaico/attachment.rb', line 20 def from_node(node, attachable = nil) new(node, attachable || ActionMosaico::Attachable.from_node(node)) end |
Instance Method Details
#caption ⇒ Object
63 64 65 |
# File 'lib/action_mosaico/attachment.rb', line 63 def node_attributes['caption'].presence end |
#full_attributes ⇒ Object
67 68 69 |
# File 'lib/action_mosaico/attachment.rb', line 67 def full_attributes node_attributes.merge(attachable_attributes).merge(sgid_attributes) end |
#inspect ⇒ Object
91 92 93 |
# File 'lib/action_mosaico/attachment.rb', line 91 def inspect "#<#{self.class.name} attachable=#{attachable.inspect}>" end |
#to_html ⇒ Object
83 84 85 |
# File 'lib/action_mosaico/attachment.rb', line 83 def to_html HtmlConversion.node_to_html(node) end |
#to_plain_text ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/action_mosaico/attachment.rb', line 75 def to_plain_text if respond_to?(:attachable_plain_text_representation) attachable_plain_text_representation() else .to_s end end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/action_mosaico/attachment.rb', line 87 def to_s to_html end |
#with_full_attributes ⇒ Object
71 72 73 |
# File 'lib/action_mosaico/attachment.rb', line 71 def with_full_attributes self.class.from_attributes(full_attributes, attachable) end |