-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to add to Alchemy's importmap from Rails application
Rails applications are technically engines, but not really. For example the `engine_name` is the `config/application.rb` modularized class name. Which makes it not nice for this interface from an app developers perspective. Let's make the interface more explicit by using a options hash with readable keys. Rails.application.config.before_initialize do Alchemy.admin_importmaps.add({ importmap_path: Rails.application.root.join("config/alchemy/importmap.rb"), source_paths: [ Rails.application.root.join("app/javascript/components/product_select.js") ], name: "product_select" }) end
- Loading branch information
Showing
5 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Alchemy do | ||
describe ".admin_importmaps" do | ||
subject { Alchemy.admin_importmaps } | ||
|
||
it "returns a Set of admin importmaps" do | ||
is_expected.to be_a(Set) | ||
end | ||
|
||
it "includes alchemy_admin importmap" do | ||
expect(subject.first).to eq({ | ||
importmap_path: Alchemy::Engine.root.join("config/importmap.rb"), | ||
name: "alchemy_admin", | ||
source_paths: [ | ||
Alchemy::Engine.root.join("app/javascript"), | ||
Alchemy::Engine.root.join("vendor/javascript") | ||
] | ||
}) | ||
end | ||
|
||
context "with additional importmaps" do | ||
before do | ||
Alchemy.admin_importmaps.add({ | ||
importmap_path: Rails.root.join("config/importmap.rb"), | ||
name: "additional_importmap", | ||
source_paths: [Rails.root.join("app/javascript")] | ||
}) | ||
end | ||
|
||
it "adds additional importmap to admin imports" do | ||
initializer = Alchemy::Engine.initializers.find { _1.name == "alchemy.importmap" } | ||
expect(Alchemy.admin_js_imports).to receive(:add).with("additional_importmap") | ||
initializer.run(Rails.application) | ||
end | ||
end | ||
end | ||
end |