propshaft 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eb4dab520f6e9bc958d7ea65ed10531ab418ac34c3daefdcec0b4d61094bcdd
4
- data.tar.gz: 8d76024de20625ee78b0cc8409a2e74b66ac0ccd8203ba14e263d89b649da21d
3
+ metadata.gz: b03a78a54847aa4fb74c996259230818db5262c8c246367f4826dd222f763d62
4
+ data.tar.gz: c393121a10fcb3cd1b151077869673260afdf99d4a7294dd88b8f600e3debe55
5
5
  SHA512:
6
- metadata.gz: 5f8fbd11cd6a8a9031be35139887e1cec8e3823a4eb68e79ad61df91a307aa1222927fd8d87316c6b55df979cdd91f57bc4d653e092190a1b7933db175e44f14
7
- data.tar.gz: 70a5ad6e8382e5dafc4bed6b26e1f9ba5008f6bd536961393b807cbb47580dbfc95c1c1cbe04b1b4954968213c2aa112ed822e156fe8f044209bade7ccc79de8
6
+ metadata.gz: f2807deda69e1f1ddb336985b69c4f2f617398450402ca60de1917599f5e6a8ad5b483386ffcd85cd62f3729ff9fb16d7a2d487e39e15de160c29342d03d4ba1
7
+ data.tar.gz: d16949bc2e7b81634d310413ea0f29065dfbe9eb4e421fb2321b9709ef460c82eaf93b2ab73d07de23dbd8111730d7755a1995081d8986d96ed28916940b8e94
data/README.md CHANGED
@@ -4,10 +4,10 @@ Propshaft is an asset pipeline library for Rails. It's built for era where bundl
4
4
 
5
5
  So that's what Propshaft doesn't do. Here's what it actually does provide:
6
6
 
7
- 1. Configurable load path: You can register directories from multiple places in your app and gems, and reference assets from all of these paths as though they were one.
8
- 1. Digest processing: All assets in the load path will be copied (or compiled) in a precompilation step for production that also stamps all of them with a digest hash, so you can use long-expiry cache headers for better performance. The digested assets can be referred to through their logical path because the processing leaves a manifest file that provides a way to translate.
9
- 1. Development server: There's no need to precompile the assets in development. You can refer to them via the same asset_path helpers and they'll be served by a development server.
10
- 1. Basic compiler step: Propshaft was explicitly not designed to provide full transpiler capabilities. You can get that better elsewhere. But it does offer a simple input->output compiler setup that by default is used to translate `asset-path` function calls in CSS to `url(digested-asset)` instead.
7
+ 1. **Configurable load path**: You can register directories from multiple places in your app and gems, and reference assets from all of these paths as though they were one.
8
+ 1. **Digest stamping**: All assets in the load path will be copied (or compiled) in a precompilation step for production that also stamps all of them with a digest hash, so you can use long-expiry cache headers for better performance. The digested assets can be referred to through their logical path because the processing leaves a manifest file that provides a way to translate.
9
+ 1. **Development server**: There's no need to precompile the assets in development. You can refer to them via the same asset_path helpers and they'll be served by a development server.
10
+ 1. **Basic compilers**: Propshaft was explicitly not designed to provide full transpiler capabilities. You can get that better elsewhere. But it does offer a simple input->output compiler setup that by default is used to translate `asset-path` function calls in CSS to `url(digested-asset)` instead.
11
11
 
12
12
 
13
13
  ## Installation
@@ -7,7 +7,7 @@ class Propshaft::Compilers::CssAssetUrls
7
7
 
8
8
  def compile(input)
9
9
  input.gsub(/asset-path\(["']([^"')]+)["']\)/) do |match|
10
- %[url("/#{assembly.config.prefix}/#{assembly.load_path.find($1).digested_path}")]
10
+ %[url("#{assembly.config.prefix}/#{assembly.load_path.find($1).digested_path}")]
11
11
  end
12
12
  end
13
13
  end
@@ -18,15 +18,6 @@ module Propshaft
18
18
  config.assets.prefix = "/assets"
19
19
  config.assets.compilers = [ [ "text/css", Propshaft::Compilers::CssAssetUrls ] ]
20
20
 
21
- # Compatibility shiming (need to provide log warnings when used)
22
- config.assets.precompile = []
23
- config.assets.debug = nil
24
- config.assets.quiet = nil
25
- config.assets.compile = nil
26
- config.assets.version = nil
27
- config.assets.css_compressor = nil
28
- config.assets.js_compressor = nil
29
-
30
21
  config.after_initialize do |app|
31
22
  config.assets.output_path ||=
32
23
  Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))
@@ -50,5 +41,14 @@ module Propshaft
50
41
  end
51
42
  end
52
43
  end
44
+
45
+ # Compatibility shiming (need to provide log warnings when used)
46
+ config.assets.precompile = []
47
+ config.assets.debug = nil
48
+ config.assets.quiet = nil
49
+ config.assets.compile = nil
50
+ config.assets.version = nil
51
+ config.assets.css_compressor = nil
52
+ config.assets.js_compressor = nil
53
53
  end
54
54
  end
@@ -8,7 +8,7 @@ module Propshaft::Resolver
8
8
 
9
9
  def resolve(logical_path)
10
10
  if asset = load_path.find(logical_path)
11
- File.join prefix, asset.logical_path
11
+ File.join prefix, asset.digested_path
12
12
  end
13
13
  end
14
14
  end
@@ -6,7 +6,9 @@ class Propshaft::Server
6
6
  end
7
7
 
8
8
  def call(env)
9
- if asset = @assembly.load_path.find(requested_path(env))
9
+ path, digest = extract_path_and_digest(env)
10
+
11
+ if (asset = @assembly.load_path.find(path)) && asset.digest == digest
10
12
  compiled_content = @assembly.compilers.compile(asset)
11
13
 
12
14
  [
@@ -15,7 +17,7 @@ class Propshaft::Server
15
17
  "Content-Length" => compiled_content.length.to_s,
16
18
  "Content-Type" => asset.content_type,
17
19
  "ETag" => asset.digest,
18
- "Cache-Control" => "public, must-revalidate"
20
+ "Cache-Control" => "public, max-age=31536000, immutable"
19
21
  },
20
22
  [ compiled_content ]
21
23
  ]
@@ -25,7 +27,11 @@ class Propshaft::Server
25
27
  end
26
28
 
27
29
  private
28
- def requested_path(env)
29
- Rack::Utils.unescape(env["PATH_INFO"].to_s.sub(/^\//, ""))
30
+ def extract_path_and_digest(env)
31
+ full_path = Rack::Utils.unescape(env["PATH_INFO"].to_s.sub(/^\//, ""))
32
+ digest = full_path[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
33
+ path = digest ? full_path.sub("-#{digest}", "") : full_path
34
+
35
+ [ path, digest ]
30
36
  end
31
37
  end
@@ -1,3 +1,3 @@
1
1
  module Propshaft
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.1.0
4
+ version: 0.1.1
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-09-19 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails