diff --git a/README.md b/README.md index 84035c6..d205f1f 100644 --- a/README.md +++ b/README.md @@ -656,6 +656,17 @@ end Rails.configuration.middleware.insert_before AnotherMiddleware, Rodauth::Rails::Middleware ``` +### Skipping Tilt + +Rodauth uses the [Tilt] gem to render built-in view & email templates. If you don't want to have Tilt as a dependency, you can disable it, provided that you've imported all view & email templates into your app: + +```rb +# config/initializers/rodauth.rb +Rodauth::Rails.configure do |config| + config.tilt = false # skip loading Tilt gem +end +``` + ## How it works ### Rack middleware diff --git a/lib/generators/rodauth/templates/config/initializers/rodauth.rb.tt b/lib/generators/rodauth/templates/config/initializers/rodauth.rb.tt index a832109..99874f4 100644 --- a/lib/generators/rodauth/templates/config/initializers/rodauth.rb.tt +++ b/lib/generators/rodauth/templates/config/initializers/rodauth.rb.tt @@ -1,3 +1,5 @@ Rodauth::Rails.configure do |config| config.app = "RodauthApp" + # config.middleware = false # disable auto-insertion of Rodauth middleware + # config.tilt = false # skip loading Tilt gem for rendering built-in templates end diff --git a/lib/rodauth/rails.rb b/lib/rodauth/rails.rb index 599ea8d..54d74cf 100644 --- a/lib/rodauth/rails.rb +++ b/lib/rodauth/rails.rb @@ -12,9 +12,6 @@ class Error < StandardError autoload :Auth, "rodauth/rails/auth" autoload :Mailer, "rodauth/rails/mailer" - @app = nil - @middleware = true - class << self def lib(**options, &block) c = Class.new(Rodauth::Rails::App) @@ -80,8 +77,13 @@ def configure yield self end + @app = nil + @middleware = true + @tilt = true + attr_writer :app attr_writer :middleware + attr_writer :tilt def app fail Rodauth::Rails::Error, "app was not configured" unless @app @@ -92,6 +94,10 @@ def app def middleware? @middleware end + + def tilt? + @tilt + end end end end diff --git a/lib/rodauth/rails/app.rb b/lib/rodauth/rails/app.rb index ad91443..c0d6357 100644 --- a/lib/rodauth/rails/app.rb +++ b/lib/rodauth/rails/app.rb @@ -9,7 +9,7 @@ class App < Roda plugin :hooks plugin :pass - def self.configure(*args, **options, &block) + def self.configure(*args, render: Rodauth::Rails.tilt?, **options, &block) auth_class = args.shift if args[0].is_a?(Class) auth_class ||= Class.new(Rodauth::Rails::Auth) name = args.shift if args[0].is_a?(Symbol) @@ -17,9 +17,9 @@ def self.configure(*args, **options, &block) fail ArgumentError, "need to pass optional Rodauth::Auth subclass and optional configuration name" if args.any? # we'll render Rodauth's built-in view templates within Rails layouts - plugin :render, layout: false unless options[:render] == false + plugin :render, layout: false unless render == false - plugin :rodauth, auth_class: auth_class, name: name, csrf: false, flash: false, json: true, **options, &block + plugin :rodauth, auth_class: auth_class, name: name, csrf: false, flash: false, json: true, render: render, **options, &block # we need to do it after request methods from rodauth have been included self::RodaRequest.include RequestMethods