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


8
9
10
# File 'lib/react/server_rendering/yaml_manifest_container.rb', line 8

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

Class Method Details

.compatible?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/react/server_rendering/yaml_manifest_container.rb', line 17

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

Instance Method Details

#find_asset(logical_path) ⇒ Object


12
13
14
15
# File 'lib/react/server_rendering/yaml_manifest_container.rb', line 12

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