Class: React::ServerRendering::YamlManifestContainer

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

Overview

Get asset content by reading the compiled file from disk using the generated manifest.yml file

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

#initializeYamlManifestContainer

Returns a new instance of YamlManifestContainer.



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

def initialize
  @assets = YAML.load_file(public_asset_path("manifest.yml"))
end

Class Method Details

.compatible?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/react/server_rendering/yaml_manifest_container.rb', line 19

def self.compatible?
  ::Rails::VERSION::MAJOR == 3
end

Instance Method Details

#find_asset(logical_path) ⇒ Object



14
15
16
17
# File 'lib/react/server_rendering/yaml_manifest_container.rb', line 14

def find_asset(logical_path)
  asset_path = @assets[logical_path] || raise("No compiled asset for #{logical_path}, was it precompiled?")
  File.read(public_asset_path(asset_path))
end