Sha256: 3d5525abf76c61374edbf9536a957e9737bd9dc23267b7b9ab7f470092d0243b

Contents?: true

Size: 1.48 KB

Versions: 15

Compression:

Stored size: 1.48 KB

Contents

require 'react/server_rendering/environment_container'
require 'react/server_rendering/manifest_container'
require 'react/server_rendering/webpacker_manifest_container'

module ReactiveRuby
  module ServerRendering
    class HyperTestAssetContainer
      def find_asset(logical_path)
        ::Rails.cache.read(logical_path)
      end
    end

    class HyperAssetContainer
      def initialize
        @ass_containers = []
        if assets_precompiled?
          @ass_containers << React::ServerRendering::ManifestContainer.new if React::ServerRendering::ManifestContainer.compatible?
        else
          @ass_containers << React::ServerRendering::EnvironmentContainer.new if ::Rails.application.assets
        end
        if React::ServerRendering::WebpackerManifestContainer.compatible?
          @ass_containers << React::ServerRendering::WebpackerManifestContainer.new
        end
        @ass_containers << HyperTestAssetContainer.new  if ::Rails.env.test?
      end

      def find_asset(logical_path)
        @ass_containers.each do |ass|
          begin
            asset = ass.find_asset(logical_path)
            return asset if asset && asset != ''
          rescue
            next # no asset found, try the next container
          end
        end
        raise "No asset found for #{logical_path}, tried: #{@ass_containers.map { |c| c.class.name }.join(', ')}"
      end

      private

      def assets_precompiled?
        !::Rails.application.config.assets.compile
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
hyper-component-0.99.6 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.5 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.4 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.3 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.2 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.1 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-component-0.99.0 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap28 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap27 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap26 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap25 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap24 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap23 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap22 lib/reactive-ruby/server_rendering/hyper_asset_container.rb
hyper-react-1.0.0.lap21 lib/reactive-ruby/server_rendering/hyper_asset_container.rb