Commit Graph

56 Commits

Author SHA1 Message Date
Jorge Manrubia
638a92f734 Initial extraction from active_record_encryption gem 2021-04-01 15:02:13 +02:00
Abhay Nikam
5de2dbff16 Fixes failing ActionText::ContentTest test cases
The test cases where failing because the test
`test_converts_Trix-formatted_attachments_with_custom_tag_name` set a
custom tag_name to `arbitrary-tag`. This test would also set the
ActionText::AttachmentGallery::ATTACHMENT_SELECTOR private constant
to `arbitrary-tag`.

Other test cases had proper ActionText::Attachment.tag_name set to
`action-text-attachment` but the constant once defined would not
reset.

This PR attempts to fix the issue by converting the
ActionText::AttachmentGallery::{ATTACHMENT_}SELECTOR to class methods

Fixes #41782
2021-03-30 16:38:11 -04:00
James Brooks
b1b0b22f50
Always render attachment partials as HTML with :html format inside trix editor 2021-03-19 13:35:09 -04:00
Xavier Noria
c431432f93 Add app/{helpers,models} to autoload_once_paths
The helpers of Action Text are added to a couple of non-reloadable
base classes:

  initializer "action_text.helper" do
    %i[action_controller_base action_mailer].each do |abstract_controller|
      ActiveSupport.on_load(abstract_controller) do
        helper ActionText::Engine.helpers
      end
    end
  end

Therefore, it does not make sense that they are reloadable themselves.

For the same price, we can also make the models non-reloadable, thus
saving parent applications from the unnecessary work of reloading this
engine.

We did this for turbo-rails as well.
2021-03-07 23:05:24 +01:00
Mark VanLandingham
bece535c98
Add config.action_text.attachment_tag_name 2021-03-05 16:57:36 -05:00
Ryuta Kamizono
7b680baea2 Remove require "active_support/core_ext/symbol/starts_ends_with"
Ruby 2.7 has native `Symbol#start_with?` and `Symbol#end_with?`.
2021-02-09 22:31:09 +09:00
Rafael Mendonça França
1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Sean Doyle
0ad777cdcc
Improve ActionText::FixtureSet documentation (#41062)
* Improve ActionText::FixtureSet documentation

Support for Action Text attachments in fixtures was added by [76b33aa][] and
released as part of [6.1.1][], but has not yet been documented.

This commit documents the `ActionText::FixtureSet` for the API
documentation, and mentions it in the Rails Guides pages.

[76b33aa]: 76b33aa3d1
[6.1.1]: https://github.com/rails/rails/releases/tag/v6.1.1

* Fix indention of comments

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2021-01-24 11:16:27 +01:00
Jonathan Hefner
44d1006de3 Run bin/yarn via Ruby
Windows cannot directly run shebang scripts, such as `bin/yarn`.
Therefore, run `bin/yarn` via Ruby.

Actually fixes #40942.
Fixes #41123.
2021-01-21 11:51:15 -06: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
ef61c9c8a3
Fix rendering Action Text HTML in new threads
Because `ActionText::Content.renderer` is implemented as a
`thread_cattr_accessor`, any default value set in the main thread will
be inaccessible from other threads.  Therefore, use a `cattr_accessor`
to store the default renderer, and fall back to it when `renderer` has
not been set by e.g. `with_renderer`.

Fixes #40757.
2020-12-07 16:41:44 -05:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Kasper Timm Hansen
835dba24cb
Merge pull request #40673 from jonathanhefner/actiontext-test-install-generator
Test Action Text install generator
2020-11-27 20:35:08 +01:00
Jonathan Hefner
76e111395c Always render Action Text HTML with :html format
Since #40222, Action Text HTML is rendered in the context of the current
request.  This causes the Action Text template format to default to the
request format, which prevents the template from being resolved when the
request format is not `:html` (e.g. `:json`).  Therefore, override the
template format to always be `:html`.

Fixes #40695.
2020-11-27 10:59:24 -06:00
Ryuta Kamizono
64c254017e Add explicit require for Symbol#start_with? 2020-11-25 15:22:32 +09: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
Jonathan Hefner
a6b503c052 Test Action Text install generator
This commit adds tests for the Action Text install generator.  It also
includes a few changes in and around `generators_test_helper.rb` to make
writing similar tests easier in the future.

Closes #39317.

Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
2020-11-23 18:07:54 -06: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
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
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
Vinicius Stock
98a3644be0
Create update yarn task (#39314)
* Use app:binstub:yarn in Action Text install generator
2020-05-17 19:51:32 +02:00
Rafael França
1add7387b3
Merge pull request #37951 from t0yohei/add-missing-action-to-action-text
Action Text: Add method to confirm rich text content existence by adding ? after content name
2020-03-19 16:26:52 -04:00
Jonathan Hefner
f6f51632e8 Use rails_command :inline option
Follow-up to #37516.
2020-02-10 17:53:41 -06:00
Kasper Timm Hansen
538424a5ca
Merge pull request #37823 from abhaynikam/35085-update-the-action-text-installer
Add ActionText installer rake task
2019-12-16 23:20:29 +01:00
Abhay Nikam
d0c73b3a9e Add ActionText installer rake task back after changes in #35085. Forwards the installer to run new ActionText generator 2019-12-16 23:27:24 +05:30
Kasper Timm Hansen
64ff6bc4c6
Tune ActionText::Generators::InstallGenerator
* Use rails_command instead of run (will also print "rails" in the output)
* Generally tune colors: print green for the status updates,
  red for the warning to get the eye.
* Combine migration copying into running one task and pass FROM.
  Generates "create_tables.engine_name.rb" migrations.
* Slim some variables and style the copy_file invocation.
2019-12-15 21:08:48 +01:00
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
Javan Makhmali
296cc53277 Fix ActiveStorage::Blob → ActionText::TrixAttachment conversion
A regression introduced in 764803e07a5c89c931df9a1c4fe730f73b7571e6 caused blobs to appear as HTML content attachments instead of file / image attachments when editing rich text content. This change restores the original intended behavior.

References: https://github.com/rails/rails/pull/35485, https://github.com/basecamp/trix/issues/706
2019-12-03 05:57:36 -05:00
Vinicius Stock
028d1611cd
Run app:update:bin from actiontext generator 2019-11-15 08:58:11 -05:00
Vinicius Stock
0bc9c16ffc
Fix rubocop offenses 2019-11-15 08:58:11 -05:00
Vinicius Stock
b1f6be8f49
Create GEM_ROOT and make js_dependencies private 2019-11-15 08:58:11 -05:00
Vinicius Stock
0875c94b09
Create ActionText install generator 2019-11-15 08:58:11 -05:00
Jan Habermann
40be6b1d4d Cleanup unneeded blank string params in ActionText 2019-08-23 20:17:38 +02:00
Javan Makhmali
55a5aac670 Optimize Action Text's plain text conversion
Fixes that converting deeply nested elements could exceed the stack level.
2019-08-22 16:24:51 -04: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
Akira Matsuda
0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
George Claghorn
930402101c Implement ActiveStorage::Blob#attachable_plain_text_representation
Fixes that file attachments without captions would not be represented in plain text generated from rich-text content, causing ActionText::RichText#present? to return false.

Closes #36607.
2019-07-07 22:03:06 -04:00
George Claghorn
339be65d66 Allow filling in the only rich-text area without a locator 2019-05-19 01:55:53 -04:00
George Claghorn
a0b102999a Prefer Capybara::Node::Element#execute_script 2019-05-19 01:47:29 -04: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
Abhay Nikam
cfe30cee3e Adds a warning message for action text installer if application pack is missing. 2019-04-19 08:30:59 +05:30
George Claghorn
ff7948b1c2 Avoid creating ActionText::RichText records unnecessarily
Assigning a has_one association for a persisted record saves the change immediately, so attempting to read a rich-text attribute on a persisted record without a corresponding ActionText::RichText would eagerly create one. Avoid assigning the rich text association to fix.
2019-03-23 10:04:48 -04:00
George Claghorn
c399f7d07a
Fix updating rich text via nested attributes
Closes #35159.
2019-03-17 17:22:46 -04:00
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Chris Oliver
764803e07a Adds default trix partial 2019-03-05 11:29:32 -06:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Vinicius Brasil
95e00befbc
Add line break to Action Text installation outputs
The Action Text installations appends `require("trix")` to the application.js file. The problem is that there isn't a line break in the beginning of the installation output, leading to syntax errors, e.g.:

```
import './application.scss'require("trix")
```

This commit moves the line break from the end to the beginning of the output, fixing it to:

```
import './application.scss'
require("trix")
```
2019-01-27 22:30:17 -02:00