Class: React::ServerRendering::ManifestContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/react/server_rendering/manifest_container.rb

Overview

Get asset content by reading the compiled file from disk using a Sprockets::Manifest.

This is good for Rails production when assets are compiled to public/assets but sometimes, they’re compiled to other directories (or other servers)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManifestContainer

Returns a new instance of ManifestContainer.



10
11
12
# File 'lib/react/server_rendering/manifest_container.rb', line 10

def initialize
  @manifest = ::Rails.application.assets_manifest
end

Class Method Details

.compatible?Boolean

sprockets-rails < 2.2.2 does not have ‘application.assets_manifest`

Returns:

  • (Boolean)


23
24
25
# File 'lib/react/server_rendering/manifest_container.rb', line 23

def self.compatible?
  ::Rails.application.respond_to?(:assets_manifest)
end

Instance Method Details

#find_asset(logical_path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/react/server_rendering/manifest_container.rb', line 14

def find_asset(logical_path)
  asset_path = @manifest.assets[logical_path] || raise(
    "No compiled asset for #{logical_path}, was it precompiled?"
  )
  asset_full_path = ::Rails.root.join("public", @manifest.dir, asset_path)
  File.read(asset_full_path)
end