sprockets-rails 3.0.4 → 3.1.0

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
  SHA1:
3
- metadata.gz: a7cb5a6b14d9c7bb706dad33e5d930e8f528d212
4
- data.tar.gz: 76221e850d34d167aa5a26d7653248d0197482c5
3
+ metadata.gz: f3ef29cbba0d6b7b2303904f32f4ee96549a2988
4
+ data.tar.gz: 2036e599613a47415973603a8284b7e97e388dd4
5
5
  SHA512:
6
- metadata.gz: 9fec7c6db539f43f5527edb868e65a1a73530be359faa79854cf12a8702b9ec9fb3b0a6a99706664bc6662d2b09a3420dbfb65c98c64df2d7a00b00403618cbe
7
- data.tar.gz: b7e049037095f8f7890236d0dc08f4bdbea922b2b50ed7155a498b8f0cd2195a3f1eb076acf932f34fe93fb2398700321fb70e7a1ff8aeaad1a6162c3e593f88
6
+ metadata.gz: ef635d7892605ede2b74af97d13e4a7e8ef3b0a20dfd54d2dd85a726b96ebb34a1ad2556f202027f074ca07d8c34044b346442aee6e6daa28c0bd050ae2c54c8
7
+ data.tar.gz: 5b207e5befdd294a7e18a23abbc86883dfbca953334b87f8d7978d7809e9ddfc7041a1a56024a5bd93a3b5fce6849feb09feb33fad5e6477eea879f9baffbc18
data/README.md CHANGED
@@ -59,6 +59,9 @@ Add additional assets to compile on deploy. Defaults to `application.js`, `appli
59
59
 
60
60
  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.
61
61
 
62
+ **`config.assets.quiet`**
63
+
64
+ Suppresses logger output for asset requests. Uses the `config.assets.prefix` path to match asset requests. Defaults to `false`.
62
65
 
63
66
  **`config.assets.version`**
64
67
 
@@ -121,6 +124,10 @@ is not enabled, then we check the environment if compiling is enabled:
121
124
  ```
122
125
  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.
123
126
 
127
+ **`config.assets.check_precompiled_asset`**
128
+
129
+ When enabled, an exception is raised for missing assets. This option is enabled by default.
130
+
124
131
  ## Complementary plugins
125
132
 
126
133
  The following plugins provide some extras for the Sprockets Asset Pipeline.
@@ -138,7 +145,7 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
138
145
  * 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.
139
146
  * 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.
140
147
  * `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
141
- * 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.
148
+ * 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.
142
149
 
143
150
  ## Experimental
144
151
 
@@ -151,6 +158,8 @@ javascript_include_tag :application, integrity: true
151
158
  # => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
152
159
  ```
153
160
 
161
+ Note that sprockets-rails only adds integrity hashes to assets when served in a secure context (over an HTTPS connection or localhost).
162
+
154
163
 
155
164
  ## Contributing to Sprockets Rails
156
165
 
@@ -11,14 +11,10 @@ module Sprockets
11
11
  def initialize(source)
12
12
  msg =
13
13
  if using_sprockets4?
14
- "Asset `#{source}` was not declared to be precompiled in production.\n" +
15
- "Declare links to your assets in `assets/config/manifest.js`.\n" +
16
- "Examples:\n" +
17
- "`//= link ../javascripts/application.js`\n" +
18
- "`//= link_directory ../javascripts .js`\n" +
19
- "`//= link_directory ../stylesheets .css`\n" +
20
- "`//= link_tree ../javascripts .js`\n" +
21
- "`//= link_tree ../images`\n"
14
+ "Asset `#{ source }` was not declared to be precompiled in production.\n" +
15
+ "Declare links to your assets in `app/assets/config/manifest.js`.\n\n" +
16
+ " //= link #{ source }\n" +
17
+ "and restart your server"
22
18
  else
23
19
  "Asset was not declared to be precompiled in production.\n" +
24
20
  "Add `Rails.application.config.assets.precompile += " +
@@ -37,7 +33,7 @@ module Sprockets
37
33
  :assets_environment, :assets_manifest,
38
34
  :assets_precompile, :precompiled_asset_checker,
39
35
  :assets_prefix, :digest_assets, :debug_assets,
40
- :resolve_assets_with
36
+ :resolve_assets_with, :check_precompiled_asset
41
37
  ]
42
38
 
43
39
  def self.included(klass)
@@ -196,7 +192,7 @@ module Sprockets
196
192
  # Only serve integrity metadata for HTTPS requests:
197
193
  # http://www.w3.org/TR/SRI/#non-secure-contexts-remain-non-secure
198
194
  def secure_subresource_integrity_context?
199
- respond_to?(:request) && self.request && self.request.ssl?
195
+ respond_to?(:request) && self.request && (self.request.local? || self.request.ssl?)
200
196
  end
201
197
 
202
198
  # Enable split asset debugging. Eventually will be deprecated
@@ -303,6 +299,7 @@ module Sprockets
303
299
  raise ArgumentError, 'config.assets.resolve_with includes :environment, but app.assets is nil' unless view.assets_environment
304
300
  @env = view.assets_environment
305
301
  @precompiled_asset_checker = view.precompiled_asset_checker
302
+ @check_precompiled_asset = view.check_precompiled_asset
306
303
  end
307
304
 
308
305
  def asset_path(path, digest, allow_non_precompiled = false)
@@ -346,7 +343,7 @@ module Sprockets
346
343
  end
347
344
 
348
345
  def raise_unless_precompiled_asset(path)
349
- raise Helper::AssetNotPrecompiled.new(path) unless precompiled?(path)
346
+ raise Helper::AssetNotPrecompiled.new(path) if @check_precompiled_asset && !precompiled?(path)
350
347
  end
351
348
  end
352
349
  end
@@ -0,0 +1,18 @@
1
+ module Sprockets
2
+ module Rails
3
+ class QuietAssets
4
+ def initialize(app)
5
+ @app = app
6
+ @assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
7
+ end
8
+
9
+ def call(env)
10
+ if env['PATH_INFO'] =~ @assets_regex
11
+ ::Rails.logger.silence { @app.call(env) }
12
+ else
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Rails
3
- VERSION = "3.0.4"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ require 'active_support/core_ext/numeric/bytes'
6
6
  require 'sprockets'
7
7
  require 'sprockets/rails/context'
8
8
  require 'sprockets/rails/helper'
9
+ require 'sprockets/rails/quiet_assets'
9
10
  require 'sprockets/rails/route_wrapper'
10
11
  require 'sprockets/rails/version'
11
12
  require 'set'
@@ -66,6 +67,20 @@ module Sprockets
66
67
  class Railtie < ::Rails::Railtie
67
68
  include Sprockets::Rails::Utils
68
69
 
70
+ class ManifestNeededError < StandardError
71
+ def initialize
72
+ msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
73
+ "But did not, please create this file and use it to link any assets that need\n" +
74
+ "to be rendered by your app:\n\n" +
75
+ "Example:\n" +
76
+ " //= link_tree ../images\n" +
77
+ " //= link_directory ../javascripts .js\n" +
78
+ " //= link_directory ../stylesheets .css\n" +
79
+ "and restart your server"
80
+ super msg
81
+ end
82
+ end
83
+
69
84
  LOOSE_APP_ASSETS = lambda do |logical_path, filename|
70
85
  filename.start_with?(::Rails.root.join("app/assets").to_s) &&
71
86
  !['.js', '.css', ''].include?(File.extname(logical_path))
@@ -80,18 +95,33 @@ module Sprockets
80
95
  config.assets = OrderedOptions.new
81
96
  config.assets._blocks = []
82
97
  config.assets.paths = []
98
+ config.assets.precompile = []
83
99
  config.assets.prefix = "/assets"
84
100
  config.assets.manifest = nil
85
- if using_sprockets4?
86
- config.assets.precompile = %w( manifest.js )
87
- else
88
- config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
101
+ config.assets.quiet = false
102
+
103
+ initializer :set_default_precompile do |app|
104
+ if using_sprockets4?
105
+ raise ManifestNeededError if !::Rails.root.join("app/assets/config/manifest.js").exist?
106
+ app.config.assets.precompile += %w( manifest.js )
107
+ else
108
+ app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
109
+ end
110
+ end
111
+
112
+ initializer :quiet_assets do |app|
113
+ if app.config.assets.quiet
114
+ app.middleware.insert_before ::Rails::Rack::Logger, ::Sprockets::Rails::QuietAssets
115
+ end
89
116
  end
117
+
90
118
  config.assets.version = ""
91
119
  config.assets.debug = false
92
120
  config.assets.compile = true
93
121
  config.assets.digest = true
94
122
  config.assets.cache_limit = 50.megabytes
123
+ config.assets.gzip = true
124
+ config.assets.check_precompiled_asset = true
95
125
 
96
126
  config.assets.configure do |env|
97
127
  config.assets.paths.each { |path| env.append_path(path) }
@@ -124,6 +154,10 @@ module Sprockets
124
154
  env.version = config.assets.version
125
155
  end
126
156
 
157
+ config.assets.configure do |env|
158
+ env.gzip = config.assets.gzip
159
+ end
160
+
127
161
  rake_tasks do |app|
128
162
  require 'sprockets/rails/task'
129
163
  Sprockets::Rails::Task.new(app)
@@ -210,6 +244,8 @@ module Sprockets
210
244
 
211
245
  self.resolve_assets_with = config.assets.resolve_with
212
246
 
247
+ self.check_precompiled_asset = config.assets.check_precompiled_asset
248
+
213
249
  # Expose the app precompiled asset check to the view
214
250
  self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }
215
251
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -119,6 +119,7 @@ files:
119
119
  - lib/sprockets/rails.rb
120
120
  - lib/sprockets/rails/context.rb
121
121
  - lib/sprockets/rails/helper.rb
122
+ - lib/sprockets/rails/quiet_assets.rb
122
123
  - lib/sprockets/rails/route_wrapper.rb
123
124
  - lib/sprockets/rails/task.rb
124
125
  - lib/sprockets/rails/utils.rb
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  version: '0'
145
146
  requirements: []
146
147
  rubyforge_project:
147
- rubygems_version: 2.5.1
148
+ rubygems_version: 2.6.6
148
149
  signing_key:
149
150
  specification_version: 4
150
151
  summary: Sprockets Rails integration