Commit Graph

347 Commits

Author SHA1 Message Date
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
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
eef63e05fb chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
John Bampton
4b681bd50f
Fix spelling in ActionText::FixtureSet.attachment docs [ci skip] 2021-04-11 10:56:31 -04:00
Jorge Manrubia
28145c3cee Rename master_key => primary_key 2021-04-01 15:02:15 +02: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
1406ac294f Remove new lines 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
Henrik Nyh
515108ee03 'lookup' -> 'look up' in dummy webpacker.ymls
Corresponding to this fix: https://github.com/rails/webpacker/pull/2961
2021-03-21 12:36:56 +00: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
Abhay Nikam
ddbf01c52e @rails/actiontext: depend on released @rails/activestorage 2021-03-06 11:32:44 -05:00
Mark VanLandingham
bece535c98
Add config.action_text.attachment_tag_name 2021-03-05 16:57:36 -05:00
Christian Schmidt
6cd184ff0f
Use image/jpeg instead of non-standard image/jpg 2021-03-05 13:14:11 -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
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
Rafael Mendonça França
6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +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
Santiago Bartesaghi
e83d7dcb2f Use 4XX instead of 2XX for validation errors responses 2021-01-06 00:10:26 -03:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09: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
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
Petrik
0a583c73c1 Change form_with to generate non remote forms by default
`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`.
2020-12-01 21:14:37 +01:00
Alex Ghiculescu
76e432341c Always recommend config.asset_host in examples 2020-11-30 16:33:51 -06: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
Yasuo Honda
6edc61970e Address "ArgumentError: missing keywords: :sql, :name" when unit tests run by ruby 3.0.0dev
This pull request addresses the `ArgumentError: missing keywords: :sql, :name`,
which has been reported at https://buildkite.com/rails/rails/builds/72990#c78d1e4c-5775-4758-9010-9ba71fdb6138

Follow up #39397

```ruby
$ ruby -v
ruby 3.0.0dev (2020-11-24T22:48:19Z master 63ad55cd88) [x86_64-linux]
$ cd actiontext
$ bin/test test/unit/model_test.rb -n test_eager_loading
Run options: -n test_eager_loading --seed 16493

E

Error:
ActionText::ModelTest#test_eager_loading:
ArgumentError: missing keywords: :sql, :name
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:29:in `block in assert_queries'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:186:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `block in finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `each'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:45:in `finish_with_state'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:30:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:688:in `log'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/sqlite3/database_statements.rb:46:in `exec_query'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:536:in `select_prepared'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:67:in `select_all'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:103:in `select_all'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/querying.rb:47:in `find_by_sql'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:850:in `block in exec_queries'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:868:in `skip_query_cache_if_necessary'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:835:in `exec_queries'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:638:in `load'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:249:in `records'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:244:in `to_ary'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:553:in `find_nth_with_limit'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:538:in `find_nth'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:122:in `first'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:153:in `last'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/unit/model_test.rb:93:in `block (2 levels) in <class:ModelTest>'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:33:in `assert_queries'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/unit/model_test.rb:93:in `block in <class:ModelTest>'

Error:
ActionText::ModelTest#test_eager_loading:
ArgumentError: missing keywords: :sql, :name
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:29:in `block in assert_queries'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:186:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `block in finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `each'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:45:in `finish_with_state'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:30:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:688:in `log'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/sqlite3/database_statements.rb:98:in `exec_rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:378:in `rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:22:in `rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:205:in `rollback'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:302:in `block in rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:300:in `rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:328:in `rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:168:in `block in teardown_fixtures'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:167:in `each'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:167:in `teardown_fixtures'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:16:in `after_teardown'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:51:in `after_teardown'

bin/test test/unit/model_test.rb:90

Finished in 0.117256s, 8.5284 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
```

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2020-11-25 12:58:03 +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
Eugene Kenny
b7eaaf73fb Update comment about reloading in development.rb [ci skip]
This comment predates the existence of `reload_classes_only_on_change`.
2020-11-02 19:36:26 +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
Omri Gabay
43d83e96c9
Add option to mute multiple database yaml warning
Adds an option to silence the warning that database configurations can
throw when it's unparsable.
2020-10-29 16:57:57 -04:00
Jonathan Hefner
33fdae0584 Fix backtraces for generated plugin tests
`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.
2020-10-07 15:40:56 -05: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
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
Rafael França
56ab961dee
Remove white list word 2020-06-09 13:41:51 -04:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Rafael França
a80115b7c5
Merge pull request #39204 from prathamesh-sonpatki/template-annotation
Add the configuration option for annotating templates with file names to the generated app
2020-05-19 19:11:31 -04:00
Prathamesh Sonpatki
a673ce69e7
Rename annotate_template_file_names to annotate_rendered_view_with_filenames
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
2020-05-19 09:28:14 +05:30
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
Jonathan Fleckenstein
dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -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
Abhay Nikam
bdfffd1355 Update the Rails mailing list URLs to new discuss discourse URL [ci skip] 2020-04-02 22:00:28 +05:30
Joel Hawksley
a59e1de26a .annotate_template_file_names annotates HTML output with template file names
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>
2020-03-30 14:50:01 -06:00
David Heinemeier Hansson
3e0cdbeaf4
require, require_relative, load by double quotes (#38841)
* 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.
2020-03-29 16:30:52 -07: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
Ernesto Tagwerker
53776124d1 Correct grammar in setup comment 2020-02-12 13:31:43 -05:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Jonathan Hefner
f6f51632e8 Use rails_command :inline option
Follow-up to #37516.
2020-02-10 17:53:41 -06:00
Jonathan Hefner
f7b5019eea Remove redundant .gitignore entries
Follow-up to #37053.  The `*.sqlite3-*` .gitignore entries added in that
commit subsume previous `*.sqlite3-journal` entries.
2020-02-07 14:05:23 -06:00
Rodrigo Ramírez Norambuena
9c166d7a37 Add test for figcaption in actiontext 2020-01-18 22:07:16 -03:00
Abhay Nikam
d8beb77252 Bump license years from 2019 to 2020 [ci skip] 2020-01-01 15:10:31 +05:30
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00: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
George Claghorn
7d0327bbbf Track Active Storage variants in the database 2019-12-06 13:26:51 -05: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
Orien Madgwick
493edf044f Add bug tracker/documentation/mailing list URIs to the gemspecs 2019-10-11 20:47:19 -04:00
Juanjo Bazán
e4b5a3eb77 update package.json files to use https homepage value 2019-10-02 12:00:11 +02:00
DmitryTsepelev
e7f798c3f5 Allow configure services for individual attachments 2019-10-01 21:24:05 +03:00
Julik Tarkhanov
3c35de7933 Always create ActiveStorage::Blob before uploading to service 2019-09-24 07:32:59 -04:00
Akira Matsuda
501bab2f64 form_with takes keyword arguments 2019-09-24 13:48:14 +09:00
Carlos Antonio da Silva
1f325fab01
Merge pull request #37053 from yahonda/ignore_sqlite3_parallel_testing_databases
Ignore SQLite3 database files generated by parallel testing
2019-08-27 09:15:58 -03:00
Yasuo Honda
c5e3c537a4 Ignore SQLite3 database files generated by parallel testing
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/34735 https://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)
$
```
2019-08-27 11:42:04 +00: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
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
Javan Makhmali
aa00aec32a Bump Trix to ^1.2.0
Adds an attachment button to the Trix toolbar that improves overall file upload usability, especially on mobile devices where files can't be dragged / dropped.

References:
- https://github.com/basecamp/trix/releases/tag/1.2.0
- https://github.com/basecamp/trix/pull/619
- https://github.com/basecamp/trix/issues/582
2019-07-30 10:12:14 -04:00
Akira Matsuda
0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
Akira Matsuda
0d981a2b3d Let the generated initializers/backtrace_silencers.rb code use Regexp#match? 2019-07-29 14:21:30 +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
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
973096b6ae Correct test name 2019-05-20 13:59: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
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
George Claghorn
b2b6341374
Add ActionDispatch::SystemTestCase#fill_in_rich_text_area 2019-05-13 12:44:06 -04:00
George Claghorn
4222acf152 Update Webpacker in Action Text's test dummy app 2019-05-11 20:27:37 -04:00
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -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
Abhay Nikam
cfe30cee3e Adds a warning message for action text installer if application pack is missing. 2019-04-19 08:30:59 +05:30
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
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
Javan Makhmali
f1b8bb4e1f
Merge pull request #35485 from excid3/default-attachable-trix-partial
Adds default trix content attachmment partial path
2019-03-11 08:38:52 -07:00
Ryuta Kamizono
b7fa01bb2f
Merge pull request #35529 from abhaynikam/35492-follow-up-to-updates-links-to-https
Updated links from http to https in guides, docs, etc
2019-03-09 20:49:27 +09:00
Abhay Nikam
476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Sharang Dashputre
bf87dae202 Upgrade webpack-dev-server version in test apps 2019-03-09 03:35:22 +05:30
Sharang Dashputre
8eaffa1945 Use the latest stable release of webpacker 2019-03-09 00:14:17 +05:30
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
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
yuuji.yaginuma
90f853581a Disable available locale checks in Action Test test
Without this change, `store_translations` silently fails when available
locales already initialized.

Ref:
https://travis-ci.org/rails/rails/jobs/497615616#L6846
https://travis-ci.org/rails/rails/jobs/497605027#L6856
2019-02-24 14:01:52 +09: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
Ryuta Kamizono
da5843436b SQLite3: Implement add_foreign_key and remove_foreign_key
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.
2019-02-11 14:15:16 +09:00
Ryuta Kamizono
8309cd2c68
Merge pull request #35071 from kamipo/text_without_limit
MySQL: Support `:size` option to change text and blob size
2019-01-29 17:02:04 +09:00
Ryuta Kamizono
1745e905a3 Allow changing text and blob size without giving the limit option
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.
2019-01-29 06:49:32 +09:00
Ryuta Kamizono
b8baa15adb Revert "Apply t.timestamps changes in Action Text and Action Mailbox"
This reverts commit 30f666f87ab873258b797b39f29cf852f7621bea.
2019-01-29 06:37:42 +09:00
Ryuta Kamizono
30f666f87a Apply t.timestamps changes in Action Text and Action Mailbox
Follow up #34956.
2019-01-29 04:59:36 +09: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
Ryuta Kamizono
5a8f0c7226
Merge pull request #34970 from kamipo/timestamps_with_precision_by_default
Make `t.timestamps` with precision by default.
2019-01-26 23:37:17 +09:00
Ryuta Kamizono
57015cdfa2 Make t.timestamps with precision by default 2019-01-26 22:49:14 +09:00
Javan Makhmali
48c6ef9a72 Fix error saving Action Text content containing non-blob attachables
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>
```
2019-01-25 16:57:36 -05:00
George Claghorn
c1e949e9e6 Prefer ImageProcessing's resize_to_limit macro over resize_to_fit
Don't upsize images smaller than the specified dimensions.
2019-01-24 11:46:42 -05:00
colorbox
91fc859016 Fix document formatting on Action Text docs [ci skip]
Use `+` instead of backquote.
2019-01-24 17:44:35 +09:00
alkesh26
97909ddcf2 Changed webserver to web server. 2019-01-22 21:11:03 +05:30
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
Ryuta Kamizono
9e4283eb1d
Merge pull request #34956 from kamipo/actionmailbox_datetime_precision
Allow using Action Mailbox on MySQL 5.5
2019-01-18 09:56:57 +09:00
Kasper Timm Hansen
9aa0815192
Action Text: bundle package.json in built gem.
After 866da19fd9fc12d001ab99ac87890ea1cebb2cd9 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)
```
2019-01-18 00:11:18 +01:00
Ryuta Kamizono
db077e8090 Allow using Action Mailbox on MySQL 5.5
Active Record still support MySQL 5.5 which doesn't support datetime
with precision.

9e34df0003/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb (L99-L101)

So we should check `supports_datetime_with_precision?` on the
connection.
2019-01-18 07:04:08 +09:00
Javan Makhmali
866da19fd9 Tidy up action_text:install task
Automate installing the appropriate packages with yarn and appending them to the default application.js pack.
2019-01-17 10:42:09 -05:00
Javan Makhmali
11b73c40c2 Make trix a peer dependency of actiontext since it’s not used directly 2019-01-17 10:42:09 -05:00
Javan Makhmali
86b489e3d6 Move all npm packages to @rails scope
Fixes #33083
2019-01-10 11:01:57 -05:00
yuuji.yaginuma
5df737b7e8 Enable Lint/DeprecatedClassMethods cop to avoid using deprecated methods 2019-01-09 12:00:08 +09:00
Aaron Patterson
ae4f7b4a0a
Merge pull request #34898 from ksolo/update-raketasks-for-new-frameworks
Add new frameworks to `tasks/release.rb`
2019-01-08 10:47:24 -08:00
Kevin Solorio
ce90ded4ca add new frameworks to tasks/release.rb
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
2019-01-08 10:36:33 -08:00
George Claghorn
29bb990f97 Add load hook for ActionText::RichText 2019-01-07 17:04:58 -05:00
George Claghorn
02d2958b6c Reset ActionText::Content.renderer before and after each request 2019-01-05 16:59:54 -05:00
George Claghorn
a4c0157312
Merge pull request #34878 from bogdanvlviv/action_text-guides-docs
Add Action Text to guides [ci skip]
2019-01-05 11:04:21 -05:00
George Claghorn
7a88f649da
Merge pull request #34875 from bogdanvlviv/test-actiontext-on-rails-6.0
Test actiontext on Rails 6.0
2019-01-05 10:41:41 -05:00
George Claghorn
35ed21bc16
Merge pull request #34876 from bogdanvlviv/remove-needless-comment-actiontext.gemspec
Remove comment from `actiontext/actiontext.gemspec`
2019-01-05 10:41:08 -05:00
bogdanvlviv
67a9a86b1d
Test actiontext on Rails 6.0
- 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 2ae3a29508e.
- `rails/actiontext$ yarn install`
2019-01-05 15:24:27 +02:00
bogdanvlviv
0fb6c9011f
Add Action Text to guides [ci skip]
- 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
2019-01-05 13:30:37 +02:00
bogdanvlviv
b04b008b3d
Remove comment from actiontext/actiontext.gemspec
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.
2019-01-05 11:57:26 +02:00
bogdanvlviv
78ed534f30
Fix API docs of ActionText::RichText [ci skip]
This text should appear on the page
https://api.rubyonrails.org/v6.0/classes/ActionText/RichText.html

Related to 86517942e469193e8624d5078d718785552c1270
2019-01-05 11:01:47 +02:00
George Claghorn
86517942e4 Generate Action Text's API docs 2019-01-04 23:56:22 -05:00
George Claghorn
0decd2ddc4 Import Action Text 2019-01-04 22:22:49 -05:00