Commit Graph

59 Commits

Author SHA1 Message Date
Rafael Mendonça França ce636e9f9f
Action Text documentation in now in Markdown 2024-01-25 20:47:14 +00:00
Petrik de Heus 3c3df4cea3
Merge pull request #50762 from p8/actiontext/document-associations-and-scopes
Document some ActionText methods [ci-skip]
2024-01-25 20:57:58 +01:00
Hartley McGuire 1ecac5b8d3
./tools/rdoc-to-md --only=actiontext -a 2024-01-24 19:08:44 -05:00
Petrik 35ecdefc14 Document some ActionText methods [ci-skip] 2024-01-15 22:21:53 +01:00
Chedli Bourguiba c3b821e6d8 Take AR affixes into account for Action Text database models 2023-12-09 11:05:52 +01:00
Sean Doyle 638c9d5722 Action Text `rich_text_area` code samples [ci skip]
The API documentation for the `rich_text_area` Action View helper
demonstrates how to invoke the helper through a `FormBuilder` instance,
instead of through the `ActionView::Base` instance.

This commit removes the `form.` prefix, and includes examples of calling
the method with an `object_name` positional argument.
2023-12-03 11:40:55 -05:00
Matias Grunberg 2dbcb3df33 fix using actiontext.js in sprocket
actiontext.js is compiled as ESM bundle instead of UMD bundle.
This leads to issues when trying to use ActionText with sprockets because the ESM bundle declares variables like they are scoped to the file but sprockets will see them as scoped globally.
This is a problem, in particular, if you want to mix actiontext with
turbo-rails.

The problem got introduced in https://github.com/rails/rails/pull/46447.
I traced valid compilation back to
https://github.com/rails/rails/pull/42895.

This commit mimic changes made in
https://github.com/rails/rails/pull/42895 to ActiveStorage:
   Retains app/assets/javascripts/actiontext.js as a UMD package for backwards compatibility with
   bundling in the asset pipeline, but also adds app/assets/javascripts/actiontext.esm.js for use
   with ESM via importmap in the browser.
2023-11-07 00:36:53 -03:00
Jonathan Hefner 4dcd6ba8d3 Update .gitattributes for generated JavaScript [ci-skip]
This adds `linguist-generated` and `linguist-vendored` attributes where
appropriate to suppress the files in diffs and exclude the files from
the project's language stats on GitHub.

See https://github.com/github/linguist for more information.
2023-11-05 15:48:08 -06:00
Sean Doyle 591d88aef4 Document Action Text Sanitization
Add documentation for `ActionText::RichText#to_s` and
`ActionText::Content#to_s` that demonstrates Action Text's ability to
sanitize and scrub its content.

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-10-30 17:49:13 -04:00
Rafael Mendonça França d0ed4c8ecc
Update actiontext JavaScript 2023-10-27 13:50:49 +00:00
Hartley McGuire c93a989635
Fix using trix in sprockets
When Trix was [updated][1] from 1.3.1 to 2.0.4, the ESM bundle of 2.0.4
was used instead of the UMD bundle (the vendored 1.3.1 file used the
UMD bundle). This leads to issues when trying to use Trix with sprockets
because the ESM bundle declares variables like they are scoped to the
file but sprockets will see them as scoped globally.

This commit fixes the issue by replacing the Trix ESM bundle with the
UMD bundle (and upgrades it from 2.0.4 to 2.0.7). Additionally, a Rake
task has been added similar to one previously [added][2] to the guides
for automatic vendoring using Importmap::Packager.

[1]: fab1b522cd
[2]: a42863f514
2023-10-25 00:25:35 -04:00
Mike Dalessio e8137c527d
Fix ActionText::ContentHelper allowed tags and attrs
which were being set to the HTML4 defaults before the sanitizer
configuration could be applied.

Also, backfill some light tests for sanitization.

Related to #48644
2023-07-17 11:43:51 -04:00
Mike Dalessio 44d3b44d9d
Add config.action_text.sanitizer_vendor
Rails 7.1 defaults to Rails::HTML::Sanitizer.best_supported_vendor,
earlier configs will use Rails::HTML4::Sanitizer.

Related to #48523 / 55bca6b8.
2023-07-04 08:54:46 -04:00
Mike Dalessio 55bca6b8e8
Update Action Text to use HTML5 when available
The change from `#clone` to `#dup` is necessary to work around an
issue in Nokogiri where `#clone` is not defined properly for HTML5
fragment and the fragment does not have a parent Document. `#dup`
behaves the way we expect, so this should be fine.
2023-06-19 15:59:59 -04:00
Hartley McGuire c7a812535d
Add doc for FormBuilder#rich_text_area
Using the style of other ActionView::Helpers::FormBuilder methods that
delegate to another method.
2023-05-26 18:24:14 -04:00
Petrik e0d77a9f5c Document ActionText::RichText methods [ci-skip] 2023-04-15 21:53:21 +02:00
Petrik c09f5fa956 Add missing headers to Action Mailbox/Mailer/Text/View docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-02 17:47:17 +02:00
Sarah Ridge 48b8285f4d
Update Action Text's Trix dependency (2.0.4) 2023-03-28 12:23:01 -04:00
justin talbott beb43e0182
Add `ActiveSupport` load hook for `ActionText::EncryptedRichText`
Both `ActionText::Record` and `ActionText::RichText` have dedicated `ActiveSupport` load hooks. This adds an
additional hook for `ActionText::EncryptedRichText`, so that external libraries have a similarly simple way
to run code after the subclass is loaded.
2023-03-22 16:00:08 -04:00
Jean Boussier 185f2d718d Allow to define the default column serializer
YAML has quite a bit of footguns, as such it's desirable
to be able to substitute it for something else or even
simply to force users to define a serializer explictly for
every serialized columns.
2023-02-22 19:32:28 +01:00
Sean Doyle fab1b522cd Update Action Text's Trix dependency
There is a new [Trix.js][] release, bumping the version from `1.3.1` to
`2.0.4`.

Applications that consume Action Text through the `@rails/actiontext`
npm package can manage their own Trix dependency version.

Similarly, Importmaps users can `pin "trix", to: "..."` to a CDN serving
`2.0.4`.

For the sake of applications that depend on Trix through the
`action_text` gem, this commit updates the pre-bundled JS and CSS code.

These changes were generated by executing the following:

```sh
cd actiontext
yarn build
cp ../node_modules/trix/dist/trix.css app/assets/stylesheets/trix.css
cp ../node_modules/trix/dist/trix.esm.js app/assets/javascripts/trix.js
```

[Trix.js]: https://trix-editor.org
[v2.0.4]: https://github.com/basecamp/trix/releases/tag/v2.0.4
2023-01-23 10:39:51 -05:00
Kaíque Kandy Koga 0dc71acf39 Apply field_error_proc to rich_text_area fields 2022-12-22 11:52:30 -06:00
Jeremy Daer 01d345c4d6
Merge pull request #45739 from basecamp/content-attachment-update
update ContentAttachment so that it works with "content" attributes
2022-09-06 11:15:10 -07:00
Jonathan Hefner b13107fe5e Fix typos [ci-skip] 2022-08-05 21:36:18 -05:00
Jamis Buck 4499a3cdd0 update ContentAttachment so that it works with "content" attributes
this makes it possible for an application to embed markup in a document
that would otherwise be undesirable or expensive to process. For example,
an incoming email may include a complicated bit of DOM in a quote, and
while you don't want to have to process and rewrite it, you also don't want
to discard it; the content attribute of ContentAttachment allows you to
make that work.
2022-08-02 15:08:16 -06:00
Gannon McGibbon aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6.
2022-01-29 14:27:45 +01:00
Gannon McGibbon 0b69ad4de6 Multi-service direct uploads in Action Text attachment uploads 2021-11-15 14:00:00 -05:00
DmitryTsepelev 193289dbbe Support direct uploads to multiple services 2021-11-14 11:49:06 +03:00
Lucas Mansur bac0038e20
Don't overwrite default opts in rich_text_area_tag (#43156)
You may want to use your own controller to authenticate requests or
perform server-side validations.
2021-09-19 20:56:17 +02:00
David Heinemeier Hansson a2a28e6c90 Switch to ESM compatible build of trix
The mirror setup isn't doing what we need to get a ESM-compatible version of Trix. So grab a build from Snowpack that's compatible for now.
2021-08-13 11:10:05 +02:00
Rafael Mendonça França 18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
David Heinemeier Hansson 0c2a94c265
No underscore style (#42898)
Just like activestorage.js
2021-07-28 15:34:59 -04:00
David Heinemeier Hansson 6c96e1cd7b
Move Active Storage JS to ESM and drop Babel transpiling (#42895)
* Move to ESM and drop Babel transpiling

* Make the activestorage JS directly available through the asset pipeline as a precompiled asset

* Use example with direct attachment

* Explain that direct reference is possible

* Active Storage JS is a module

* Retain umd asset for backwards compatibility, add ESM file in addition

* Explain how to use activestorage.esm with importmap

* Use untranspiled activestorage inclusion

* Don't repeat terser options
2021-07-28 15:17:13 -04:00
David Heinemeier Hansson 9c73d4aeab
Make Action Text + Trix JS/CSS available via the asset pipeline (#42857)
* Action Text JS should be available via the asset pipeline too

* Main was a module anyway, no need to reference that twice

* Fix rollup references

* Precompile action text JS for asset pipeline

* No JavaScript dependencies needed with the asset pipeline

* Stub Webpacker::Engine to trigger webpack path for testing

* Extract asset paths

* Exercise asset pipeline path

* Terser doesn't do anything useful on this small package

* Make trix directly available to the asset pipeline

* Indirect doesn't carry its worth

* Reminder for development about keeping things in sync for the asset pipeline

* Ensure this isn't turned into undefined while mirroring

* Mirror Trix CSS for asset pipeline

* Add the needed JS include tag automatically under the asset pipeline

* Please RuboCop

* Keep the peer dependency

Even though we also need it explicitly as a dev dependency in order to generate the mirror output for trix.

* Fix test

* Add CHANGELOG entry
2021-07-26 18:57:42 -04:00
Steve Polito e0d57541ab Add note regarding "trix-content" class 2021-05-30 10:37:21 -05:00
Sean Doyle 68bb2650d5 Action Text: forward form: option to hidden input
Trix's `<trix-editor>` doesn't support the [form][] property like
`<textarea>` or other form fields.

For example, consider the following HTML and event listener:

```html
<form action="/articles" method="post">
  <textarea name="content"></textarea>

  <button type="submit">Save</button>
</form>

<script>
  addEventListener("keydown", ({ key, metaKey, target }) => {
    if (target.form && key == "Enter" && (metaKey || ctrlKey)) {
      form.requestSubmit()
    }
  })
</script>
```

The `target` (an instance of `HTMLTextAreaElement` relies on the
[HTMLTextAreaElement.form][] property for access to its associated
`<form>`. While it's usually equivalent to `target.closest("form")`,
that isn't always the case. Declaring a `[form]` attribute with another
`<form>` element's `[id]` value can associate a field to a `<form>` that
is _not an ancestor_. That means that the event listener from above
would continue to work with this HTML:

```html
<textarea name="content" form="new_article"></textarea>

<!-- elsewhere -->
<form id="new_article" action="/articles" method="post">
  <button type="submit">Save</button>
</form>
```

Unfortunately, if the `<textarea>` element were replaced with a
`<trix-editor>`, the event listener's reliance on accessing the form as
a property would break, since the `<trix-editor>` custom element doesn't
declare that property. There is currently a pull request
([basecamp/trix#899][]) to add support for accessing the `form` as a
property of the `<trix-editor>` element.

The [feedback][] provided on that pull request suggests that we
implement the `form` property by delegating to the `<input
type="hidden">` element. Currently, `<input type="hidden">` elements
constructed by Action Text helpers cannot declare the `[form]`
attribute.

This commit adds support by special-casing the `options[:form]` key
within `ActionText::TagHelper#rich_text_area_tag`.

[form]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement#properties
[basecamp/trix#899]: https://github.com/basecamp/trix/pull/899#discussion_r618543357
[feedback]: https://github.com/basecamp/trix/pull/899#discussion_r618543357
2021-04-25 20:27:24 -04:00
Jorge Manrubia 638a92f734 Initial extraction from active_record_encryption gem 2021-04-01 15:02:13 +02:00
Mark VanLandingham bece535c98
Add config.action_text.attachment_tag_name 2021-03-05 16:57:36 -05:00
Abhay Nikam adc5eb66f8
Action Text: call #to_trix_html on rich_text_area_tag value 2021-02-28 11:20:59 -05:00
Sean Doyle 3500571b43 Improve ActionText extensiblibility
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.
2020-12-29 20:06:45 -05:00
Jonathan Hefner 614e813161
Disentangle Action Text from ApplicationController
This commit allows Action Text to be used without having an
ApplicationController defined.  In doing so, it also fixes Action Text
attachments to render the correct URL host in mailers.

It also avoids allocating an ActionController::Renderer per request.

Fixes #37183.
Fixes #35578.
Fixes #36963.
Closes #38714.

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-10-30 01:01:42 +00:00
George Claghorn b0287d0681 Extract ActionText::Record
Permit applications to hack in custom DB config for ActionText::RichText until AT has first-class multi-DB support:

    ActiveSupport.on_load(:action_text_record) do
      connects_to reading: :action_text_replica, writing: :action_text_primary
    end
2020-09-29 11:59:14 -04:00
Paulo Ancheta b9571ae45f
Add value option to ActionView::Helpers::FormBuilder#rich_text_area 2020-09-01 21:43:07 -04:00
Jan Habermann 40be6b1d4d Cleanup unneeded blank string params in ActionText 2019-08-23 20:17:38 +02:00
Juanito Fatas 52f0b050e2
Update sanitizer in ActionView::Helpers::SanitizeHelper
- The sanitizer has been changed to safe_list_sanitizer.
- deprecate white_list_sanitizer
2019-08-05 03:35:35 +02:00
Akira Matsuda 530f7805ed It may be better to explicitly require 'object/try' where we call `try`
In most cases it works now without explicit require because it's accidentally required through
active_support/core_ext/date_and_time/calculations.rb where we still call `try`,
but that would stop working if we changed the Calculations implementation and remove the require call there.
2019-08-01 18:51:51 +09:00
George Claghorn aa7da0471f Deduplicate ActionText::RichText embeds
Fix that an ActiveRecord::RecordNotUnique error would be raised when saving rich-text content with the same file attached multiple times.
2019-05-17 16:46:16 -04:00
Javan Makhmali 0ec2a90754 Make Action Text's rendering helpers more configurable
- Allow configuring the sanitizer and its options
- Split attachment rendering and sanitizing helpers so each can be overridden by applications
2019-04-22 10:15:25 -04:00
Chris LaRose c03a50ade3 Explicitly require rails-html-sanitizer gem in ActionText helpers
If the [`action_text.helper` initializer][0] runs after
`ActionController::Base` has been loaded, but before the
`rails-html-sanitizer` gem has been `require`d, then the reference to
the constant `Rails::Html` in the body of the
`ActionText::ContentHelper` module raises an `uninitialized constant`
exception.

[0]: 2170338239/actiontext/lib/action_text/engine.rb (L31-L35)
2019-03-06 17:32:03 -08:00
Abhay Nikam b3778c5708 Allows rich_text_area_tag to add I18n translated placeholder text if placeholder option set to true 2019-02-22 10:18:21 +05:30