-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: better engine mounting #3533
base: main
Are you sure you want to change the base?
Changes from 11 commits
69e0f5a
80f4850
9c17530
7e3004c
c4a3288
8e03308
286496b
d3d8144
8f74693
ed1bfa5
59d2000
a3cf5ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ class Configuration | |
attr_accessor :resources | ||
attr_accessor :prefix_path | ||
attr_accessor :resource_parent_controller | ||
attr_accessor :mount_avo_engines | ||
attr_accessor :default_url_options | ||
attr_accessor :click_row_to_view_record | ||
attr_accessor :alert_dismiss_time | ||
|
@@ -112,7 +111,6 @@ def initialize | |
@field_wrapper_layout = :inline | ||
@resources = nil | ||
@resource_parent_controller = "Avo::ResourcesController" | ||
@mount_avo_engines = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a setter method to raise an error with docs link. |
||
@cache_store = computed_cache_store | ||
@logger = default_logger | ||
@turbo = default_turbo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ class Engine < ::Rails::Engine | |
isolate_namespace Avo | ||
|
||
config.after_initialize do | ||
# This callback is triggered 2 times | ||
# This flag check will avoid to re-execute the logic | ||
next if @already_initialized | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this in production. |
||
@already_initialized = true | ||
|
||
# Reset before reloads in development | ||
::Avo.asset_manager.reset | ||
|
||
|
@@ -39,12 +44,6 @@ class Engine < ::Rails::Engine | |
end | ||
end | ||
|
||
# Ensure we reboot the app when something changes | ||
config.to_prepare do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we still need this for reloading the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's run this only in development |
||
# Boot Avo | ||
::Avo.boot | ||
end | ||
|
||
initializer "avo.autoload" do |app| | ||
# This undoes Rails' previous nested directories behavior in the `app` dir. | ||
# More on this: https://github.com/fxn/zeitwerk/issues/250 | ||
|
@@ -59,6 +58,17 @@ class Engine < ::Rails::Engine | |
app.config.watchable_dirs[directory_path] = [:rb] | ||
end | ||
end | ||
|
||
# Add the mount_avo method to Rails | ||
ActionDispatch::Routing::Mapper.include(Module.new { | ||
def mount_avo(at: Avo.configuration.root_path, **options) | ||
Paul-Bob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mount Avo::Engine, at:, **options | ||
Paul-Bob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Avo.plugin_manager.engines.each do |engine| | ||
mount engine[:klass], at: "#{at}/#{engine[:options].delete(:at)}", **engine[:options] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need comments with examples. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And maybe use |
||
end | ||
end | ||
}) | ||
end | ||
|
||
initializer "avo.reloader" do |app| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,6 @@ Avo.configure do |config| | |
# used only when you have custom `map` configuration in your config.ru | ||
# config.prefix_path = "/internal" | ||
|
||
# Sometimes you might want to mount Avo's engines yourself. | ||
# https://docs.avohq.io/3.0/routing.html | ||
# config.mount_avo_engines = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should still be here with a warning that it's not working anymore. Maybe |
||
|
||
# Where should the user be redirected when visiting the `/<%= options[:path] %>` url | ||
# config.home_path = nil | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. Raise and error with docs links.