* 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
* 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>
* 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>
* Stop trying to configure listen by default on compatible platforms
Modern computers with SSDs don't see much/any benefit from having an evented file update watcher. Remove complexity by taking this spinning-drive concession out.
* Actually need listen for testing the opt-in
* Test no longer relevant
* 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
* 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
Similar to: #42378
Tried adding test cases for the changes but
migration file would always use id as primary_key_type
and reference type as foreign_key_type. Did not find
any good way to assert the changes.
Tested locally and following is the schema
generated for Action Text migration if
`primary_key_type: :uuid`
```
create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name", null: false
t.text "body"
t.string "record_type", null: false
t.uuid "record_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end
```
Terser is more up to date with modern javascript features, and the
uglifier gem repository recommends using it for minifying ES6+.
Followup for 955041b
Affected gems:
* actionmailbox
* activestorage
* actiontext
This fixes the following warning:
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.
The new connection handling does not support `connection_handlers`
getter and setter.
Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
(called from require at ~/.gem/ruby/3.1.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34)
Currently when you make a new Rails app, we generate a lot of initializers. For new users, I think we should try and include as few as possible - the less files, the less daunting a new app is. And for upgrades I'd like to [continue to simplify the update process](https://github.com/rails/rails/pull/41083), in this case by not bringing back initializers you have probably already dismissed or modified.
In this PR I'm proposing we remove two initializers: `application_controller_renderer.rb` and `cookies_serializer.rb`:
**`application_controller_renderer.rb`**. This configures [`ActionController::Renderer`](https://api.rubyonrails.org/classes/ActionController/Renderer.html), for rendering views outside of controller actions. I don't think this is something most Rails apps will need (certainly not on day 1); users can configure this feature when they need it.
**`cookies_serializer.rb`**. This was added for [Rails 4.1](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#cookies-serializer). The behaviour is:
- For new apps, the initializer says `:json`.
- For upgraded apps that don't have the initializer, it is added with value `:marshal`.
- If there's no initializer, the [default value](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)) is `:marshal`.
Since nobody should be upgrading direct from Rails 4.0 to Rails 7.0, we can simplify this by using new framework defaults. So the behavior will now be:
- For new apps, `config.load_defaults("7.0")` sets the value to `:json`.
- The `new_framework_defaults_7_0.rb` file explains this, and suggests using `:hybrid` to be upgrade to JSON cookies.
- No changes to [the code](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)); the default value is `:marshal` if you don't set one.
So if you were not setting a `cookies_serializer` previously and you want to keep using `:marshal`, you'll need to explicitly set this before using `config.load_defaults("7.0")`, otherwise it will switch to `:json`. The upside of this is you won't get the `cookies_serializer.rb` file created for you every time you upgrade.
Both methods are defined in multiple parts of the framework. It would
be useful to put them in a proper place, so that repetition is
avoided.
I chose the implementation from `ActiveRecord` because it's a bit more
complete with the `SQLCounter` class, and also because other parts
depend on it.
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
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
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.
* 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>
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.
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.
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.
All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
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.
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>
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>
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.
`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/". Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.
This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.
Additionally, this commit refactors and expands existing test coverage.
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
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
As a developer, when looking at a page in my web browser, it's sometimes
difficult to figure out which template(s) are being used to render the page.
config.action_view.annotate_template_file_names adds HTML comments to the
rendered output indicating where each template begins and ends.
Co-authored-by: Aaron Patterson <tenderlove@github.com>
* require, require_relative, load by double quotes
We're getting rid of all single quote usage, unless it serves a specific purpose, as per the general style guide.
* 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.
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
Rails 6.0 introduces parallel testing and the default degree of parallelism is configured based on the number of CPU.
refer https://github.com/rails/rails/pull/34735https://github.com/rails/rails/pull/31900
When any minitest executed under the OS where 2 or more CPU available,
SQLite 3 database files are not git-ignored.
Also updated other files which ignores SQLite database files.
* Steps to reproduce
```
$ git clone https://github.com/yahonda/rep_ignore_sqlite3_databases.git
$ cd rep_ignore_sqlite3_databases/
$ bin/rails test
$ git status
```
* Expected behavior:
- No `Untracked files:`
* Actual behavior:
- SQLite 3 database files appeared
```
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
db/test.sqlite3-0
db/test.sqlite3-1
db/test.sqlite3-2
db/test.sqlite3-3
db/test.sqlite3-4
db/test.sqlite3-5
nothing added to commit but untracked files present (use "git add" to track)
$
```
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.
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.
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.
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)
I implemented Foreign key create in `create_table` for SQLite3 at
#24743. This follows #24743 to implement `add_foreign_key` and
`remove_foreign_key`.
Unfortunately SQLite3 has one limitation that
`PRAGMA foreign_key_list(table-name)` doesn't have constraint name.
So we couldn't implement find/remove foreign key by name for now.
Fixes#35207.
Closes#31343.
In MySQL, the text column size is 65,535 bytes by default (1 GiB in
PostgreSQL). It is sometimes too short when people want to use a text
column, so they sometimes change the text size to mediumtext (16 MiB) or
longtext (4 GiB) by giving the `limit` option.
Unlike MySQL, PostgreSQL doesn't allow the `limit` option for a text
column (raises ERROR: type modifier is not allowed for type "text").
So `limit: 4294967295` (longtext) couldn't be used in Action Text.
I've allowed changing text and blob size without giving the `limit`
option, it prevents that migration failure on PostgreSQL.
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")
```
Failing test before the ActionText::RichText change:
```
Error:
ActionText::ModelTest#test_embed_extraction_only_extracts_file_attachments:
ArgumentError: Could not find or build blob: expected attachable, got #<ActionText::Attachables::RemoteImage:0x00007fb0259fef70 @url="http://example.com/cat.jpg", @content_type="image", @width=nil, @height=nil>
```
After 866da19fd9 we now use package.json
to install Action Text's JS dependencies (see JS_PACKAGE_PATH).
But when the gem pacakge for Action Text is built, package.json was not
included so running `rails action_text:install` in a Rails app would
fail with:
```
rails action_text:install
rails aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - xxx/gems/actiontext-6.0.0.alpha/lib/templates/../../package.json
./bin/rails:4:in `<main>'
Tasks: TOP => app:template
(See full trace by running task with --trace)
```
The Frameworks collection was missing actiontext and actionmailbox,
this would mean they are skipped when running any tasks that
iterated through this collection
changes include
Breaking up frameworks declaration into multiple lines and put
them in order. This should make adding to the list easier and
if you need to scan it, they will be in order you would expect
Add `package` task to both actiontext and actionmailbox
- config.load_defaults 6.0 in the dummy app and
fix the test since by default rails 6.0 configured
does not generate "utf8" hidden input, see #32125
- Use `ActiveRecord::Migration[6.0]` in the dummy app
since actiontext will be since Rails 6.0
- Fix `CreateActiveStorageTables` migration in the dummy app.
Add `t.foreign_key :active_storage_blobs, column: :blob_id`
It was added in 2ae3a29508.
- `rails/actiontext$ yarn install`
- Move some actiontext/README.md content to Action Text Overview guide
- I added WIP label to that guide since we definitely want to complement it.
- Add Action Text to Major Features of Rails 6.0
Similar approach was used in #34812
This comment was autogenerated, see
`railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt`
Since actiontext is well described in this file, I think we shouldn't
keep this comment. Note that this commit is more like cosmetic change,
so it is OK if we don't merge this.