klenod-rack 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/klenod/rack/asset_app.rb +16 -4
- data/lib/klenod/rack/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f174f0692b93ef18d2d3e80f98f9d728b2fa6afcb1356adccec2b93234a3241
|
|
4
|
+
data.tar.gz: a3d5423c1cb1f2885bd07a4cd2c2114c36445f3604485a8e7eda41ee8b59388d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf0eee2068c7ffe800bff1f94f0f12aefd88e4463fc1d93f135c7cba5d1c775c77b6c94cb41c23a939c0b0ae927bd1d9849e670836bcb7aaacf7aa5e9ede4ced
|
|
7
|
+
data.tar.gz: d31adabf9589421525909d5d9b8a67607a7cefa9d019256b21f38ab737fe881bf360c5cd97c9d6611e20891015d2eeed86baeb06f82ab7d5b6db17b6680a9927
|
data/README.md
CHANGED
|
@@ -14,5 +14,10 @@ Use this gem when exposing Klenod assets from a Rack-compatible server:
|
|
|
14
14
|
```ruby
|
|
15
15
|
require "klenod/rack"
|
|
16
16
|
|
|
17
|
-
assets = Klenod::Rack::AssetApp.new(bundle, assets_dir: "public")
|
|
17
|
+
assets = Klenod::Rack::AssetApp.new(bundle, assets_dir: "public", base: bundle.base)
|
|
18
18
|
```
|
|
19
|
+
|
|
20
|
+
Assets are written directly under `assets_dir` using their root-relative output paths.
|
|
21
|
+
`AssetApp` maps an origin-relative build base such as `/assets/` or `/.assets/` to
|
|
22
|
+
those files. For an external base such as a CDN URL, use `path_prefix:` to choose
|
|
23
|
+
the local path it should serve.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "http/accept"
|
|
4
|
+
require "klenod/runtime/asset_url"
|
|
4
5
|
|
|
5
6
|
module Klenod
|
|
6
7
|
module Rack
|
|
@@ -19,14 +20,15 @@ module Klenod
|
|
|
19
20
|
class AssetApp
|
|
20
21
|
CACHE_CONTROL = "public, max-age=31536000, immutable"
|
|
21
22
|
|
|
22
|
-
def initialize(source, app: nil, assets_dir: nil, path_prefix: "/assets/")
|
|
23
|
+
def initialize(source, app: nil, assets_dir: nil, path_prefix: "/assets/", base: nil)
|
|
23
24
|
@source = source
|
|
24
25
|
@app = app
|
|
25
26
|
@assets_dir = assets_dir
|
|
26
|
-
@
|
|
27
|
+
@base = base && Runtime::AssetUrl.normalize(base)
|
|
28
|
+
@path_prefix = @base ? (Runtime::AssetUrl.path_prefix(@base) || path_prefix) : path_prefix
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
attr_reader :source, :app, :assets_dir, :path_prefix
|
|
31
|
+
attr_reader :source, :app, :assets_dir, :path_prefix, :base
|
|
30
32
|
|
|
31
33
|
def call(env)
|
|
32
34
|
response = response_for(env.fetch("PATH_INFO", ""), env)
|
|
@@ -39,7 +41,7 @@ module Klenod
|
|
|
39
41
|
def response_for(path, env = {})
|
|
40
42
|
return nil unless asset_path?(path)
|
|
41
43
|
|
|
42
|
-
asset =
|
|
44
|
+
asset = asset_for(asset_output_path(path))
|
|
43
45
|
brotli_available = brotli_asset_available?(asset)
|
|
44
46
|
compressed = brotli_available && accepts_brotli?(env.fetch("HTTP_ACCEPT_ENCODING", ""))
|
|
45
47
|
body = compressed ? brotli_asset_bytes(asset) : asset_bytes(asset)
|
|
@@ -70,6 +72,16 @@ module Klenod
|
|
|
70
72
|
path.start_with?(path_prefix)
|
|
71
73
|
end
|
|
72
74
|
|
|
75
|
+
def asset_output_path(path)
|
|
76
|
+
"/#{path.delete_prefix(path_prefix)}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def asset_for(output_path)
|
|
80
|
+
source.asset(output_path)
|
|
81
|
+
rescue KeyError
|
|
82
|
+
source.asset("#{Runtime::AssetUrl::LEGACY_OUTPUT_PREFIX}#{output_path.delete_prefix("/")}")
|
|
83
|
+
end
|
|
84
|
+
|
|
73
85
|
def asset_bytes(asset)
|
|
74
86
|
if source.respond_to?(:asset_bytes)
|
|
75
87
|
source.asset_bytes(asset.output_path, assets_dir: assets_dir)
|
data/lib/klenod/rack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.6
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.6
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: http-accept
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
requirements:
|
|
62
62
|
- - ">="
|
|
63
63
|
- !ruby/object:Gem::Version
|
|
64
|
-
version: 4.0
|
|
64
|
+
version: '4.0'
|
|
65
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
67
|
- - ">="
|