Skip to content

Commit 6ec669b

Browse files
author
David Heinemeier Hansson
authored
Action Text installer should assume importmap for asset pipeline (rails#43011)
* Action Text installer should assume importmap for asset pipeline * Fix test
1 parent a2cd0a5 commit 6ec669b

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

actiontext/lib/generators/action_text/install/install_generator.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ def append_javascript_dependencies
4444
end
4545
end
4646
else
47-
if (application_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
48-
insert_into_file application_layout_path.to_s, %(\n <%= javascript_include_tag "trix", "actiontext", "data-turbo-track": "reload", defer: true %>), before: /\s*<\/head>/
47+
if (application_javascript_path = Rails.root.join("app/assets/javascripts/application.js")).exist?
48+
insert_into_file application_javascript_path.to_s, %(\nimport "trix"\nimport "@rails/actiontext")
4949
else
5050
say <<~INSTRUCTIONS, :green
51-
You must add the actiontext.js and trix.js JavaScript files to the head of your application layout:
52-
53-
<%= javascript_include_tag "trix", "actiontext", "data-turbo-track": "reload", defer: true %>
51+
You must import the @rails/actiontext.js and trix.js JavaScript files in your application entrypoint.
5452
INSTRUCTIONS
5553
end
5654
end

railties/test/generators/action_text_install_generator_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ class ActionText::Generators::InstallGeneratorTest < Rails::Generators::TestCase
103103
test "run just for asset pipeline" do
104104
run_under_asset_pipeline
105105

106-
application_layout = Pathname("app/views/layouts/application.html.erb").expand_path(destination_root)
107-
application_layout.dirname.mkpath
108-
application_layout.write("</head>\n")
106+
application_js = Pathname("app/assets/javascripts/application.js").expand_path(destination_root)
107+
application_js.dirname.mkpath
108+
application_js.write ""
109109

110110
run_generator_instance
111111

112-
assert_file application_layout do |content|
112+
assert_file application_js do |content|
113113
assert_match %r"trix", content
114114
end
115115
end

0 commit comments

Comments
 (0)