sprockets-rails 2.3.3 → 3.4.2

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
- SHA1:
3
- metadata.gz: ce070066edd25fc773120801099deaa44cbab0a8
4
- data.tar.gz: 0ae39779bf56111b665205168d7b4daebd47ea94
2
+ SHA256:
3
+ metadata.gz: 73feab57944f69ac95583179fd64af5d7e927b6e352260ce8d061e95b2dbdfd8
4
+ data.tar.gz: 4cec001efd7cd64ee755114ccdaa80dac093abf39efd0e982223329508e3ddb1
5
5
  SHA512:
6
- metadata.gz: 4032a379c2a1d87b5d28e2be7119c628aaf36814fc0d34c717068fc91b59b69af7ed979107f0c47d37aad0c42e485ade12b688cd8ea562ca2bfbdceb5daa75c4
7
- data.tar.gz: b32fc1c142d819cf55b734fda999b7a55f88d1ce7a164f6417ff6839f3acb15fe00a38004b6507dc867e50ffabcb186ca4e73e80f53be6b5f61068c2a2e3987c
6
+ metadata.gz: 551eeb4f6d09b58157c6fbe2797f4e7ec69dde50cb9a160862e75cd2fe73063e1935582e3bf69533a835d3045d8562ce73de636caa89320e0d1a8b19cb875326
7
+ data.tar.gz: 2ea2f80c41a29207772023a344a5404d0aeae3c32987c5dae511f7941637a3ac744e02d66681d667e1b583fe91b2b606c43ab708436766cf708a76408628cb42
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Joshua Peek
1
+ Copyright (c) 2014-2016 Joshua Peek
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -27,7 +27,7 @@ Only removes old assets (keeps the most recent 3 copies) from `public/assets`. U
27
27
 
28
28
  **`rake assets:clobber`**
29
29
 
30
- Nuke `public/assets` and clear the Sprockets file system cache.
30
+ Nuke `public/assets`.
31
31
 
32
32
  #### Customize
33
33
 
@@ -37,11 +37,6 @@ You can also redefine the task with the built in task generator.
37
37
 
38
38
  ``` ruby
39
39
  require 'sprockets/rails/task'
40
- # clean the old tasks
41
- Rake::Task["assets:environment"].clear
42
- Rake::Task["assets:precompile"].clear
43
- Rake::Task["assets:clean"].clear
44
- Rake::Task["assets:clobber"].clear
45
40
  Sprockets::Rails::Task.new(Rails.application) do |t|
46
41
  t.environment = lambda { Rails.application.assets }
47
42
  t.assets = %w( application.js application.css )
@@ -51,23 +46,25 @@ end
51
46
 
52
47
  Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
53
48
 
54
- Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb).
55
-
49
+ Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/rails/sprockets/blob/master/lib/rake/sprocketstask.rb).
56
50
 
57
51
  ### Initializer options
58
52
 
59
- **`config.assets.precompile`**
53
+ **`config.assets.unknown_asset_fallback`**
60
54
 
61
- Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
55
+ When set to a truthy value, a result will be returned even if the requested asset is not found in the asset pipeline. When set to a falsey value it will raise an error when no asset is found in the pipeline. Defaults to `true`.
62
56
 
63
- **`config.assets.raise_runtime_errors`**
57
+ **`config.assets.precompile`**
64
58
 
65
- Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`.
59
+ Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
66
60
 
67
61
  **`config.assets.paths`**
68
62
 
69
63
  Add additional load paths to this Array. Rails includes `app/assets`, `lib/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to this.
70
64
 
65
+ **`config.assets.quiet`**
66
+
67
+ Suppresses logger output for asset requests. Uses the `config.assets.prefix` path to match asset requests. Defaults to `false`.
71
68
 
72
69
  **`config.assets.version`**
73
70
 
@@ -83,21 +80,17 @@ config.assets.version = 'v2'
83
80
 
84
81
  Defaults to `/assets`. Changes the directory to compile assets to.
85
82
 
86
- **`config.assets.manifest`**
87
-
88
- Defines the full path to be used for the asset precompiler's manifest file. Defaults to a randomly-generated filename in the `config.assets.prefix` directory within the public folder.
89
-
90
83
  **`config.assets.digest`**
91
84
 
92
- Link to undigest asset filenames. This option will eventually go away. Unless when `compile` is disabled.
85
+ When enabled, fingerprints will be added to asset filenames.
93
86
 
94
87
  **`config.assets.debug`**
95
88
 
96
- Enable expanded asset debugging mode. Individual files will be served to make referencing filenames in the web console easier. This feature will eventually be deprecated and replaced by Source Maps in Sprockets 3.x.
89
+ Enable asset debugging mode. A source map will be included with each asset when this is true.
97
90
 
98
91
  **`config.assets.compile`**
99
92
 
100
- Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`.
93
+ Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be `nil` to prevent inadvertent compilation calls. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. Initializers expecting `Rails.application.assets` during boot should be accessing the environment in a `config.assets.configure` block. See below.
101
94
 
102
95
  **`config.assets.configure`**
103
96
 
@@ -105,18 +98,42 @@ Invokes block with environment when the environment is initialized. Allows direc
105
98
 
106
99
  ``` ruby
107
100
  config.assets.configure do |env|
108
- env.js_compressor = :uglify # or :closure, :yui
101
+ env.js_compressor = :uglifier # or :closure, :yui
109
102
  env.css_compressor = :sass # or :yui
110
103
 
111
104
  require 'my_processor'
112
105
  env.register_preprocessor 'application/javascript', MyProcessor
113
106
 
114
107
  env.logger = Rails.logger
115
-
116
- env.cache = ActiveSupport::Cache::FileStore.new("tmp/cache/assets")
117
108
  end
118
109
  ```
119
110
 
111
+ **`config.assets.resolve_assets_in_css_urls`**
112
+
113
+ When this option is enabled, sprockets-rails will register a CSS postprocessor to resolve assets referenced in [`url()`](https://developer.mozilla.org/en-US/docs/Web/CSS/url()) function calls and replace them with the digested paths. Defaults to `true`.
114
+
115
+ **`config.assets.resolve_with`**
116
+
117
+ A list of `:environment` and `:manifest` symbols that defines the order that
118
+ we try to find assets: manifest first, environment second? Manifest only?
119
+
120
+ By default, we check the manifest first if asset digests are enabled and debug
121
+ is not enabled, then we check the environment if compiling is enabled:
122
+ ```
123
+ # Dev where debug is true, or digests are disabled
124
+ %i[ environment ]
125
+
126
+ # Dev default, or production with compile enabled.
127
+ %i[ manifest environment ]
128
+
129
+ # Production default.
130
+ %i[ manifest ]
131
+ ```
132
+ If the resolver list is empty (e.g. if debug is true and compile is false), the standard rails public path resolution will be used.
133
+
134
+ **`config.assets.check_precompiled_asset`**
135
+
136
+ When enabled, an exception is raised for missing assets. This option is enabled by default.
120
137
 
121
138
  ## Complementary plugins
122
139
 
@@ -125,36 +142,51 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
125
142
  * [coffee-rails](https://github.com/rails/coffee-rails)
126
143
  * [sass-rails](https://github.com/rails/sass-rails)
127
144
 
128
- **NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (any many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
145
+ **NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (and many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
129
146
 
130
147
 
131
148
  ## Changes from Rails 3.x
132
149
 
133
150
  * Only compiles digest filenames. Static non-digest assets should simply live in public/.
134
151
  * Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist.
135
- * JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglify` or `config.assets.css_compressor = :sass` for the standard compressors.
152
+ * JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglifier` or `config.assets.css_compressor = :sass` for the standard compressors.
136
153
  * The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource.
137
154
  * `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
138
- * Two cleanup tasks. `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used. While `rake assets:clobber` nukes the entire `public/assets` directory and clears your filesystem cache. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
155
+ * Two cleanup tasks: `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used, while `rake assets:clobber` nukes the entire `public/assets` directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
156
+
157
+ ### But what if I want sprockets to generate non-digest assets?
158
+
159
+ You have several options:
139
160
 
161
+ * Use the [non-digest-assets gem](https://github.com/mvz/non-digest-assets).
162
+ * Use the [sprockets-redirect gem](https://github.com/sikachu/sprockets-redirect).
163
+ * Use the [smart_assets gem](https://github.com/zarqman/smart_assets).
164
+ * Create [a rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134) to pre-generate a non-digest version in `public/`.
140
165
 
141
- ## Contributing
166
+ ## Experimental
142
167
 
143
- Usual bundler workflow.
168
+ ### [SRI](http://www.w3.org/TR/SRI/) support
144
169
 
145
- ``` shell
146
- $ git clone https://github.com/rails/sprockets-rails.git
147
- $ cd sprockets-rails/
148
- $ bundle install
149
- $ bundle exec rake test
170
+ Sprockets 3.x adds experimental support for subresource integrity checks. The spec is still evolving and the API may change in backwards incompatible ways.
171
+
172
+ ``` ruby
173
+ javascript_include_tag :application, integrity: true
174
+ # => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
150
175
  ```
151
176
 
152
- [![Build Status](https://secure.travis-ci.org/rails/sprockets-rails.png)](http://travis-ci.org/rails/sprockets-rails)
177
+ Note that sprockets-rails only adds integrity hashes to assets when served in a secure context (over an HTTPS connection or localhost).
178
+
179
+
180
+ ## Contributing to Sprockets Rails
153
181
 
182
+ Sprockets Rails is work of many contributors. You're encouraged to submit pull requests, propose
183
+ features and discuss issues.
184
+
185
+ See [CONTRIBUTING](CONTRIBUTING.md).
154
186
 
155
187
  ## Releases
156
188
 
157
- sprockets-rails 2.x will primarily target sprockets 2.x with future compatibility for 3.x. Consider upgrading to sprockets-rails 3.x to take full advantage of 3.x features.
189
+ sprockets-rails 3.x will primarily target sprockets 3.x. And future versions will target the corresponding sprockets release line.
158
190
 
159
191
  The minor and patch version will be updated according to [semver](http://semver.org/).
160
192
 
@@ -162,9 +194,10 @@ The minor and patch version will be updated according to [semver](http://semver.
162
194
  * Any time the sprockets dependency is bumped, there will be a new minor release
163
195
  * Simple bug fixes will be patch releases
164
196
 
165
-
166
197
  ## License
167
198
 
168
- Copyright &copy; 2014 Joshua Peek.
199
+ Sprockets Rails is released under the [MIT License](MIT-LICENSE).
200
+
201
+ ## Code Status
169
202
 
170
- Released under the MIT license. See `LICENSE` for details.
203
+ * [![Gem Version](https://badge.fury.io/rb/sprockets-rails.svg)](http://badge.fury.io/rb/sprockets-rails)
@@ -0,0 +1,17 @@
1
+ module Sprockets
2
+ module Rails
3
+ # Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
4
+ class AssetUrlProcessor
5
+ REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
6
+ def self.call(input)
7
+ context = input[:environment].context_class.new(input)
8
+ data = input[:data].gsub(REGEX) do |_match|
9
+ path = Regexp.last_match[:path]
10
+ "url(#{context.asset_path(path)})"
11
+ end
12
+
13
+ context.metadata.merge(data: data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ require 'action_view/helpers'
2
+ require 'sprockets'
3
+
4
+ module Sprockets
5
+ module Rails
6
+ module Context
7
+ include ActionView::Helpers::AssetUrlHelper
8
+ include ActionView::Helpers::AssetTagHelper
9
+
10
+ def self.included(klass)
11
+ klass.class_eval do
12
+ class_attribute :config, :assets_prefix, :digest_assets
13
+ end
14
+ end
15
+
16
+ def compute_asset_path(path, options = {})
17
+ @dependencies << 'actioncontroller-asset-url-config'
18
+
19
+ begin
20
+ asset_uri = resolve(path)
21
+ rescue FileNotFound
22
+ # TODO: eh, we should be able to use a form of locate that returns
23
+ # nil instead of raising an exception.
24
+ end
25
+
26
+ if asset_uri
27
+ asset = link_asset(path)
28
+ digest_path = asset.digest_path
29
+ path = digest_path if digest_assets
30
+ File.join(assets_prefix || "/", path)
31
+ else
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ register_dependency_resolver 'actioncontroller-asset-url-config' do |env|
39
+ config = env.context_class.config
40
+ [config.relative_url_root,
41
+ (config.asset_host unless config.asset_host.respond_to?(:call))]
42
+ end
43
+
44
+ # fallback to the default pipeline when using Sprockets 3.x
45
+ unless config[:pipelines].include? :debug
46
+ register_pipeline :debug, config[:pipelines][:default]
47
+ end
48
+ end