File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
actiontext/lib/action_text Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module ActionText
4
+ # = Action Text Attachable
5
+ #
6
+ # Include this module to make a record attachable to an <tt>ActionText::Content</tt>.
7
+ #
8
+ # class Person < ApplicationRecord
9
+ # include ActionText::Attachable
10
+ # end
11
+ #
12
+ # person = Person.create! name: "Javan"
13
+ # html = %Q(<action-text-attachment sgid="#{person.attachable_sgid}"></action-text-attachment>)
14
+ # content = ActionText::Content.new(html)
15
+ # content.attachables # => [person]
4
16
module Attachable
5
17
extend ActiveSupport ::Concern
6
18
7
19
LOCATOR_NAME = "attachable"
8
20
9
21
class << self
22
+ # Extracts the <tt>ActionText::Attachable</tt> from the attachment HTML node:
23
+ #
24
+ # person = Person.create! name: "Javan"
25
+ # html = %Q(<action-text-attachment sgid="#{person.attachable_sgid}"></action-text-attachment>)
26
+ # fragment = ActionText::Fragment.wrap(html)
27
+ # attachment_node = fragment.find_all(ActionText::Attachment.tag_name).first
28
+ # ActionText::Attachable.from_node(attachment_node) # => person
10
29
def from_node ( node )
11
30
if attachable = attachable_from_sgid ( node [ "sgid" ] )
12
31
attachable
You can’t perform that action at this time.
0 commit comments