Skip to content

Commit afae9d0

Browse files
committed
Add dedicated configuration for skipping Tilt
Having to pass `render: false` when registering Rodauth configurations can be a bit awkward when the developer isn't otherwise exposed with Rodauth being a Roda plugin. Moreover, it can be cumbersome, because it needs to be passed for every Rodauth configuration. Having dedicated configuration makes it much more straighforward to skip Tilt, and this way it doesn't get mixed with things that actually affect authentication behavior or calling Rodauth methods.
1 parent c118003 commit afae9d0

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,17 @@ end
656656
Rails.configuration.middleware.insert_before AnotherMiddleware, Rodauth::Rails::Middleware
657657
```
658658

659+
### Skipping Tilt
660+
661+
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:
662+
663+
```rb
664+
# config/initializers/rodauth.rb
665+
Rodauth::Rails.configure do |config|
666+
config.tilt = false # skip loading Tilt gem
667+
end
668+
```
669+
659670
## How it works
660671

661672
### Rack middleware
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Rodauth::Rails.configure do |config|
22
config.app = "RodauthApp"
3+
# config.middleware = false # disable auto-insertion of Rodauth middleware
4+
# config.tilt = false # skip loading Tilt gem for rendering built-in templates
35
end

lib/rodauth/rails.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ class Error < StandardError
1212
autoload :Auth, "rodauth/rails/auth"
1313
autoload :Mailer, "rodauth/rails/mailer"
1414

15-
@app = nil
16-
@middleware = true
17-
1815
class << self
1916
def lib(**options, &block)
2017
c = Class.new(Rodauth::Rails::App)
@@ -80,8 +77,13 @@ def configure
8077
yield self
8178
end
8279

80+
@app = nil
81+
@middleware = true
82+
@tilt = true
83+
8384
attr_writer :app
8485
attr_writer :middleware
86+
attr_writer :tilt
8587

8688
def app
8789
fail Rodauth::Rails::Error, "app was not configured" unless @app
@@ -92,6 +94,10 @@ def app
9294
def middleware?
9395
@middleware
9496
end
97+
98+
def tilt?
99+
@tilt
100+
end
95101
end
96102
end
97103
end

lib/rodauth/rails/app.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class App < Roda
99
plugin :hooks
1010
plugin :pass
1111

12-
def self.configure(*args, **options, &block)
12+
def self.configure(*args, render: Rodauth::Rails.tilt?, **options, &block)
1313
auth_class = args.shift if args[0].is_a?(Class)
1414
auth_class ||= Class.new(Rodauth::Rails::Auth)
1515
name = args.shift if args[0].is_a?(Symbol)
1616

1717
fail ArgumentError, "need to pass optional Rodauth::Auth subclass and optional configuration name" if args.any?
1818

1919
# we'll render Rodauth's built-in view templates within Rails layouts
20-
plugin :render, layout: false unless options[:render] == false
20+
plugin :render, layout: false unless render == false
2121

22-
plugin :rodauth, auth_class: auth_class, name: name, csrf: false, flash: false, json: true, **options, &block
22+
plugin :rodauth, auth_class: auth_class, name: name, csrf: false, flash: false, json: true, render: render, **options, &block
2323

2424
# we need to do it after request methods from rodauth have been included
2525
self::RodaRequest.include RequestMethods

0 commit comments

Comments
 (0)