propshaft 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b03a78a54847aa4fb74c996259230818db5262c8c246367f4826dd222f763d62
4
- data.tar.gz: c393121a10fcb3cd1b151077869673260afdf99d4a7294dd88b8f600e3debe55
3
+ metadata.gz: e0c1e97b63b0b9fe76fa0a65a143ff7c705287fb342d1c414aedbb5cd4388b1c
4
+ data.tar.gz: 30c367753aa1ff0bdedacea3a5ac07b9c21a04f6da4610eb1a0336444c0a305b
5
5
  SHA512:
6
- metadata.gz: f2807deda69e1f1ddb336985b69c4f2f617398450402ca60de1917599f5e6a8ad5b483386ffcd85cd62f3729ff9fb16d7a2d487e39e15de160c29342d03d4ba1
7
- data.tar.gz: d16949bc2e7b81634d310413ea0f29065dfbe9eb4e421fb2321b9709ef460c82eaf93b2ab73d07de23dbd8111730d7755a1995081d8986d96ed28916940b8e94
6
+ metadata.gz: 9150cdb2117a008edb02f77426479bc7deeb2ce8bf6d4ba0541716862d2c49c17c3765e138dced1495b12bd25deb1f4f68e45fda78311d4acb9a720ba3ffaac4
7
+ data.tar.gz: af02249eceeefd87057bf69aca1780c04f74b31b705b61e0b4696f7b3a9e7ed363759612f85e1d5e0fe53a02659ff77e9769c3b375b16cfd9fa7b3ae93cdb4cb
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Propshaft
2
2
 
3
- Propshaft is an asset pipeline library for Rails. It's built for era where bundling assets to save on HTTP connections is no longer urgent, where JavaScript and CSS is either compiled by dedicated Node.js bundlers or served directly to the browsers, and where increases in bandwidth has made the need for minification less pressing. These factors allow for a dramatically simpler and faster asset pipeline compared to previous options, like Sprockets.
3
+ Propshaft is an asset pipeline library for Rails. It's built for an era where bundling assets to save on HTTP connections is no longer urgent, where JavaScript and CSS are either compiled by dedicated Node.js bundlers or served directly to the browsers, and where increases in bandwidth have made the need for minification less pressing. These factors allow for a dramatically simpler and faster asset pipeline compared to previous options, like Sprockets.
4
4
 
5
- So that's what Propshaft doesn't do. Here's what it actually does provide:
5
+ So that's what Propshaft doesn't do. Here's what it does provide:
6
6
 
7
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
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.
@@ -17,16 +17,16 @@ With Rails 7+, you can start a new application with propshaft using `rails new m
17
17
 
18
18
  ## Usage
19
19
 
20
- Propshaft makes all the assets from all the paths its been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of bundled assets.
20
+ Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.
21
21
 
22
- These assets can be referenced through their logical path using the normal helpers like `asset_path`, `image_tag`, `javascript_include_tag`, and all the other asset helper tags. These logical references are automatically converted into digest-aware paths in production when `assets:precompile` has been run (through a json mapping file found in `public/assets/.manifest.json`).
22
+ These assets can be referenced through their logical path using the normal helpers like `asset_path`, `image_tag`, `javascript_include_tag`, and all the other asset helper tags. These logical references are automatically converted into digest-aware paths in production when `assets:precompile` has been run (through a JSON mapping file found in `public/assets/.manifest.json`).
23
23
 
24
24
  Additionally, Propshaft ships with a CSS function called `asset-path("image.svg")` that'll be compiled into `url("/assets/image-f2e1ec14d6856e1958083094170ca6119c529a73.svg")` when doing `assets:precompile`. This function is applied to all `.css` files.
25
25
 
26
26
 
27
27
  ## Migrating from Sprockets
28
28
 
29
- Propshaft does a lot less than Sprockets, by design, so it might well be a fair bit of work to migrate, if it's even desirable. This is particularly true if you rely on Sprockets to provide any form of transpiling, like CoffeeScript or Sass, or if you rely on any gems that do. You'll need to either stop transpiling or use a Node-based transpiler, like those in `jsbundling-rails` and `cssbundling-rails`.
29
+ Propshaft does a lot less than Sprockets, by design, so it might well be a fair bit of work to migrate if it's even desirable. This is particularly true if you rely on Sprockets to provide any form of transpiling, like CoffeeScript or Sass, or if you rely on any gems that do. You'll need to either stop transpiling or use a Node-based transpiler, like those in `jsbundling-rails` and `cssbundling-rails`.
30
30
 
31
31
  On the other hand, if you're already bundling JavaScript and CSS through a Node-based setup, then Propshaft is going to slot in easily. Since you don't need another tool to bundle or transpile. Just to digest and serve.
32
32
 
@@ -11,8 +11,12 @@ class Propshaft::LoadPath
11
11
  assets_by_path[asset_name]
12
12
  end
13
13
 
14
- def assets
15
- assets_by_path.values
14
+ def assets(content_types: nil)
15
+ if content_types
16
+ assets_by_path.values.select { |asset| asset.content_type.in?(content_types) }
17
+ else
18
+ assets_by_path.values
19
+ end
16
20
  end
17
21
 
18
22
  def manifest
@@ -1,5 +1,6 @@
1
1
  class Propshaft::Processor
2
2
  MANIFEST_FILENAME = ".manifest.json"
3
+ COMPRESSABLE_CONTENT_TYPES = %i[ js css text json xml html svg otf ttf ].collect { |t| Mime[t] }
3
4
 
4
5
  attr_reader :load_path, :output_path, :compilers
5
6
 
@@ -41,10 +42,6 @@ class Propshaft::Processor
41
42
  compile_asset(asset) || copy_asset(asset)
42
43
  end
43
44
 
44
- def copy_asset(asset)
45
- FileUtils.copy asset.path, output_path.join(asset.digested_path)
46
- end
47
-
48
45
  def compile_asset(asset)
49
46
  File.open(output_path.join(asset.digested_path), "w+") do |file|
50
47
  begin
@@ -56,10 +53,13 @@ class Propshaft::Processor
56
53
  end if compilers.compilable?(asset)
57
54
  end
58
55
 
56
+ def copy_asset(asset)
57
+ FileUtils.copy asset.path, output_path.join(asset.digested_path)
58
+ end
59
+
59
60
 
60
61
  def compress_assets
61
- # FIXME: Only try to compress text assets with brotli
62
- load_path.assets.each do |asset|
62
+ load_path.assets(content_types: COMPRESSABLE_CONTENT_TYPES).each do |asset|
63
63
  compress_asset output_path.join(asset.digested_path)
64
64
  end if compressor_available?
65
65
  end
@@ -4,7 +4,7 @@ require "active_support/ordered_options"
4
4
 
5
5
  # FIXME: There's gotta be a better way than this hack?
6
6
  class Rails::Engine < Rails::Railtie
7
- initializer :append_assets_path, group: :all do |app|
7
+ initializer "propshaft.append_assets_path", group: :all do |app|
8
8
  app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
9
9
  app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
10
10
  app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
@@ -1,3 +1,3 @@
1
1
  module Propshaft
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/propshaft.rb CHANGED
@@ -1,3 +1,6 @@
1
+ module Propshaft
2
+ end
3
+
1
4
  require "propshaft/assembly"
2
5
  require "propshaft/helper"
3
6
  require "propshaft/railtie"
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.1
4
+ version: 0.1.5
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-21 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails