Skip to content

Commit a53538a

Browse files
committed
feat(SprocketsRenderer) support a custom asset container
1 parent 2382989 commit a53538a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/react/server_rendering/sprockets_renderer.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,24 @@ def after_render(component_name, props, prerender_options)
4242
@replay_console ? CONSOLE_REPLAY : ""
4343
end
4444

45-
# Given an asset name, return the fully-compiled body of that asset.
45+
class << self
46+
attr_accessor :asset_container_class
47+
end
48+
49+
# Get an object which exposes assets by their logical path.
4650
#
4751
# Out of the box, it supports a Sprockets::Environment (application.assets)
4852
# and a Sprockets::Manifest (application.assets_manifest), which covers the
4953
# default Rails setups.
5054
#
51-
# TODO: what if the assets aren't on the local server (maybe they're on a CDN?)
52-
# Can we check for asset_host configuration here?
55+
# You can provide a custom asset container
56+
# with `React::ServerRendering::SprocketsRender.asset_container_class = MyAssetContainer`.
5357
#
5458
# @return [#find_asset(logical_path)] An object that returns asset contents by logical path
5559
def asset_container
56-
@asset_container ||= if ::Rails.application.config.assets.compile
60+
@asset_container ||= if self.class.asset_container_class.present?
61+
self.class.asset_container_class.new
62+
elsif ::Rails.application.config.assets.compile
5763
EnvironmentContainer.new
5864
else
5965
ManifestContainer.new

0 commit comments

Comments
 (0)