Skip to content

Commit 1ecac5b

Browse files
committed
./tools/rdoc-to-md --only=actiontext -a
1 parent 195d801 commit 1ecac5b

31 files changed

+316
-238
lines changed

actiontext/app/helpers/action_text/content_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
require "rails-html-sanitizer"
46

57
module ActionText

actiontext/app/helpers/action_text/tag_helper.rb

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
require "active_support/core_ext/object/try"
46
require "action_view/helpers/tags/placeholderable"
57

68
module ActionText
79
module TagHelper
810
cattr_accessor(:id, instance_accessor: false) { 0 }
911

10-
# Returns a +trix-editor+ tag that instantiates the Trix JavaScript editor as well as a hidden field
11-
# that Trix will write to on changes, so the content will be sent on form submissions.
12+
# Returns a `trix-editor` tag that instantiates the Trix JavaScript editor as
13+
# well as a hidden field that Trix will write to on changes, so the content will
14+
# be sent on form submissions.
15+
#
16+
# #### Options
17+
# * `:class` - Defaults to "trix-content" so that default styles will be
18+
# applied. Setting this to a different value will prevent default styles
19+
# from being applied.
20+
# * `[:data][:direct_upload_url]` - Defaults to `rails_direct_uploads_url`.
21+
# * `[:data][:blob_url_template]` - Defaults to
22+
# `rails_service_blob_url(":signed_id", ":filename")`.
1223
#
13-
# ==== Options
14-
# * <tt>:class</tt> - Defaults to "trix-content" so that default styles will be applied.
15-
# Setting this to a different value will prevent default styles from being applied.
16-
# * <tt>[:data][:direct_upload_url]</tt> - Defaults to +rails_direct_uploads_url+.
17-
# * <tt>[:data][:blob_url_template]</tt> - Defaults to <tt>rails_service_blob_url(":signed_id", ":filename")</tt>.
1824
#
19-
# ==== Example
25+
# #### Example
2026
#
21-
# rich_text_area_tag "content", message.content
22-
# # <input type="hidden" name="content" id="trix_input_post_1">
23-
# # <trix-editor id="content" input="trix_input_post_1" class="trix-content" ...></trix-editor>
27+
# rich_text_area_tag "content", message.content
28+
# # <input type="hidden" name="content" id="trix_input_post_1">
29+
# # <trix-editor id="content" input="trix_input_post_1" class="trix-content" ...></trix-editor>
2430
def rich_text_area_tag(name, value = nil, options = {})
2531
options = options.symbolize_keys
2632
form = options.delete(:form)
@@ -56,23 +62,27 @@ def render
5662
end
5763

5864
module FormHelper
59-
# Returns a +trix-editor+ tag that instantiates the Trix JavaScript editor as well as a hidden field
60-
# that Trix will write to on changes, so the content will be sent on form submissions.
65+
# Returns a `trix-editor` tag that instantiates the Trix JavaScript editor as
66+
# well as a hidden field that Trix will write to on changes, so the content will
67+
# be sent on form submissions.
68+
#
69+
# #### Options
70+
# * `:class` - Defaults to "trix-content" which ensures default styling is
71+
# applied.
72+
# * `:value` - Adds a default value to the HTML input tag.
73+
# * `[:data][:direct_upload_url]` - Defaults to `rails_direct_uploads_url`.
74+
# * `[:data][:blob_url_template]` - Defaults to
75+
# `rails_service_blob_url(":signed_id", ":filename")`.
6176
#
62-
# ==== Options
63-
# * <tt>:class</tt> - Defaults to "trix-content" which ensures default styling is applied.
64-
# * <tt>:value</tt> - Adds a default value to the HTML input tag.
65-
# * <tt>[:data][:direct_upload_url]</tt> - Defaults to +rails_direct_uploads_url+.
66-
# * <tt>[:data][:blob_url_template]</tt> - Defaults to <tt>rails_service_blob_url(":signed_id", ":filename")</tt>.
6777
#
68-
# ==== Example
69-
# rich_text_area :message, :content
70-
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1">
71-
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
78+
# #### Example
79+
# rich_text_area :message, :content
80+
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1">
81+
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
7282
#
73-
# rich_text_area :message, :content, value: "<h1>Default message</h1>"
74-
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1" value="<h1>Default message</h1>">
75-
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
83+
# rich_text_area :message, :content, value: "<h1>Default message</h1>"
84+
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1" value="<h1>Default message</h1>">
85+
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
7686
def rich_text_area(object_name, method, options = {})
7787
Tags::ActionText.new(object_name, method, self, options).render
7888
end
@@ -81,9 +91,9 @@ def rich_text_area(object_name, method, options = {})
8191
class FormBuilder
8292
# Wraps ActionView::Helpers::FormHelper#rich_text_area for form builders:
8393
#
84-
# <%= form_with model: @message do |f| %>
85-
# <%= f.rich_text_area :content %>
86-
# <% end %>
94+
# <%= form_with model: @message do |f| %>
95+
# <%= f.rich_text_area :content %>
96+
# <% end %>
8797
#
8898
# Please refer to the documentation of the base helper for details.
8999
def rich_text_area(method, options = {})

actiontext/app/models/action_text/encrypted_rich_text.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
46
class EncryptedRichText < RichText
57
encrypts :body

actiontext/app/models/action_text/record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
46
class Record < ActiveRecord::Base # :nodoc:
57
self.abstract_class = true

actiontext/app/models/action_text/rich_text.rb

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
4-
# = Action Text \RichText
6+
# # Action Text RichText
57
#
6-
# The RichText record holds the content produced by the Trix editor in a serialized +body+ attribute.
7-
# It also holds all the references to the embedded files, which are stored using Active Storage.
8-
# This record is then associated with the Active Record model the application desires to have
9-
# rich text content using the +has_rich_text+ class method.
8+
# The RichText record holds the content produced by the Trix editor in a
9+
# serialized `body` attribute. It also holds all the references to the embedded
10+
# files, which are stored using Active Storage. This record is then associated
11+
# with the Active Record model the application desires to have rich text content
12+
# using the `has_rich_text` class method.
1013
#
11-
# class Message < ActiveRecord::Base
12-
# has_rich_text :content
13-
# end
14+
# class Message < ActiveRecord::Base
15+
# has_rich_text :content
16+
# end
1417
#
15-
# message = Message.create!(content: "<h1>Funny times!</h1>")
16-
# message.content #=> #<ActionText::RichText....
17-
# message.content.to_s # => "<h1>Funny times!</h1>"
18-
# message.content.to_plain_text # => "Funny times!"
18+
# message = Message.create!(content: "<h1>Funny times!</h1>")
19+
# message.content #=> #<ActionText::RichText....
20+
# message.content.to_s # => "<h1>Funny times!</h1>"
21+
# message.content.to_plain_text # => "Funny times!"
1922
#
20-
# message = Message.create!(content: "<div onclick='action()'>safe<script>unsafe</script></div>")
21-
# message.content #=> #<ActionText::RichText....
22-
# message.content.to_s # => "<div>safeunsafe</div>"
23-
# message.content.to_plain_text # => "safeunsafe"
23+
# message = Message.create!(content: "<div onclick='action()'>safe<script>unsafe</script></div>")
24+
# message.content #=> #<ActionText::RichText....
25+
# message.content.to_s # => "<div>safeunsafe</div>"
26+
# message.content.to_plain_text # => "safeunsafe"
2427
class RichText < Record
2528
##
2629
# :method: to_s
2730
#
2831
# Safely transforms RichText into an HTML String.
2932
#
30-
# message = Message.create!(content: "<h1>Funny times!</h1>")
31-
# message.content.to_s # => "<h1>Funny times!</h1>"
33+
# message = Message.create!(content: "<h1>Funny times!</h1>")
34+
# message.content.to_s # => "<h1>Funny times!</h1>"
3235
#
33-
# message = Message.create!(content: "<div onclick='action()'>safe<script>unsafe</script></div>")
34-
# message.content.to_s # => "<div>safeunsafe</div>"
36+
# message = Message.create!(content: "<div onclick='action()'>safe<script>unsafe</script></div>")
37+
# message.content.to_s # => "<div>safeunsafe</div>"
3538

3639
serialize :body, coder: ActionText::Content
3740
delegate :to_s, :nil?, to: :body
@@ -43,32 +46,33 @@ class RichText < Record
4346
self.embeds = body.attachables.grep(ActiveStorage::Blob).uniq if body.present?
4447
end
4548

46-
# Returns a plain-text version of the markup contained by the +body+ attribute,
49+
# Returns a plain-text version of the markup contained by the `body` attribute,
4750
# with tags removed but HTML entities encoded.
4851
#
49-
# message = Message.create!(content: "<h1>Funny times!</h1>")
50-
# message.content.to_plain_text # => "Funny times!"
52+
# message = Message.create!(content: "<h1>Funny times!</h1>")
53+
# message.content.to_plain_text # => "Funny times!"
5154
#
52-
# NOTE: that the returned string is not HTML safe and should not be rendered in browsers.
55+
# NOTE: that the returned string is not HTML safe and should not be rendered in
56+
# browsers.
5357
#
54-
# message = Message.create!(content: "&lt;script&gt;alert()&lt;/script&gt;")
55-
# message.content.to_plain_text # => "<script>alert()</script>"
58+
# message = Message.create!(content: "&lt;script&gt;alert()&lt;/script&gt;")
59+
# message.content.to_plain_text # => "<script>alert()</script>"
5660
def to_plain_text
5761
body&.to_plain_text.to_s
5862
end
5963

60-
# Returns the +body+ attribute in a format that makes it editable in the Trix
64+
# Returns the `body` attribute in a format that makes it editable in the Trix
6165
# editor. Previews of attachments are rendered inline.
6266
#
63-
# content = "<h1>Funny Times!</h1><figure data-trix-attachment='{\"sgid\":\"..."\}'></figure>"
64-
# message = Message.create!(content: content)
65-
# message.content.to_trix_html # =>
66-
# # <div class="trix-content">
67-
# # <h1>Funny times!</h1>
68-
# # <figure data-trix-attachment='{\"sgid\":\"..."\}'>
69-
# # <img src="http://example.org/rails/active_storage/.../funny.jpg">
70-
# # </figure>
71-
# # </div>
67+
# content = "<h1>Funny Times!</h1><figure data-trix-attachment='{\"sgid\":\"..."\}'></figure>"
68+
# message = Message.create!(content: content)
69+
# message.content.to_trix_html # =>
70+
# # <div class="trix-content">
71+
# # <h1>Funny times!</h1>
72+
# # <figure data-trix-attachment='{\"sgid\":\"..."\}'>
73+
# # <img src="http://example.org/rails/active_storage/.../funny.jpg">
74+
# # </figure>
75+
# # </div>
7276
def to_trix_html
7377
body&.to_trix_html
7478
end

actiontext/lib/action_text/attachable.rb

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

3+
# :markup: markdown
4+
35
module ActionText
4-
# = Action Text \Attachable
6+
# # Action Text Attachable
57
#
68
# Include this module to make a record attachable to an ActionText::Content.
79
#
8-
# class Person < ApplicationRecord
9-
# include ActionText::Attachable
10-
# end
10+
# class Person < ApplicationRecord
11+
# include ActionText::Attachable
12+
# end
1113
#
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]
14+
# person = Person.create! name: "Javan"
15+
# html = %Q(<action-text-attachment sgid="#{person.attachable_sgid}"></action-text-attachment>)
16+
# content = ActionText::Content.new(html)
17+
# content.attachables # => [person]
1618
module Attachable
1719
extend ActiveSupport::Concern
1820

1921
LOCATOR_NAME = "attachable"
2022

2123
class << self
22-
# Extracts the +ActionText::Attachable+ from the attachment HTML node:
24+
# Extracts the `ActionText::Attachable` from the attachment HTML node:
2325
#
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
26+
# person = Person.create! name: "Javan"
27+
# html = %Q(<action-text-attachment sgid="#{person.attachable_sgid}"></action-text-attachment>)
28+
# fragment = ActionText::Fragment.wrap(html)
29+
# attachment_node = fragment.find_all(ActionText::Attachment.tag_name).first
30+
# ActionText::Attachable.from_node(attachment_node) # => person
2931
def from_node(node)
3032
if attachable = attachable_from_sgid(node["sgid"])
3133
attachable
@@ -57,23 +59,23 @@ def from_attachable_sgid(sgid)
5759
ActionText::Attachable.from_attachable_sgid(sgid, only: self)
5860
end
5961

60-
# Returns the path to the partial that is used for rendering missing attachables.
61-
# Defaults to "action_text/attachables/missing_attachable".
62+
# Returns the path to the partial that is used for rendering missing
63+
# attachables. Defaults to "action_text/attachables/missing_attachable".
6264
#
6365
# Override to render a different partial:
6466
#
65-
# class User < ApplicationRecord
66-
# def self.to_missing_attachable_partial_path
67-
# "users/missing_attachable"
67+
# class User < ApplicationRecord
68+
# def self.to_missing_attachable_partial_path
69+
# "users/missing_attachable"
70+
# end
6871
# end
69-
# end
7072
def to_missing_attachable_partial_path
7173
ActionText::Attachables::MissingAttachable::DEFAULT_PARTIAL_PATH
7274
end
7375
end
7476

75-
# Returns the Signed Global ID for the attachable. The purpose of the ID is
76-
# set to 'attachable' so it can't be reused for other purposes.
77+
# Returns the Signed Global ID for the attachable. The purpose of the ID is set
78+
# to 'attachable' so it can't be reused for other purposes.
7779
def attachable_sgid
7880
to_sgid(expires_in: nil, for: LOCATOR_NAME).to_s
7981
end
@@ -98,30 +100,30 @@ def previewable_attachable?
98100
false
99101
end
100102

101-
# Returns the path to the partial that is used for rendering the attachable
102-
# in Trix. Defaults to +to_partial_path+.
103+
# Returns the path to the partial that is used for rendering the attachable in
104+
# Trix. Defaults to `to_partial_path`.
103105
#
104106
# Override to render a different partial:
105107
#
106-
# class User < ApplicationRecord
107-
# def to_trix_content_attachment_partial_path
108-
# "users/trix_content_attachment"
108+
# class User < ApplicationRecord
109+
# def to_trix_content_attachment_partial_path
110+
# "users/trix_content_attachment"
111+
# end
109112
# end
110-
# end
111113
def to_trix_content_attachment_partial_path
112114
to_partial_path
113115
end
114116

115117
# Returns the path to the partial that is used for rendering the attachable.
116-
# Defaults to +to_partial_path+.
118+
# Defaults to `to_partial_path`.
117119
#
118120
# Override to render a different partial:
119121
#
120-
# class User < ApplicationRecord
121-
# def to_attachable_partial_path
122-
# "users/attachable"
122+
# class User < ApplicationRecord
123+
# def to_attachable_partial_path
124+
# "users/attachable"
125+
# end
123126
# end
124-
# end
125127
def to_attachable_partial_path
126128
to_partial_path
127129
end

actiontext/lib/action_text/attachables/content_attachment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
46
module Attachables
57
class ContentAttachment # :nodoc:

actiontext/lib/action_text/attachables/missing_attachable.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
46
module Attachables
57
class MissingAttachable

actiontext/lib/action_text/attachables/remote_image.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# :markup: markdown
4+
35
module ActionText
46
module Attachables
57
class RemoteImage

0 commit comments

Comments
 (0)