propshaft 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/propshaft/asset.rb +4 -0
- data/lib/propshaft/compilers/css_asset_urls.rb +21 -4
- data/lib/propshaft/compilers.rb +1 -1
- data/lib/propshaft/processor.rb +4 -0
- data/lib/propshaft/railtie.rb +5 -0
- data/lib/propshaft/server.rb +8 -7
- data/lib/propshaft/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32316706959e2a09f2ac10010fb76ddc25ddfab8ba6a8b06cfb71dc0e75c0deb
|
4
|
+
data.tar.gz: 1b6c3074c0a8f4c0d21287d6c27689bb443e7a58c18a690420f932709a244c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a8cfb18503c100507681ee4da2e76d8493898de8f79cfab01b7b640b92affed80ab3a135f7eb8514a53d2e6d11943e3500c6681ac879d14367fcfa5d5f8432f
|
7
|
+
data.tar.gz: c5e47f07a0d52306a11bb132f0ad7139b208eeb5cd9396d6274423b4de8b2deed013895107027ced61f4887d5aaeee413ae9e41065a74c022a4c4529572d4048
|
data/lib/propshaft/asset.rb
CHANGED
@@ -1,13 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Propshaft::Compilers::CssAssetUrls
|
2
4
|
attr_reader :assembly
|
3
5
|
|
6
|
+
ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
|
7
|
+
|
4
8
|
def initialize(assembly)
|
5
9
|
@assembly = assembly
|
6
10
|
end
|
7
11
|
|
8
|
-
def compile(input)
|
9
|
-
input.gsub(
|
10
|
-
%[url("#{assembly.config.prefix}/#{assembly.load_path.find($1).digested_path}")]
|
11
|
-
end
|
12
|
+
def compile(logical_path, input)
|
13
|
+
input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1) }
|
12
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def resolve_path(directory, filename)
|
18
|
+
if filename.start_with?("../")
|
19
|
+
Pathname.new(directory + filename).relative_path_from("").to_s
|
20
|
+
elsif filename.start_with?("/")
|
21
|
+
filename.delete_prefix("/").to_s
|
22
|
+
else
|
23
|
+
(directory + filename.delete_prefix("./")).to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def asset_url(resolved_path)
|
28
|
+
%[url("#{assembly.config.prefix}/#{assembly.load_path.find(resolved_path).digested_path}")]
|
29
|
+
end
|
13
30
|
end
|
data/lib/propshaft/compilers.rb
CHANGED
@@ -23,7 +23,7 @@ class Propshaft::Compilers
|
|
23
23
|
if relevant_registrations = registrations[asset.content_type.to_s]
|
24
24
|
asset.content.dup.tap do |input|
|
25
25
|
relevant_registrations.each do |compiler|
|
26
|
-
input.replace compiler.new(assembly).compile(input)
|
26
|
+
input.replace compiler.new(assembly).compile(asset.logical_path, input)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
else
|
data/lib/propshaft/processor.rb
CHANGED
data/lib/propshaft/railtie.rb
CHANGED
data/lib/propshaft/server.rb
CHANGED
@@ -8,16 +8,17 @@ class Propshaft::Server
|
|
8
8
|
def call(env)
|
9
9
|
path, digest = extract_path_and_digest(env)
|
10
10
|
|
11
|
-
if (asset = @assembly.load_path.find(path)) && asset.digest
|
11
|
+
if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)
|
12
12
|
compiled_content = @assembly.compilers.compile(asset)
|
13
13
|
|
14
14
|
[
|
15
15
|
200,
|
16
16
|
{
|
17
|
-
"Content-Length"
|
18
|
-
"Content-Type"
|
19
|
-
"
|
20
|
-
"
|
17
|
+
"Content-Length" => compiled_content.length.to_s,
|
18
|
+
"Content-Type" => asset.content_type.to_s,
|
19
|
+
"Accept-Encoding" => "Vary",
|
20
|
+
"ETag" => asset.digest,
|
21
|
+
"Cache-Control" => "public, max-age=31536000, immutable"
|
21
22
|
},
|
22
23
|
[ compiled_content ]
|
23
24
|
]
|
@@ -29,9 +30,9 @@ class Propshaft::Server
|
|
29
30
|
private
|
30
31
|
def extract_path_and_digest(env)
|
31
32
|
full_path = Rack::Utils.unescape(env["PATH_INFO"].to_s.sub(/^\//, ""))
|
32
|
-
digest = full_path[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
|
33
|
+
digest = full_path[/-([0-9a-f]{7,128})\.(?!digested)[^.]+\z/, 1]
|
33
34
|
path = digest ? full_path.sub("-#{digest}", "") : full_path
|
34
|
-
|
35
|
+
|
35
36
|
[ path, digest ]
|
36
37
|
end
|
37
38
|
end
|
data/lib/propshaft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propshaft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|