lib/madmin/engine.rb in madmin-1.2.11 vs lib/madmin/engine.rb in madmin-2.0.0

- old
+ new

@@ -1,5 +1,7 @@ +require "importmap-rails" + module Madmin class Engine < ::Rails::Engine isolate_namespace Madmin config.before_configuration do |app| @@ -7,8 +9,26 @@ app.config.eager_load_paths << File.expand_path("app/madmin/fields", Rails.root) end config.to_prepare do Madmin.reset_resources! + Madmin.site_name ||= Rails.application.class.module_parent_name + end + + initializer "madmin.assets" do |app| + if app.config.respond_to?(:assets) + app.config.assets.paths << root.join("app/assets/stylesheets") + app.config.assets.paths << root.join("app/javascript") + app.config.assets.precompile += %w[madmin_manifest] + end + end + + initializer "madmin.importmap", before: "importmap" do |app| + Madmin.importmap.draw root.join("config/importmap.rb") + Madmin.importmap.cache_sweeper watches: root.join("app/javascript") + + ActiveSupport.on_load(:action_controller_base) do + before_action { Madmin.importmap.cache_sweeper.execute_if_updated } + end end end end