diff --git a/README.md b/README.md index b0bb779..c74db61 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,21 @@ Mount the engine in your `routes.rb`: mount Audits1984::Engine => "/console" ``` +### API-only apps or apps using `vite_rails` and other asset pipelines outside Rails + +If you want to use this gem with an [API-only Rails app](https://guides.rubyonrails.org/api_app.html) or an app that's using `vite_ruby`/`vite_rails`, or some other custom asset pipeline different from Sprockets and Propshaft, you need just one more thing: configure an asset pipeline so you can serve the JavaScript and CSS included in this gem. We recommend to use [`Propshaft`](https://github.com/rails/propshaft). You simply need to add this line to your application's Gemfile: + +```ruby +gem "propshaft" +``` + +Then execute +```bash +$ bundle install +``` + +And you should be ready to go. + ### Authenticate auditors By default, the library controllers will inherit from the host application's `ApplicationController`. To authenticate auditors, you need to implement a method `#find_current_auditor` in your `ApplicationController`. This method must return a record representing the auditing user. It can be any model but it has to respond to `#name`. diff --git a/app/controllers/audits1984/application_controller.rb b/app/controllers/audits1984/application_controller.rb index 7ec2eae..b308d5b 100644 --- a/app/controllers/audits1984/application_controller.rb +++ b/app/controllers/audits1984/application_controller.rb @@ -1,9 +1,16 @@ module Audits1984 class ApplicationController < Audits1984.base_controller_class.constantize + ActionController::Base::MODULES.each do |mod| + include mod unless self < mod + end + before_action :authenticate_auditor layout "audits1984/application" + helper Audits1984::ApplicationHelper unless self < Audits1984::ApplicationHelper + helper Importmap::ImportmapTagsHelper unless self < Importmap::ImportmapTagsHelper + private def authenticate_auditor unless respond_to?(:find_current_auditor, true) diff --git a/audits1984.gemspec b/audits1984.gemspec index 77ad938..490869b 100644 --- a/audits1984.gemspec +++ b/audits1984.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |spec| spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] spec.add_dependency "rouge" - spec.add_dependency "turbo-rails" spec.add_dependency "importmap-rails", ">= 1.2.1" + spec.add_dependency "turbo-rails" spec.add_dependency "rinku" spec.add_dependency "console1984" diff --git a/lib/audits1984/engine.rb b/lib/audits1984/engine.rb index c2ec11c..eb01dff 100644 --- a/lib/audits1984/engine.rb +++ b/lib/audits1984/engine.rb @@ -7,6 +7,13 @@ module Audits1984 class Engine < ::Rails::Engine isolate_namespace Audits1984 + initializer "audits1984.middleware" do |app| + if app.config.api_only + app.middleware.use ActionDispatch::Flash + app.middleware.use ::Rack::MethodOverride + end + end + config.audits1984 = ActiveSupport::OrderedOptions.new initializer "audits1984.config" do