actiontext 7.1.3.4 → 7.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actiontext might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -95
  3. data/app/helpers/action_text/content_helper.rb +2 -0
  4. data/app/helpers/action_text/tag_helper.rb +38 -28
  5. data/app/models/action_text/encrypted_rich_text.rb +2 -2
  6. data/app/models/action_text/record.rb +2 -0
  7. data/app/models/action_text/rich_text.rb +58 -26
  8. data/db/migrate/20180528164100_create_action_text_tables.rb +1 -1
  9. data/lib/action_text/attachable.rb +35 -33
  10. data/lib/action_text/attachables/content_attachment.rb +2 -0
  11. data/lib/action_text/attachables/missing_attachable.rb +2 -0
  12. data/lib/action_text/attachables/remote_image.rb +2 -0
  13. data/lib/action_text/attachment.rb +27 -25
  14. data/lib/action_text/attachment_gallery.rb +2 -0
  15. data/lib/action_text/attachments/caching.rb +2 -0
  16. data/lib/action_text/attachments/minification.rb +2 -0
  17. data/lib/action_text/attachments/trix_conversion.rb +2 -0
  18. data/lib/action_text/attribute.rb +36 -22
  19. data/lib/action_text/content.rb +46 -26
  20. data/lib/action_text/deprecator.rb +2 -0
  21. data/lib/action_text/encryption.rb +2 -0
  22. data/lib/action_text/engine.rb +2 -0
  23. data/lib/action_text/fixture_set.rb +34 -34
  24. data/lib/action_text/fragment.rb +4 -0
  25. data/lib/action_text/gem_version.rb +6 -4
  26. data/lib/action_text/html_conversion.rb +2 -0
  27. data/lib/action_text/plain_text_conversion.rb +2 -0
  28. data/lib/action_text/rendering.rb +2 -0
  29. data/lib/action_text/serialization.rb +2 -0
  30. data/lib/action_text/system_test_helper.rb +20 -17
  31. data/lib/action_text/trix_attachment.rb +2 -0
  32. data/lib/action_text/version.rb +3 -1
  33. data/lib/action_text.rb +1 -1
  34. data/lib/generators/action_text/install/install_generator.rb +10 -3
  35. data/lib/rails/generators/test_unit/install_generator.rb +2 -0
  36. data/package.json +2 -2
  37. metadata +15 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d51a41ff03b550ac428a52ce89ee785539d2ac0b386c5597f4c06b763070d054
4
- data.tar.gz: 85028cdc38e4448c321e17190924c602f7bd940588307ef42206c7e0842ba31a
3
+ metadata.gz: '038e42b13d583f9db670ee6dc104ef802f4c9c77920037b38a95fb28e9a625b4'
4
+ data.tar.gz: 31ee1edbf17eebb4ff96b83a4af0a296d80ea55244c5301e940f939ecaee4921
5
5
  SHA512:
6
- metadata.gz: 417dec3ad3e197b566e52b5b42356481d6a5f54e1a792b5f16c7eeaa45137b2a4bdeeb32e83fd890d884fc60864e7d6062ebe25115710a40de06df3c93812c95
7
- data.tar.gz: ab1691bf97b79a8f2b644b6bf324c06fc663fd8ca2ba4641a906fcf7062a4c4acb4103b25b405561fc21e81198ce7b7541a9d02921d137ae14de6eb75d01b1c7
6
+ metadata.gz: d8b926161af97aa1f62f17f6c775b045184af218452fb38243f0ca58713af6b313a51d6015651c8c9199ea148bf0ba80a825d0fb2e4cb9c17b1edc863efb6dc1
7
+ data.tar.gz: 2be0ecf3329ce40edf0e365082efb993c053a6d359877bc75ea9b953d569ed85730def05e950f03ffb644375004c4795067838a3240d4b6bfd102e622288c958
data/CHANGELOG.md CHANGED
@@ -1,34 +1,38 @@
1
- ## Rails 7.1.3.4 (June 04, 2024) ##
1
+ ## Rails 7.2.0.beta2 (June 04, 2024) ##
2
2
 
3
3
  * Sanitize ActionText HTML ContentAttachment in Trix edit view
4
4
  [CVE-2024-32464]
5
5
 
6
6
 
7
- ## Rails 7.1.3.3 (May 16, 2024) ##
7
+ ## Rails 7.2.0.beta1 (May 29, 2024) ##
8
8
 
9
- * Upgrade Trix to 1.3.2 to fix [CVE-2024-34341](https://github.com/basecamp/trix/security/advisories/GHSA-qjqp-xr96-cj99).
9
+ * Use `includes` instead of `eager_load` for `with_all_rich_text`.
10
10
 
11
- *Rafael Mendonça França*
11
+ *Petrik de Heus*
12
12
 
13
+ * Delegate `ActionText::Content#deconstruct` to `Nokogiri::XML::DocumentFragment#elements`.
13
14
 
14
- ## Rails 7.1.3.2 (February 21, 2024) ##
15
+ ```ruby
16
+ content = ActionText::Content.new <<~HTML
17
+ <h1>Hello, world</h1>
15
18
 
16
- * No changes.
19
+ <div>The body</div>
20
+ HTML
17
21
 
22
+ content => [h1, div]
18
23
 
19
- ## Rails 7.1.3.1 (February 21, 2024) ##
24
+ assert_pattern { h1 => { content: "Hello, world" } }
25
+ assert_pattern { div => { content: "The body" } }
26
+ ```
20
27
 
21
- * No changes.
22
-
23
-
24
- ## Rails 7.1.3 (January 16, 2024) ##
25
-
26
- * No changes.
28
+ *Sean Doyle*
27
29
 
30
+ * Fix all Action Text database related models to respect
31
+ `ActiveRecord::Base.table_name_prefix` configuration.
28
32
 
29
- ## Rails 7.1.2 (November 10, 2023) ##
33
+ *Chedli Bourguiba*
30
34
 
31
- * Compile ESM package that can be used directly in the browser as `actiontext.esm.js`.
35
+ * Compile ESM package that can be used directly in the browser as actiontext.esm.js
32
36
 
33
37
  *Matias Grunberg*
34
38
 
@@ -36,7 +40,7 @@
36
40
 
37
41
  *Matias Grunberg*
38
42
 
39
- * Upgrade Trix to 2.0.7.
43
+ * Upgrade Trix to 2.0.7
40
44
 
41
45
  *Hartley McGuire*
42
46
 
@@ -44,82 +48,4 @@
44
48
 
45
49
  *Hartley McGuire*
46
50
 
47
-
48
- ## Rails 7.1.1 (October 11, 2023) ##
49
-
50
- * No changes.
51
-
52
-
53
- ## Rails 7.1.0 (October 05, 2023) ##
54
-
55
- * No changes.
56
-
57
-
58
- ## Rails 7.1.0.rc2 (October 01, 2023) ##
59
-
60
- * No changes.
61
-
62
-
63
- ## Rails 7.1.0.rc1 (September 27, 2023) ##
64
-
65
- * No changes.
66
-
67
-
68
- ## Rails 7.1.0.beta1 (September 13, 2023) ##
69
-
70
- * Use `Rails::HTML5::SafeListSanitizer` by default in the Rails 7.1 configuration if it is
71
- supported.
72
-
73
- Action Text's sanitizer can be configured by setting
74
- `config.action_text.sanitizer_vendor`. Supported values are `Rails::HTML4::Sanitizer` or
75
- `Rails::HTML5::Sanitizer`.
76
-
77
- The Rails 7.1 configuration will set this to `Rails::HTML5::Sanitizer` when it is supported, and
78
- fall back to `Rails::HTML4::Sanitizer`. Previous configurations default to
79
- `Rails::HTML4::Sanitizer`.
80
-
81
- As a result of this change, the defaults for `ActionText::ContentHelper.allowed_tags` and
82
- `.allowed_attributes` are applied at runtime, so the value of these attributes is now 'nil'
83
- unless set by the application. You may call `sanitizer_allowed_tags` or
84
- `sanitizer_allowed_attributes` to inspect the tags and attributes being allowed by the
85
- sanitizer.
86
-
87
- *Mike Dalessio*
88
-
89
- * Attachables now can override default attachment missing template.
90
-
91
- When rendering Action Text attachments where the underlying attachable model has
92
- been removed, a fallback template is used. You now can override this template on
93
- a per-model basis. For example, you could render a placeholder image for a file
94
- attachment or the text "Deleted User" for a User attachment.
95
-
96
- *Matt Swanson*, *Joel Drapper*
97
-
98
- * Update bundled Trix version from `1.3.1` to `2.0.4`.
99
-
100
- *Sarah Ridge*, *Sean Doyle*
101
-
102
- * Apply `field_error_proc` to `rich_text_area` form fields.
103
-
104
- *Kaíque Kandy Koga*
105
-
106
- * Action Text attachment URLs rendered in a background job (a la Turbo
107
- Streams) now use `Rails.application.default_url_options` and
108
- `Rails.application.config.force_ssl` instead of `http://example.org`.
109
-
110
- *Jonathan Hefner*
111
-
112
- * Support `strict_loading:` option for `has_rich_text` declaration
113
-
114
- *Sean Doyle*
115
-
116
- * Update ContentAttachment so that it can encapsulate arbitrary HTML content in a document.
117
-
118
- *Jamis Buck*
119
-
120
- * Fix an issue that caused the content layout to render multiple times when a
121
- rich_text field was updated.
122
-
123
- *Jacob Herrington*
124
-
125
- Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/actiontext/CHANGELOG.md) for previous changes.
51
+ Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actiontext/CHANGELOG.md) for previous changes.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rails-html-sanitizer"
4
6
 
5
7
  module ActionText
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/object/try"
4
6
  require "action_view/helpers/tags/placeholderable"
5
7
 
@@ -7,20 +9,24 @@ module ActionText
7
9
  module TagHelper
8
10
  cattr_accessor(:id, instance_accessor: false) { 0 }
9
11
 
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")`.
12
23
  #
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>.
18
24
  #
19
- # ==== Example
25
+ # #### Example
20
26
  #
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>
24
30
  def rich_text_area_tag(name, value = nil, options = {})
25
31
  options = options.symbolize_keys
26
32
  form = options.delete(:form)
@@ -56,23 +62,27 @@ module ActionView::Helpers
56
62
  end
57
63
 
58
64
  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")`.
61
76
  #
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>.
67
77
  #
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>
72
82
  #
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>
76
86
  def rich_text_area(object_name, method, options = {})
77
87
  Tags::ActionText.new(object_name, method, self, options).render
78
88
  end
@@ -81,9 +91,9 @@ module ActionView::Helpers
81
91
  class FormBuilder
82
92
  # Wraps ActionView::Helpers::FormHelper#rich_text_area for form builders:
83
93
  #
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 %>
87
97
  #
88
98
  # Please refer to the documentation of the base helper for details.
89
99
  def rich_text_area(method, options = {})
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  class EncryptedRichText < RichText
5
- self.table_name = "action_text_rich_texts"
6
-
7
7
  encrypts :body
8
8
  end
9
9
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  class Record < ActiveRecord::Base # :nodoc:
5
7
  self.abstract_class = true
@@ -1,55 +1,87 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
- # = Action Text \RichText
6
+ # # Action Text RichText
5
7
  #
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.
10
13
  #
11
- # class Message < ActiveRecord::Base
12
- # has_rich_text :content
13
- # end
14
+ # class Message < ActiveRecord::Base
15
+ # has_rich_text :content
16
+ # end
14
17
  #
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!"
19
22
  #
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"
20
27
  class RichText < Record
21
- self.table_name = "action_text_rich_texts"
28
+ ##
29
+ # :method: to_s
30
+ #
31
+ # Safely transforms RichText into an HTML String.
32
+ #
33
+ # message = Message.create!(content: "<h1>Funny times!</h1>")
34
+ # message.content.to_s # => "<h1>Funny times!</h1>"
35
+ #
36
+ # message = Message.create!(content: "<div onclick='action()'>safe<script>unsafe</script></div>")
37
+ # message.content.to_s # => "<div>safeunsafe</div>"
22
38
 
23
39
  serialize :body, coder: ActionText::Content
24
40
  delegate :to_s, :nil?, to: :body
25
41
 
42
+ ##
43
+ # :method: record
44
+ #
45
+ # Returns the associated record.
26
46
  belongs_to :record, polymorphic: true, touch: true
47
+
48
+ ##
49
+ # :method: embeds
50
+ #
51
+ # Returns the `ActiveStorage::Blob`s of the embedded files.
27
52
  has_many_attached :embeds
28
53
 
29
54
  before_save do
30
55
  self.embeds = body.attachables.grep(ActiveStorage::Blob).uniq if body.present?
31
56
  end
32
57
 
33
- # Returns the +body+ attribute as plain text with all HTML tags removed.
58
+ # Returns a plain-text version of the markup contained by the `body` attribute,
59
+ # with tags removed but HTML entities encoded.
60
+ #
61
+ # message = Message.create!(content: "<h1>Funny times!</h1>")
62
+ # message.content.to_plain_text # => "Funny times!"
63
+ #
64
+ # NOTE: that the returned string is not HTML safe and should not be rendered in
65
+ # browsers.
34
66
  #
35
- # message = Message.create!(content: "<h1>Funny times!</h1>")
36
- # message.content.to_plain_text # => "Funny times!"
67
+ # message = Message.create!(content: "&lt;script&gt;alert()&lt;/script&gt;")
68
+ # message.content.to_plain_text # => "<script>alert()</script>"
37
69
  def to_plain_text
38
70
  body&.to_plain_text.to_s
39
71
  end
40
72
 
41
- # Returns the +body+ attribute in a format that makes it editable in the Trix
73
+ # Returns the `body` attribute in a format that makes it editable in the Trix
42
74
  # editor. Previews of attachments are rendered inline.
43
75
  #
44
- # content = "<h1>Funny Times!</h1><figure data-trix-attachment='{\"sgid\":\"..."\}'></figure>"
45
- # message = Message.create!(content: content)
46
- # message.content.to_trix_html # =>
47
- # # <div class="trix-content">
48
- # # <h1>Funny times!</h1>
49
- # # <figure data-trix-attachment='{\"sgid\":\"..."\}'>
50
- # # <img src="http://example.org/rails/active_storage/.../funny.jpg">
51
- # # </figure>
52
- # # </div>
76
+ # content = "<h1>Funny Times!</h1><figure data-trix-attachment='{\"sgid\":\"..."\}'></figure>"
77
+ # message = Message.create!(content: content)
78
+ # message.content.to_trix_html # =>
79
+ # # <div class="trix-content">
80
+ # # <h1>Funny times!</h1>
81
+ # # <figure data-trix-attachment='{\"sgid\":\"..."\}'>
82
+ # # <img src="http://example.org/rails/active_storage/.../funny.jpg">
83
+ # # </figure>
84
+ # # </div>
53
85
  def to_trix_html
54
86
  body&.to_trix_html
55
87
  end
@@ -20,6 +20,6 @@ class CreateActionTextTables < ActiveRecord::Migration[6.0]
20
20
  setting = config.options[config.orm][:primary_key_type]
21
21
  primary_key_type = setting || :primary_key
22
22
  foreign_key_type = setting || :bigint
23
- [primary_key_type, foreign_key_type]
23
+ [ primary_key_type, foreign_key_type ]
24
24
  end
25
25
  end
@@ -1,31 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
- # = Action Text \Attachable
6
+ # # Action Text Attachable
5
7
  #
6
8
  # Include this module to make a record attachable to an ActionText::Content.
7
9
  #
8
- # class Person < ApplicationRecord
9
- # include ActionText::Attachable
10
- # end
10
+ # class Person < ApplicationRecord
11
+ # include ActionText::Attachable
12
+ # end
11
13
  #
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]
16
18
  module Attachable
17
19
  extend ActiveSupport::Concern
18
20
 
19
21
  LOCATOR_NAME = "attachable"
20
22
 
21
23
  class << self
22
- # Extracts the +ActionText::Attachable+ from the attachment HTML node:
24
+ # Extracts the `ActionText::Attachable` from the attachment HTML node:
23
25
  #
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
29
31
  def from_node(node)
30
32
  if attachable = attachable_from_sgid(node["sgid"])
31
33
  attachable
@@ -57,23 +59,23 @@ module ActionText
57
59
  ActionText::Attachable.from_attachable_sgid(sgid, only: self)
58
60
  end
59
61
 
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".
62
64
  #
63
65
  # Override to render a different partial:
64
66
  #
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
68
71
  # end
69
- # end
70
72
  def to_missing_attachable_partial_path
71
73
  ActionText::Attachables::MissingAttachable::DEFAULT_PARTIAL_PATH
72
74
  end
73
75
  end
74
76
 
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.
77
79
  def attachable_sgid
78
80
  to_sgid(expires_in: nil, for: LOCATOR_NAME).to_s
79
81
  end
@@ -98,30 +100,30 @@ module ActionText
98
100
  false
99
101
  end
100
102
 
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`.
103
105
  #
104
106
  # Override to render a different partial:
105
107
  #
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
109
112
  # end
110
- # end
111
113
  def to_trix_content_attachment_partial_path
112
114
  to_partial_path
113
115
  end
114
116
 
115
117
  # 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`.
117
119
  #
118
120
  # Override to render a different partial:
119
121
  #
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
123
126
  # end
124
- # end
125
127
  def to_attachable_partial_path
126
128
  to_partial_path
127
129
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  module Attachables
5
7
  class ContentAttachment # :nodoc:
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  module Attachables
5
7
  class MissingAttachable
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  module Attachables
5
7
  class RemoteImage
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/object/try"
4
6
 
5
7
  module ActionText
6
- # = Action Text \Attachment
8
+ # # Action Text Attachment
7
9
  #
8
10
  # Attachments serialize attachables to HTML or plain text.
9
11
  #
10
- # class Person < ApplicationRecord
11
- # include ActionText::Attachable
12
- # end
12
+ # class Person < ApplicationRecord
13
+ # include ActionText::Attachable
14
+ # end
13
15
  #
14
- # attachable = Person.create! name: "Javan"
15
- # attachment = ActionText::Attachment.from_attachable(attachable)
16
- # attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk..."
16
+ # attachable = Person.create! name: "Javan"
17
+ # attachment = ActionText::Attachment.from_attachable(attachable)
18
+ # attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk..."
17
19
  class Attachment
18
20
  include Attachments::TrixConversion, Attachments::Minification, Attachments::Caching
19
21
 
@@ -82,29 +84,29 @@ module ActionText
82
84
 
83
85
  # Converts the attachment to plain text.
84
86
  #
85
- # attachable = ActiveStorage::Blob.find_by filename: "racecar.jpg"
86
- # attachment = ActionText::Attachment.from_attachable(attachable)
87
- # attachment.to_plain_text # => "[racecar.jpg]"
87
+ # attachable = ActiveStorage::Blob.find_by filename: "racecar.jpg"
88
+ # attachment = ActionText::Attachment.from_attachable(attachable)
89
+ # attachment.to_plain_text # => "[racecar.jpg]"
88
90
  #
89
- # Use the +caption+ when set:
91
+ # Use the `caption` when set:
90
92
  #
91
- # attachment = ActionText::Attachment.from_attachable(attachable, caption: "Vroom vroom")
92
- # attachment.to_plain_text # => "[Vroom vroom]"
93
+ # attachment = ActionText::Attachment.from_attachable(attachable, caption: "Vroom vroom")
94
+ # attachment.to_plain_text # => "[Vroom vroom]"
93
95
  #
94
96
  # The presentation can be overridden by implementing the
95
- # +attachable_plain_text_representation+ method:
97
+ # `attachable_plain_text_representation` method:
96
98
  #
97
- # class Person < ApplicationRecord
98
- # include ActionText::Attachable
99
+ # class Person < ApplicationRecord
100
+ # include ActionText::Attachable
99
101
  #
100
- # def attachable_plain_text_representation
101
- # "[#{name}]"
102
+ # def attachable_plain_text_representation
103
+ # "[#{name}]"
104
+ # end
102
105
  # end
103
- # end
104
106
  #
105
- # attachable = Person.create! name: "Javan"
106
- # attachment = ActionText::Attachment.from_attachable(attachable)
107
- # attachment.to_plain_text # => "[Javan]"
107
+ # attachable = Person.create! name: "Javan"
108
+ # attachment = ActionText::Attachment.from_attachable(attachable)
109
+ # attachment.to_plain_text # => "[Javan]"
108
110
  def to_plain_text
109
111
  if respond_to?(:attachable_plain_text_representation)
110
112
  attachable_plain_text_representation(caption)
@@ -115,9 +117,9 @@ module ActionText
115
117
 
116
118
  # Converts the attachment to HTML.
117
119
  #
118
- # attachable = Person.create! name: "Javan"
119
- # attachment = ActionText::Attachment.from_attachable(attachable)
120
- # attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk...
120
+ # attachable = Person.create! name: "Javan"
121
+ # attachment = ActionText::Attachment.from_attachable(attachable)
122
+ # attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk...
121
123
  def to_html
122
124
  HtmlConversion.node_to_html(node)
123
125
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionText
4
6
  class AttachmentGallery
5
7
  include ActiveModel::Model