Sha256: eaa8b3bcb537fae42fb996e6b7fd91657177faa0e6fa3725e1f2a2772e0435c1

Contents?: true

Size: 701 Bytes

Versions: 15

Compression:

Stored size: 701 Bytes

Contents

module ViteInlineSvgFileLoader
  class << self
    def named(filename)
      vite = ViteRuby.instance
      vite_asset_path = vite.manifest.path_for(filename)

      if vite.dev_server_running?
        fetch_from_dev_server(vite_asset_path)
      else
        Rails.public_path.join(vite_asset_path.sub(%r{^/}, "")).read
      end
    end

    private

    def fetch_from_dev_server(path)
      config = ViteRuby.config
      dev_server_uri = URI("#{config.protocol}://#{config.host_with_port}#{path}")
      response = Net::HTTP.get_response(dev_server_uri)
      raise "Failed to load inline SVG from #{dev_server_uri}" unless response.is_a?(Net::HTTPSuccess)

      response.body
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nextgen-0.14.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.13.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.12.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.11.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.10.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.9.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.8.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.7.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.6.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.5.1 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.5.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.4.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.3.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.2.0 template/lib/vite_inline_svg_file_loader.rb
nextgen-0.1.0 template/lib/vite_inline_svg_file_loader.rb