actiontext 7.1.5.2 → 8.1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -132
- data/app/assets/javascripts/actiontext.esm.js +114 -14
- data/app/assets/javascripts/actiontext.js +120 -17
- data/app/helpers/action_text/content_helper.rb +2 -0
- data/app/helpers/action_text/tag_helper.rb +63 -37
- data/app/javascript/actiontext/attachment_upload.js +78 -12
- data/app/javascript/actiontext/index.js +10 -1
- data/app/models/action_text/encrypted_rich_text.rb +2 -2
- data/app/models/action_text/record.rb +2 -0
- data/app/models/action_text/rich_text.rb +62 -27
- data/db/migrate/20180528164100_create_action_text_tables.rb +1 -1
- data/lib/action_text/attachable.rb +35 -33
- data/lib/action_text/attachables/content_attachment.rb +2 -0
- data/lib/action_text/attachables/missing_attachable.rb +2 -0
- data/lib/action_text/attachables/remote_image.rb +2 -0
- data/lib/action_text/attachment.rb +27 -25
- data/lib/action_text/attachment_gallery.rb +2 -0
- data/lib/action_text/attachments/caching.rb +2 -0
- data/lib/action_text/attachments/minification.rb +2 -0
- data/lib/action_text/attachments/trix_conversion.rb +2 -0
- data/lib/action_text/attribute.rb +61 -27
- data/lib/action_text/content.rb +49 -28
- data/lib/action_text/deprecator.rb +2 -0
- data/lib/action_text/encryption.rb +2 -0
- data/lib/action_text/engine.rb +7 -2
- data/lib/action_text/fixture_set.rb +35 -35
- data/lib/action_text/fragment.rb +4 -0
- data/lib/action_text/gem_version.rb +6 -4
- data/lib/action_text/html_conversion.rb +2 -0
- data/lib/action_text/plain_text_conversion.rb +65 -28
- data/lib/action_text/rendering.rb +2 -1
- data/lib/action_text/serialization.rb +2 -0
- data/lib/action_text/system_test_helper.rb +52 -33
- data/lib/action_text/trix_attachment.rb +2 -0
- data/lib/action_text/version.rb +3 -1
- data/lib/generators/action_text/install/install_generator.rb +4 -21
- data/lib/generators/action_text/install/templates/actiontext.css +414 -5
- data/lib/rails/generators/test_unit/install_generator.rb +2 -0
- data/package.json +3 -2
- metadata +28 -16
- data/app/assets/javascripts/trix.js +0 -13720
- data/app/assets/stylesheets/trix.css +0 -412
|
@@ -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
|
-
#
|
|
8
|
+
# # Action Text Attachment
|
|
7
9
|
#
|
|
8
10
|
# Attachments serialize attachables to HTML or plain text.
|
|
9
11
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
12
|
+
# class Person < ApplicationRecord
|
|
13
|
+
# include ActionText::Attachable
|
|
14
|
+
# end
|
|
13
15
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
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
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
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
|
|
91
|
+
# Use the `caption` when set:
|
|
90
92
|
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
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
|
-
#
|
|
97
|
+
# `attachable_plain_text_representation` method:
|
|
96
98
|
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
+
# class Person < ApplicationRecord
|
|
100
|
+
# include ActionText::Attachable
|
|
99
101
|
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
+
# def attachable_plain_text_representation
|
|
103
|
+
# "[#{name}]"
|
|
104
|
+
# end
|
|
102
105
|
# end
|
|
103
|
-
# end
|
|
104
106
|
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
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
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
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,40 +1,56 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionText
|
|
4
6
|
module Attribute
|
|
5
7
|
extend ActiveSupport::Concern
|
|
6
8
|
|
|
7
9
|
class_methods do
|
|
8
|
-
# Provides access to a dependent RichText model that holds the body and
|
|
9
|
-
#
|
|
10
|
+
# Provides access to a dependent RichText model that holds the body and
|
|
11
|
+
# attachments for a single named rich text attribute. This dependent attribute
|
|
12
|
+
# is lazily instantiated and will be auto-saved when it's been changed. Example:
|
|
13
|
+
#
|
|
14
|
+
# class Message < ActiveRecord::Base
|
|
15
|
+
# has_rich_text :content
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# message = Message.create!(content: "<h1>Funny times!</h1>")
|
|
19
|
+
# message.content? #=> true
|
|
20
|
+
# message.content.to_s # => "<h1>Funny times!</h1>"
|
|
21
|
+
# message.content.to_plain_text # => "Funny times!"
|
|
22
|
+
#
|
|
23
|
+
# The dependent RichText model will also automatically process attachments links
|
|
24
|
+
# as sent via the Trix-powered editor. These attachments are associated with the
|
|
25
|
+
# RichText model using Active Storage.
|
|
10
26
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
# end
|
|
27
|
+
# If you wish to preload the dependent RichText model, you can use the named
|
|
28
|
+
# scope:
|
|
14
29
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
# message.content.to_plain_text # => "Funny times!"
|
|
30
|
+
# Message.all.with_rich_text_content # Avoids N+1 queries when you just want the body, not the attachments.
|
|
31
|
+
# Message.all.with_rich_text_content_and_embeds # Avoids N+1 queries when you just want the body and attachments.
|
|
32
|
+
# Message.all.with_all_rich_text # Loads all rich text associations.
|
|
19
33
|
#
|
|
20
|
-
#
|
|
21
|
-
# These attachments are associated with the RichText model using Active Storage.
|
|
34
|
+
# #### Options
|
|
22
35
|
#
|
|
23
|
-
#
|
|
36
|
+
# * `:encrypted` - Pass true to encrypt the rich text attribute. The
|
|
37
|
+
# encryption will be non-deterministic. See
|
|
38
|
+
# `ActiveRecord::Encryption::EncryptableRecord.encrypts`. Default: false.
|
|
24
39
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
40
|
+
# * `:strict_loading` - Pass true to force strict loading. When omitted,
|
|
41
|
+
# `strict_loading:` will be set to the value of the
|
|
42
|
+
# `strict_loading_by_default` class attribute (false by default).
|
|
28
43
|
#
|
|
29
|
-
#
|
|
44
|
+
# * `:store_if_blank` - Pass false to not create RichText records with empty values,
|
|
45
|
+
# if a blank value is provided. Default: true.
|
|
30
46
|
#
|
|
31
|
-
# * <tt>:encrypted</tt> - Pass true to encrypt the rich text attribute. The encryption will be non-deterministic. See
|
|
32
|
-
# +ActiveRecord::Encryption::EncryptableRecord.encrypts+. Default: false.
|
|
33
47
|
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
|
|
48
|
+
# Note: Action Text relies on polymorphic associations, which in turn store
|
|
49
|
+
# class names in the database. When renaming classes that use `has_rich_text`,
|
|
50
|
+
# make sure to also update the class names in the
|
|
51
|
+
# `action_text_rich_texts.record_type` polymorphic type column of the
|
|
52
|
+
# corresponding rows.
|
|
53
|
+
def has_rich_text(name, encrypted: false, strict_loading: strict_loading_by_default, store_if_blank: true)
|
|
38
54
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
39
55
|
def #{name}
|
|
40
56
|
rich_text_#{name} || build_rich_text_#{name}
|
|
@@ -43,12 +59,29 @@ module ActionText
|
|
|
43
59
|
def #{name}?
|
|
44
60
|
rich_text_#{name}.present?
|
|
45
61
|
end
|
|
46
|
-
|
|
47
|
-
def #{name}=(body)
|
|
48
|
-
self.#{name}.body = body
|
|
49
|
-
end
|
|
50
62
|
CODE
|
|
51
63
|
|
|
64
|
+
if store_if_blank
|
|
65
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
66
|
+
def #{name}=(body)
|
|
67
|
+
self.#{name}.body = body
|
|
68
|
+
end
|
|
69
|
+
CODE
|
|
70
|
+
else
|
|
71
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
72
|
+
def #{name}=(body)
|
|
73
|
+
if body.present?
|
|
74
|
+
self.#{name}.body = body
|
|
75
|
+
else
|
|
76
|
+
if #{name}?
|
|
77
|
+
self.#{name}.body = body
|
|
78
|
+
self.#{name}.mark_for_destruction
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
CODE
|
|
83
|
+
end
|
|
84
|
+
|
|
52
85
|
rich_text_class_name = encrypted ? "ActionText::EncryptedRichText" : "ActionText::RichText"
|
|
53
86
|
has_one :"rich_text_#{name}", -> { where(name: name) },
|
|
54
87
|
class_name: rich_text_class_name, as: :record, inverse_of: :record, autosave: true, dependent: :destroy,
|
|
@@ -60,9 +93,10 @@ module ActionText
|
|
|
60
93
|
|
|
61
94
|
# Eager load all dependent RichText models in bulk.
|
|
62
95
|
def with_all_rich_text
|
|
63
|
-
|
|
96
|
+
includes(rich_text_association_names)
|
|
64
97
|
end
|
|
65
98
|
|
|
99
|
+
# Returns the names of all rich text associations.
|
|
66
100
|
def rich_text_association_names
|
|
67
101
|
reflect_on_all_associations(:has_one).collect(&:name).select { |n| n.start_with?("rich_text_") }
|
|
68
102
|
end
|
data/lib/action_text/content.rb
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionText
|
|
4
|
-
#
|
|
6
|
+
# # Action Text Content
|
|
5
7
|
#
|
|
6
|
-
# The
|
|
8
|
+
# The `ActionText::Content` class wraps an HTML fragment to add support for
|
|
7
9
|
# parsing, rendering and serialization. It can be used to extract links and
|
|
8
|
-
# attachments, convert the fragment to plain text, or serialize the fragment
|
|
9
|
-
#
|
|
10
|
+
# attachments, convert the fragment to plain text, or serialize the fragment to
|
|
11
|
+
# the database.
|
|
10
12
|
#
|
|
11
13
|
# The ActionText::RichText record serializes the `body` attribute as
|
|
12
|
-
#
|
|
14
|
+
# `ActionText::Content`.
|
|
13
15
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
16
|
+
# class Message < ActiveRecord::Base
|
|
17
|
+
# has_rich_text :content
|
|
18
|
+
# end
|
|
17
19
|
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
20
|
+
# message = Message.create!(content: "<h1>Funny times!</h1>")
|
|
21
|
+
# body = message.content.body # => #<ActionText::Content "<div class=\"trix-conte...">
|
|
22
|
+
# body.to_s # => "<h1>Funny times!</h1>"
|
|
23
|
+
# body.to_plain_text # => "Funny times!"
|
|
22
24
|
class Content
|
|
23
25
|
include Rendering, Serialization, ContentHelper
|
|
24
26
|
|
|
25
27
|
attr_reader :fragment
|
|
26
28
|
|
|
29
|
+
delegate :deconstruct, to: :fragment
|
|
27
30
|
delegate :blank?, :empty?, :html_safe, :present?, to: :to_html # Delegating to to_html to avoid including the layout
|
|
28
31
|
|
|
29
32
|
class << self
|
|
@@ -46,19 +49,19 @@ module ActionText
|
|
|
46
49
|
|
|
47
50
|
# Extracts links from the HTML fragment:
|
|
48
51
|
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
+
# html = '<a href="http://example.com/">Example</a>'
|
|
53
|
+
# content = ActionText::Content.new(html)
|
|
54
|
+
# content.links # => ["http://example.com/"]
|
|
52
55
|
def links
|
|
53
56
|
@links ||= fragment.find_all("a[href]").map { |a| a["href"] }.uniq
|
|
54
57
|
end
|
|
55
58
|
|
|
56
|
-
# Extracts
|
|
59
|
+
# Extracts ActionText::Attachment objects from the HTML fragment:
|
|
57
60
|
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
61
|
+
# attachable = ActiveStorage::Blob.first
|
|
62
|
+
# html = %Q(<action-text-attachment sgid="#{attachable.attachable_sgid}" caption="Captioned"></action-text-attachment>)
|
|
63
|
+
# content = ActionText::Content.new(html)
|
|
64
|
+
# content.attachments # => [#<ActionText::Attachment attachable=#<ActiveStorage::Blob...
|
|
62
65
|
def attachments
|
|
63
66
|
@attachments ||= attachment_nodes.map do |node|
|
|
64
67
|
attachment_for_node(node)
|
|
@@ -75,12 +78,12 @@ module ActionText
|
|
|
75
78
|
@gallery_attachments ||= attachment_galleries.flat_map(&:attachments)
|
|
76
79
|
end
|
|
77
80
|
|
|
78
|
-
# Extracts
|
|
81
|
+
# Extracts ActionText::Attachable objects from the HTML fragment:
|
|
79
82
|
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
83
|
+
# attachable = ActiveStorage::Blob.first
|
|
84
|
+
# html = %Q(<action-text-attachment sgid="#{attachable.attachable_sgid}" caption="Captioned"></action-text-attachment>)
|
|
85
|
+
# content = ActionText::Content.new(html)
|
|
86
|
+
# content.attachables # => [attachable]
|
|
84
87
|
def attachables
|
|
85
88
|
@attachables ||= attachment_nodes.map do |node|
|
|
86
89
|
ActionText::Attachable.from_node(node)
|
|
@@ -110,10 +113,21 @@ module ActionText
|
|
|
110
113
|
self.class.new(content, canonicalize: false)
|
|
111
114
|
end
|
|
112
115
|
|
|
113
|
-
# Returns the
|
|
116
|
+
# Returns a plain-text version of the markup contained by the content, with tags
|
|
117
|
+
# removed but HTML entities encoded.
|
|
118
|
+
#
|
|
119
|
+
# content = ActionText::Content.new("<h1>Funny times!</h1>")
|
|
120
|
+
# content.to_plain_text # => "Funny times!"
|
|
121
|
+
#
|
|
122
|
+
# content = ActionText::Content.new("<div onclick='action()'>safe<script>unsafe</script></div>")
|
|
123
|
+
# content.to_plain_text # => "safeunsafe"
|
|
114
124
|
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
125
|
+
# NOTE: that the returned string is not HTML safe and should not be rendered in
|
|
126
|
+
# browsers without additional sanitization.
|
|
127
|
+
#
|
|
128
|
+
# content = ActionText::Content.new("<script>alert()</script>")
|
|
129
|
+
# content.to_plain_text # => "<script>alert()</script>"
|
|
130
|
+
# ActionText::ContentHelper.sanitizer.sanitize(content.to_plain_text) # => ""
|
|
117
131
|
def to_plain_text
|
|
118
132
|
render_attachments(with_full_attributes: false, &:to_plain_text).fragment.to_plain_text
|
|
119
133
|
end
|
|
@@ -134,6 +148,13 @@ module ActionText
|
|
|
134
148
|
"action_text/contents/content"
|
|
135
149
|
end
|
|
136
150
|
|
|
151
|
+
# Safely transforms Content into an HTML String.
|
|
152
|
+
#
|
|
153
|
+
# content = ActionText::Content.new(content: "<h1>Funny times!</h1>")
|
|
154
|
+
# content.to_s # => "<h1>Funny times!</h1>"
|
|
155
|
+
#
|
|
156
|
+
# content = ActionText::Content.new("<div onclick='action()'>safe<script>unsafe</script></div>")
|
|
157
|
+
# content.to_s # => "<div>safeunsafe</div>"
|
|
137
158
|
def to_s
|
|
138
159
|
to_rendered_html_with_layout
|
|
139
160
|
end
|
data/lib/action_text/engine.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
require "rails"
|
|
4
6
|
require "action_controller/railtie"
|
|
5
7
|
require "active_record/railtie"
|
|
6
8
|
require "active_storage/engine"
|
|
7
9
|
|
|
8
10
|
require "action_text"
|
|
11
|
+
require "action_text/trix"
|
|
9
12
|
|
|
10
13
|
module ActionText
|
|
11
14
|
class Engine < Rails::Engine
|
|
@@ -32,7 +35,7 @@ module ActionText
|
|
|
32
35
|
|
|
33
36
|
initializer "action_text.asset" do
|
|
34
37
|
if Rails.application.config.respond_to?(:assets)
|
|
35
|
-
Rails.application.config.assets.precompile += %w( actiontext.js actiontext.esm.js
|
|
38
|
+
Rails.application.config.assets.precompile += %w( actiontext.js actiontext.esm.js )
|
|
36
39
|
end
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -85,7 +88,9 @@ module ActionText
|
|
|
85
88
|
|
|
86
89
|
config.after_initialize do |app|
|
|
87
90
|
if klass = app.config.action_text.sanitizer_vendor
|
|
88
|
-
|
|
91
|
+
ActiveSupport.on_load(:action_view) do
|
|
92
|
+
ActionText::ContentHelper.sanitizer = klass.safe_list_sanitizer.new
|
|
93
|
+
end
|
|
89
94
|
end
|
|
90
95
|
end
|
|
91
96
|
end
|
|
@@ -1,68 +1,68 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionText
|
|
4
|
-
#
|
|
6
|
+
# # Action Text FixtureSet
|
|
5
7
|
#
|
|
6
|
-
# Fixtures are a way of organizing data that you want to test against; in
|
|
7
|
-
#
|
|
8
|
+
# Fixtures are a way of organizing data that you want to test against; in short,
|
|
9
|
+
# sample data.
|
|
8
10
|
#
|
|
9
11
|
# To learn more about fixtures, read the ActiveRecord::FixtureSet documentation.
|
|
10
12
|
#
|
|
11
|
-
#
|
|
13
|
+
# ### YAML
|
|
12
14
|
#
|
|
13
15
|
# Like other Active Record-backed models, ActionText::RichText records inherit
|
|
14
|
-
# from ActiveRecord::Base instances and can therefore be populated by
|
|
15
|
-
# fixtures.
|
|
16
|
+
# from ActiveRecord::Base instances and can therefore be populated by fixtures.
|
|
16
17
|
#
|
|
17
|
-
# Consider an
|
|
18
|
+
# Consider an `Article` class:
|
|
18
19
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
20
|
+
# class Article < ApplicationRecord
|
|
21
|
+
# has_rich_text :content
|
|
22
|
+
# end
|
|
22
23
|
#
|
|
23
|
-
# To declare fixture data for the related
|
|
24
|
-
#
|
|
24
|
+
# To declare fixture data for the related `content`, first declare fixture data
|
|
25
|
+
# for `Article` instances in `test/fixtures/articles.yml`:
|
|
25
26
|
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
27
|
+
# first:
|
|
28
|
+
# title: An Article
|
|
28
29
|
#
|
|
29
30
|
# Then declare the ActionText::RichText fixture data in
|
|
30
|
-
#
|
|
31
|
-
#
|
|
31
|
+
# `test/fixtures/action_text/rich_texts.yml`, making sure to declare each
|
|
32
|
+
# entry's `record:` key as a polymorphic relationship:
|
|
32
33
|
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
34
|
+
# first:
|
|
35
|
+
# record: first (Article)
|
|
36
|
+
# name: content
|
|
37
|
+
# body: <div>Hello, world.</div>
|
|
37
38
|
#
|
|
38
39
|
# When processed, Active Record will insert database records for each fixture
|
|
39
40
|
# entry and will ensure the Action Text relationship is intact.
|
|
40
41
|
class FixtureSet
|
|
41
|
-
# Fixtures support Action Text attachments as part of their
|
|
42
|
-
# HTML.
|
|
42
|
+
# Fixtures support Action Text attachments as part of their `body` HTML.
|
|
43
43
|
#
|
|
44
|
-
#
|
|
44
|
+
# ### Examples
|
|
45
45
|
#
|
|
46
|
-
# For example, consider a second
|
|
47
|
-
#
|
|
46
|
+
# For example, consider a second `Article` fixture declared in
|
|
47
|
+
# `test/fixtures/articles.yml`:
|
|
48
48
|
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
49
|
+
# second:
|
|
50
|
+
# title: Another Article
|
|
51
51
|
#
|
|
52
|
-
# You can attach a mention of
|
|
53
|
-
#
|
|
54
|
-
# in
|
|
52
|
+
# You can attach a mention of `articles(:first)` to `second`'s `content` by
|
|
53
|
+
# embedding a call to `ActionText::FixtureSet.attachment` in the `body:` value
|
|
54
|
+
# in `test/fixtures/action_text/rich_texts.yml`:
|
|
55
55
|
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
56
|
+
# second:
|
|
57
|
+
# record: second (Article)
|
|
58
|
+
# name: content
|
|
59
|
+
# body: <div>Hello, <%= ActionText::FixtureSet.attachment("articles", :first) %></div>
|
|
60
60
|
#
|
|
61
61
|
def self.attachment(fixture_set_name, label, column_type: :integer)
|
|
62
62
|
signed_global_id = ActiveRecord::FixtureSet.signed_global_id fixture_set_name, label,
|
|
63
63
|
column_type: column_type, for: ActionText::Attachable::LOCATOR_NAME
|
|
64
64
|
|
|
65
|
-
%(
|
|
65
|
+
%(<#{Attachment.tag_name} sgid="#{signed_global_id}"></#{Attachment.tag_name}>)
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
end
|
data/lib/action_text/fragment.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionText
|
|
4
6
|
class Fragment
|
|
5
7
|
class << self
|
|
@@ -21,6 +23,8 @@ module ActionText
|
|
|
21
23
|
|
|
22
24
|
attr_reader :source
|
|
23
25
|
|
|
26
|
+
delegate :deconstruct, to: "source.elements"
|
|
27
|
+
|
|
24
28
|
def initialize(source)
|
|
25
29
|
@source = source
|
|
26
30
|
end
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionText
|
|
4
|
-
# Returns the currently loaded version of Action Text as a
|
|
6
|
+
# Returns the currently loaded version of Action Text as a `Gem::Version`.
|
|
5
7
|
def self.gem_version
|
|
6
8
|
Gem::Version.new VERSION::STRING
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
module VERSION
|
|
10
|
-
MAJOR =
|
|
12
|
+
MAJOR = 8
|
|
11
13
|
MINOR = 1
|
|
12
|
-
TINY =
|
|
13
|
-
PRE = "
|
|
14
|
+
TINY = 2
|
|
15
|
+
PRE = "1"
|
|
14
16
|
|
|
15
17
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
|
16
18
|
end
|