Skip to content

Commit d6d57ae

Browse files
committed
Document ActionText::Attachable [ci-skip]
1 parent 533161a commit d6d57ae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

actiontext/lib/action_text/attachable.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
# frozen_string_literal: true
22

33
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]
416
module Attachable
517
extend ActiveSupport::Concern
618

719
LOCATOR_NAME = "attachable"
820

921
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
1029
def from_node(node)
1130
if attachable = attachable_from_sgid(node["sgid"])
1231
attachable

0 commit comments

Comments
 (0)