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 maniftest.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(::Rails.root.join("public", ::Rails.application.config.assets.prefix, "manifest.yml"))
end

Class Method Details

.compatible?Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#find_asset(logical_path) ⇒ Object



12
13
14
15
16
# 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?")
  asset_full_path = ::Rails.root.join("public", ::Rails.application.config.assets.prefix, asset_path)
  File.read(asset_full_path)
end