New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ActionText extensiblibility #40308
Improve ActionText extensiblibility #40308
Conversation
The prose changes introduced here were done in tandem with the implementation changes, which is to say that I'm very open to feedback on how to provide better ActionText guidance. |
e100198
to
790c464
Compare
df65a22
to
2797d0f
Compare
2797d0f
to
192b790
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In documentation changes, I think ActionText
-> Action Text
because Rails components should have space in between the words. Refer: https://guides.rubyonrails.org/api_documentation_guidelines.html#wording
(known as blobs). On installation, Action Text will copy over a partial to | ||
`app/views/active_storage/blobs/_blob.html.erb`, which you can specialize. | ||
|
||
### Rendering attachments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome part. I always wanted to document this as currently their is no way anyone would know how to process and list attachments. Thank you @seanpdoyle
@@ -81,7 +81,7 @@ class Message < ApplicationRecord | |||
end | |||
``` | |||
|
|||
Note that you don't need to add a `content` field to your `messages` table. | |||
**Note:** you don't need to add a `content` field to your `messages` table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of field
saying database column content
sounds more readable to me. Please ignore if that doesn't sound okay to you. :)
This is great. There a few other |
dbc75dc
to
a358294
Compare
Thanks for the review @georgeclaghorn. I've pushed up those Are there other documentation changes we'd need to make as well? |
a358294
to
3bd09c1
Compare
aa11a4e
to
0d68477
Compare
0d68477
to
8349ee6
Compare
8349ee6
to
4900642
Compare
@@ -47,6 +47,9 @@ def create_actiontext_files | |||
|
|||
copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb", | |||
"app/views/active_storage/blobs/_blob.html.erb" | |||
|
|||
copy_file "#{GEM_ROOT}/app/views/layouts/action_text/contents/_content.html.erb", | |||
"app/views/layouts/action_text/contents/_content.html.erb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@georgeclaghorn I've pushed up a change to copy over the layout as part of rails generate action_text:install
.
4900642
to
ab400c9
Compare
e72e24b
to
95e1808
Compare
95e1808
to
23614b3
Compare
Extensible layout --- Expose how we render the HTML _surrounding_ rich text content as an extensible `layouts/action_text/contents/_content.html.erb` template to encourage user-land customizations, while retaining private API control over how the rich text itself is rendered by moving the `#render_action_text_content` helper invocation to the `action_text/contents/_content.html.erb` partial. Extensible Attachable `#to_attachable_partial_path` --- When an application declares a canonical partial for a record, there is no way to override which partial is used when transformed to Rich Text. For example, a default `Person < ApplicationRecord` instance returns `"people/person"` from calls to `#to_partial_path`, resulting in the `app/views/people/_person.html.erb` partial being rendered. Prior to this change, when encountering an `<action-text-attachment sgid="...">` element, ActionText retrieved the corresponding `Attachable` instance (usually an `ActiveRecord::Base` instance) and transformed it to rich text HTML by rendering the partial that corresponds to its `#to_partial_path`. This proposed change instead invokes `Attachable#to_attachable_partial_path`. By default, `#to_attachable_partial_path` is an alias for `#to_partial_path`. Guides --- Extend the `guides/action_text_overview` document to describe how to customize these templates, and to better illustrate how ActionText::Attachable instances are rendered into HTML.
23614b3
to
3500571
Compare
@seanpdoyle is something needed for these changes to become visible? The source is correct: https://github.com/rails/rails/blob/master/guides/source/action_text_overview.md But the website still shows the previous version (no section "Rendering Rich Text content"): https://edgeguides.rubyonrails.org/action_text_overview.html |
I'm not sure, I don't think I've had a guides change merged before. Any ideas @rafaelfranca? |
Are these changes not in 6.1.4.1 or is something wrong with my gem installation because looking inside the gem, the changes are not there. I can't imagine they have been sitting for almost a year and never making it to a new version. |
Extensible layout
Expose how we render the HTML surrounding rich text content as an
extensible
layouts/action_text/contents/_content.html.erb
template toencourage user-land customizations, while retaining private API control
over how the rich text itself is rendered by moving the
#render_action_text_content
helper invocation to theaction_text/contents/_content.html.erb
partial.Extensible Attachable
#to_attachable_partial_path
When an application declares a canonical partial for a record, there is
no way to override which partial is used when transformed to Rich Text.
For example, a default
Person < ApplicationRecord
instance returns"people/person"
from calls to#to_partial_path
, resulting in theapp/views/people/_person.html.erb
partial being rendered.Prior to this change, when encountering an
<action-text-attachment sgid="...">
element, ActionText retrieved the correspondingAttachable
instance (usually anActiveRecord::Base
instance) andtransformed it to rich text HTML by rendering the partial that
corresponds to its
#to_partial_path
.This proposed change instead invokes
Attachable#to_attachable_partial_path
. By default,#to_attachable_partial_path
is an alias for#to_partial_path
.Guides
Extend the
guides/action_text_overview
document todescribe how to customize these templates, and to better illustrate how
ActionText::Attachable instances are rendered into HTML.