-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
bridgetown_ssr.rb
34 lines (28 loc) · 944 Bytes
/
bridgetown_ssr.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true
class Roda
module RodaPlugins
module BridgetownSSR
module InstanceMethods
# Helper to get the site associated with the Roda app
# @return [Bridgetown::Site]
def bridgetown_site
self.class.opts[:bridgetown_site]
end
alias_method :site, :bridgetown_site
end
def self.load_dependencies(app)
app.plugin :custom_block_results
# This lets us return callable objects directly in Roda response blocks
app.handle_block_result(Bridgetown::RodaCallable) do |callable|
callable.(self)
end
end
def self.configure(app, _opts = {}, &)
app.include Bridgetown::Filters::URLFilters
app.opts[:bridgetown_site] =
Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &)
end
end
register_plugin :bridgetown_ssr, BridgetownSSR
end
end