Commit Graph

37 Commits

Author SHA1 Message Date
Rafael Mendonça França
30683cbf85
Copy-edit CHANGELOG 2023-03-25 16:50:19 +00:00
Matt Swanson
fbf0145f19 Allow Attachables to override default template when attachment is missing 2023-02-13 10:45:12 -05: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
Sean Doyle
0e9013081e Revert "Focus editor after calling fill_in_rich_text_area"
Closes [rails/rails#46803][].

This reverts commit 67a4ac6c5651a00e613de298631d460116bba38c.

Once the system test helper test suite executes in CI, we can
re-introduce the changes as part of [rails/rails#46807][].

[rails/rails#46803]: https://github.com/rails/rails/issues/46803#issuecomment-1364112967
[rails/rails#46807]: https://github.com/rails/rails/pull/46807
2022-12-23 14:19:25 -05:00
Kaíque Kandy Koga
0dc71acf39 Apply field_error_proc to rich_text_area fields 2022-12-22 11:52:30 -06:00
Jonathan Hefner
93038baad7 Use routes.default_url_options in AC::Renderer env
When a host is not specified for an `ActionController::Renderer`'s env,
the host and related options will now be derived from the routes'
`default_url_options` and `ActionDispatch::Http::URL.secure_protocol`.

For example, with:

  ```ruby
  Rails.application.default_url_options = { host: "rubyonrails.org" }
  Rails.application.config.force_ssl = true
  ```

Before:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "http://example.org/blog"
  ```

After:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "https://rubyonrails.org/blog"
  ```

As a consequence, Action Text attachment URLs rendered in a background
job (a la Turbo Streams) will now use `Rails.application.default_url_options`.

Fixes #41795.
Fixes hotwired/turbo-rails#54.
Fixes hotwired/turbo-rails#155.
2022-12-15 16:22:07 -06:00
Sean Doyle
67a4ac6c56 Focus editor after calling fill_in_rich_text_area
When System Tests call `fill_in_rich_text_area`, they interact with
`<trix-editor>` elements by changing the contents programmatically.

This is unlike how end-users will interact with the element. Overhauling
the test helper to more accurately reflect Real World usage would
require a sizable effort.

With that being said, leaving the `<trix-editor>` with focus after
populating its contents is a minor change that makes it a more genuine
recreation.
2022-12-09 09:48:27 -05:00
Sean Doyle
4a743b9e0a Support has_rich_text with strict_loading:
Expand the `has_rich_text` signature to accept a `strict_loading:`
value. Forward that value along to the `has_one` declaration made under
the hood. When omitted, `strict_loading:` will be set to the value of
the `strict_loading_by_default` class attribute (false by default).
2022-10-18 17:06:26 -04:00
Jamis Buck
c8ea92cf27 update CHANGELOG 2022-08-02 16:05:25 -06:00
Jacob Herrington
5811097ece Avoid renders in equality check of rich_text content 2022-02-18 14:33:12 -06:00
Rafael Mendonça França
83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
matt swanson
0b1f83d0bc
Better ActionText plain text output for nested lists (#37976)
* Improve plaintext output for nested lists

* Update plain_text_conversion_test.rb

* Add additional test cases

* Refactor a bit

* Add changelog entry

* Rearrange methods

Co-authored-by: Matt Swanson <matt@mdswanson.com>
2021-10-12 18:05:04 +02:00
Rafael Mendonça França
49bc29a8fb
Fix CHANGELOG [ci skip] 2021-09-20 17:56:06 -04: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
Rafael Mendonça França
d177551c30
Preparing for 7.0.0.alpha2 release 2021-09-15 18:22:51 -04:00
Rafael Mendonça França
9b7be48212
Preparing for 7.0.0.alpha1 release 2021-09-15 17:55:08 -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
Dirkjan Bussink
0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02: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
Mark VanLandingham
bece535c98
Add config.action_text.attachment_tag_name 2021-03-05 16:57:36 -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
Ryuta Kamizono
401ce9dd3d Tweak CHANGELOGs [ci skip]
* Remove trailing space
* Add period
* etc
2020-12-29 21:11:16 +09:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
matt swanson
9b6459aab6
Add support for eager loading all rich text associations at once (#39397)
* Add `with_all_rich_text` method to eager load all RichText models at once

* Update actiontext/test/test_helper.rb

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>

* Update actiontext/lib/action_text/attribute.rb

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-11-24 18:19:46 +01:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Sean Doyle
76b33aa3d1
Add ActionText::FixtureSet.attachment
Permit generating rich-text attachment markup in YAML fixtures:

    hello_world_review_content:
      record: hello_world (Review)
      name: content
      body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
2020-10-30 15:53:35 -04:00
Sean Doyle
614580270d Locate fill_in_rich_text_area by <label> text
This commit dovetails with [#38551] in its focus on improving the
ability to test calls to `rich_text_area` in accessibility-minded ways.

In addition to searching for `<trix-editor>` elements with the
appropriate [`aria-label`][aria-label] attribute, also support locating
elements that match the corresponding `<label>` element's text.

Now that [basecamp/trix#829][] has been merged and released, clicking on
`<label>` elements that reference `<trix-editor>` elements will move
focus into the `<trix-editor>` element.

There are still some accessible [label text][] improvements that could
be made, but extending `fill_in_rich_text_area` to account for `<label
for="...">` elements is a good start.

[#38551]: https://github.com/rails/rails/pull/38551
[aria-label]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
[basecamp/trix#829]: https://github.com/basecamp/trix/pull/829
[label text]: https://github.com/basecamp/trix/pull/829#issuecomment-699119852
2020-10-02 18:02:14 -04:00
Paulo Ancheta
b9571ae45f
Add value option to ActionView::Helpers::FormBuilder#rich_text_area 2020-09-01 21:43:07 -04:00
प्रथमेश Sonpatki
1a2de86568
Add release notes for Action Text [ci skip] (#39231)
Also cleanup Action Text Changelog.
2020-05-11 23:13:33 +05:30
Kyohei Toyoda
07533a3d2f Add method to confirm rich text content existence by adding ? after content name
This change introduces a rich text object to make
it easier to confirm it context is existing or not.

If we have a class like below.

class Information < ApplicationRecord
  has_rich_text :notes
end

Before:
i = Information.new
i.notes? => NoMethodError
i.notes = "Some sample text"
i.notes.present? => true

After:
i = Information.new
i.notes? => false

i.notes = "Some sample text"
i.notes? => true
2019-12-13 12:58:42 +09:00
Ryuta Kamizono
cc27e9988f Unify to use 4 spaces indentation in CHANGELOGs [ci skip]
Especially, somehow `CHANGELOG.md` in actiontext and activestorage in
master branch had used 3 spaces indentation.
2019-06-05 05:53:49 +09:00
George Claghorn
b2b6341374
Add ActionDispatch::SystemTestCase#fill_in_rich_text_area 2019-05-13 12:44:06 -04:00
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
George Claghorn
0decd2ddc4 Import Action Text 2019-01-04 22:22:49 -05:00