Class: ActionText::TrixAttachment
- Defined in:
- actiontext/lib/action_text/trix_attachment.rb
Constant Summary collapse
- TAG_NAME =
"figure"
- SELECTOR =
"[data-trix-attachment]"
- COMPOSED_ATTRIBUTES =
%w( caption presentation )
- ATTRIBUTES =
%w( sgid contentType url href filename filesize width height previewable content ) + COMPOSED_ATTRIBUTES
- ATTRIBUTE_TYPES =
{ "previewable" => ->(value) { value.to_s == "true" }, "filesize" => ->(value) { Integer(value.to_s, exception: false) || value }, "width" => ->(value) { Integer(value.to_s, exception: false) }, "height" => ->(value) { Integer(value.to_s, exception: false) }, :default => ->(value) { value.to_s } }
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(node) ⇒ TrixAttachment
constructor
A new instance of TrixAttachment.
- #to_html ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(node) ⇒ TrixAttachment
Returns a new instance of TrixAttachment.
51 52 53 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 51 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node
49 50 51 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 49 def node @node end |
Class Method Details
.from_attributes(attributes) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 19 def from_attributes(attributes) attributes = process_attributes(attributes) = attributes.except(*COMPOSED_ATTRIBUTES) trix_attributes = attributes.slice(*COMPOSED_ATTRIBUTES) node = ActionText::HtmlConversion.create_element(TAG_NAME) node["data-trix-attachment"] = JSON.generate() node["data-trix-attributes"] = JSON.generate(trix_attributes) if trix_attributes.any? new(node) end |
Instance Method Details
#attributes ⇒ Object
55 56 57 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 55 def attributes @attributes ||= .merge(composed_attributes).slice(*ATTRIBUTES) end |
#to_html ⇒ Object
59 60 61 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 59 def to_html ActionText::HtmlConversion.node_to_html(node) end |
#to_s ⇒ Object
63 64 65 |
# File 'actiontext/lib/action_text/trix_attachment.rb', line 63 def to_s to_html end |