Commit Graph

72 Commits

Author SHA1 Message Date
David Heinemeier Hansson
82e4432058
Javascript generator option with choices (#43160)
* Switch to a single controller option for choosing JavaScript approach

* Remove remnants of webpacker specific work within Rails

* No longer used

* Missing space

* Raise if unknown option is passed

* Style

* Use latest versions

* Make channels setup generic to all node setups

* Make Action Text installer work with any node package manager

* Explaining variables are not useless

* Rubocop pleasing

* Don't rely on Rails.root

Tests don't like it!

* Rubocopping

* Assume importmap

* No longer relevant

* Another cop

* Style

* Correct installation notice

* Add dependencies for action cable when adding a channel

* Fix paths to be relative to generator

* Just go straight to yarn, forget about binstub

* Fix tests

* Fixup installer, only yarn once

* Test generically with run

* Style

* Fix reference and reversibility

* Style

* Fix test

* Test pinning dependencies

* Remove extra space

* Add more tests

* Use latest dependencies

* Relegated this to controllers

* Refactor ChannelGenerator + more tests

Use a uniform level of abstraction
2021-09-04 11:53:57 +02:00
Jean Boussier
4b4d1452d9 Eliminate some Integer() rescue nil patterns in Action Text 2021-08-26 19:39:44 +02:00
David Heinemeier Hansson
d5b9618da1
Remove default reliance on Sass and CSS generators (#43110)
* No benefit to having actiontext css as scss

* Update test

* Update docs

* No more css assets to be generated

New world, new CSS frameworks, new needs.

* SCSS is becoming optional

* Remove Sass as a default-on setting

But continue to make it easy to add.

* Update docs

* No longer used

* Update tests

* Update docs

* Update docs

* No longer used

* No longer by default

* Fix tests

* Promote Tailwind CSS as an alternative to Sass

* Fix test and copy task

* Update railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Co-authored-by: Kevin Newton <kddnewton@gmail.com>

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-08-26 13:40:25 +02:00
David Heinemeier Hansson
af7428c4ac
Replace webpack with importmapped Hotwire as default js (#42999)
* Turbolinks is being replaced with Hotwire

* Make --webpack opt-in

* Don't use specific webpacker installers any more in preparation for next Webpacker

* Update railties/lib/rails/app_updater.rb

Co-authored-by: Alex Ghiculescu <alex@tanda.co>

* Trailing whitespace

* Convert to Turbo data attribute for tracking

* Default is no webpack, no hotwire

* Swap out turbolinks references for hotwire

* Drop explicit return

* Only generate package.json if using webpack

* Only create package.json in webpack mode

* Only create app/javascript in webpack mode

* Generate correct style/js links based on js mode

* Fix tests from changed output format

Not sure why these are showing up in this PR, though.

* Rubocopping

* Stick with webpack for the test app for now

* Adjust tests

* Replace minitest-reporters with minitest-ci (#43016)

minitest-reporters is used to create junit xml reports on CI.

But when it loads before rails minitest plugin makes
`Rails::TestUnitReporter` not being added as a reporter.

minitest-ci is now only loaded at ci and does not interferes with
rails minitest plugins. And keeps junit reports workings

* Too heavy handed to actually run bundle

Just like we don't auto-migrate

* Pin js frameworks in importmap

Instead of having importmap preconfigure it.

* Match updated app/javascript path

* No need for the explaining comment

* Fixes test cases for replace webpack with importmapped Hotwire as default js (#42999)

* Fix rubocop issues

* Fix more railities test cases

* Fix plugin generator railties shared test cases

* Fix Action Text install generator asset pipeline spec

* They're modules, not files

* Let dev use the latest release as well

So we don't have to replace unexisting dev releases with latest release

* Make Webpack responsible for generating all the JS files it needs

Webpacker 6 has already moved from app/javascript to app/packs.

* Don't add rails/ujs by default any longer

All the ajax/form functionality has been superseded by Turbo. The rest lives in a weird inbetween land we need to address through other means.

* Use new importmap location

* Switch to using turbo-rails and stimulus-rails directly

The hotwire-rails gem does not offer enough value for its indirection

* Use latest Webpacker

* Prevent version resolution requests from getting swallowed

* Use ESM syntax for imports

* Move management of yarn, package.json, etc to Webpacker 6

* Update for Webpacker 6

* Move bin/setup addition to Webpacker as well

* Remove dead tests

* Bump to Webpacker 6.0.0.rc.2

* No longer relevant given the new default is no webpacker

* Rely on Webpacker 6

* No longer relevant

* No longer relevant

* Make cable channel generator work for both webpacker and importmap setups

* Fix tests

* For tests testing importmap way

* Use Webpacker 6 dummy

* RuboCopping

* One more bump to fix webpack-dev-server

* Another bump. Hopefully the last one!

* Also enough to not want turbo tracking on

* Fix tests

* Latest

* Fix tests

* Fix more tests

* Fix tests

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2021-08-26 10:39:36 +02:00
David Heinemeier Hansson
6ec669b65d
Action Text installer should assume importmap for asset pipeline (#43011)
* Action Text installer should assume importmap for asset pipeline

* Fix test
2021-08-13 14:43:06 +02:00
David Heinemeier Hansson
a2cd0a57f7
Ensure image processing gem is enabled when turning on action text so image uploads work out-of-the-box (#43010)
* Ensure image processing gem is enabled when turning on action text so uploads will work

* Test enabling image_processing gem

* Fix rubocop issue
2021-08-13 14:05:23 +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
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
Alex Ghiculescu
7f348eb9d4 Document Active Storage & Action Text eager loading
Docs for https://github.com/rails/rails/pull/40842 + https://github.com/rails/rails/pull/39397

[ci skip]
2021-06-14 11:03:48 -05:00
Ryuta Kamizono
bbbc861f71 Enable Performance/MapCompact cop
Follow up to #42053.
2021-04-23 16:33:02 +09:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
John Bampton
4b681bd50f
Fix spelling in ActionText::FixtureSet.attachment docs [ci skip] 2021-04-11 10:56:31 -04:00
Jorge Manrubia
588c972d21 Removes the Action Text dependency from Active Record
Move the Action Text stuff to its own concern in `actiontext`.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
f046617853 Temporary change just to confirm this is the problem with some intermittent failures in buildkite
[skip ci]
2021-04-01 15:02:14 +02:00
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