sprockets 3.0.0.beta.5 → 3.0.0.beta.6

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
  SHA1:
3
- metadata.gz: 6a6bee17ca558f25cc69850e82405f479f3d3af3
4
- data.tar.gz: b513251bb8582e5fc2d30ccf3b0a65336e14edd9
3
+ metadata.gz: 8efcdd68f447ff7e005fe4edd68eaae03f06f1d6
4
+ data.tar.gz: d0b92f39df358468d6039d3d1bb08970d271a733
5
5
  SHA512:
6
- metadata.gz: 2b16c9ea238f143f8b9e0881c74748446ae160179db5895195d00075e72eb7982630270ab8e1609ed93d05a86259d48b21c29723d9c9e90749b6010fa6599b89
7
- data.tar.gz: 02c9e685bb2b994590402d7761b5476dc6c67afb49563ea04b6493c5b89a16d17069176ab4c3d7900367b41176ee059d2f653416d002dc4b7393c64ce9622794
6
+ metadata.gz: 6819d688dd19334c5f09ba24e3399fcb2a8cf5c233e6be75450d8fdeb909abfc356c68dc0a38203e07bc6a8aa636e6ccaa1868a1396fd346d5145405806ca580
7
+ data.tar.gz: c8d3438168908e7f72ca0f4fe68669ed3d91c237e4712be6c43970de7ccd87d5178acf7171abcbde28d448bcdf1a0c7cd73b52122abe299cbb53ddb274d7fc67
@@ -127,9 +127,9 @@ module Rake
127
127
  task :clobber => ["clobber_#{name}"]
128
128
 
129
129
  desc name == :assets ? "Clean old assets" : "Clean old #{name} assets"
130
- task "clean_#{name}" do
130
+ task "clean_#{name}", [:keep] do |t, args|
131
131
  with_logger do
132
- manifest.clean(keep)
132
+ manifest.clean(Integer(args.keep || self.keep))
133
133
  end
134
134
  end
135
135
 
@@ -2,6 +2,18 @@ require 'uri'
2
2
 
3
3
  module Sprockets
4
4
  module AssetURI
5
+ # Internal: Check if String is a valid Asset URI.
6
+ #
7
+ # str - Possible String asset URI.
8
+ #
9
+ # Returns true or false.
10
+ def self.valid?(str)
11
+ # Quick prefix check before attempting a full parse
12
+ str.start_with?("file://") && parse(str) ? true : false
13
+ rescue URI::InvalidURIError
14
+ false
15
+ end
16
+
5
17
  # Internal: Parse Asset URI.
6
18
  #
7
19
  # Examples
@@ -53,13 +53,7 @@ module Sprockets
53
53
 
54
54
  value = safe_open(path) do |f|
55
55
  begin
56
- raw = f.read
57
- if raw =~ /\A\x04\x08/
58
- marshaled = raw
59
- else
60
- marshaled = Zlib::Inflate.new(Zlib::MAX_WBITS).inflate(raw)
61
- end
62
- Marshal.load(marshaled)
56
+ EncodingUtils.unmarshaled_deflated(f.read, Zlib::MAX_WBITS)
63
57
  rescue Exception => e
64
58
  @logger.error do
65
59
  "#{self.class}[#{path}] could not be unmarshaled: " +
@@ -119,7 +119,11 @@ module Sprockets
119
119
  end
120
120
 
121
121
  def locate(path, options = {})
122
- _resolve(:locate, path, options)
122
+ if AssetURI.valid?(path)
123
+ path
124
+ else
125
+ _resolve(:locate, path, options)
126
+ end
123
127
  end
124
128
 
125
129
  # `depend_on` allows you to state a dependency on a file without
@@ -165,7 +169,7 @@ module Sprockets
165
169
  # `path` must be an asset which may or may not already be included
166
170
  # in the bundle.
167
171
  def stub_asset(path)
168
- @stubbed << @environment.locate(path, accept: @content_type, bundle: false)
172
+ @stubbed << locate(path, accept: @content_type, bundle: false)
169
173
  nil
170
174
  end
171
175
 
@@ -80,10 +80,7 @@ module Sprockets
80
80
  @content_type = input[:content_type]
81
81
 
82
82
  data = input[:data]
83
- cache_key = ['DirectiveProcessor', VERSION, data]
84
- result = input[:cache].fetch(cache_key) do
85
- process_source(data)
86
- end
83
+ result = process_source(data)
87
84
 
88
85
  data, directives = result.values_at(:data, :directives)
89
86
 
@@ -27,6 +27,30 @@ module Sprockets
27
27
  # Public: Alias for CodingUtils.deflate
28
28
  DEFLATE = method(:deflate)
29
29
 
30
+ # Internal: Unmarshal optionally deflated data.
31
+ #
32
+ # Checks leading marshal header to see if the bytes are uncompressed
33
+ # otherwise inflate the data an unmarshal.
34
+ #
35
+ # str - Marshaled String
36
+ # window_bits - Integer deflate window size. See ZLib::Inflate.new()
37
+ #
38
+ # Returns unmarshaled Object or raises an Exception.
39
+ def unmarshaled_deflated(str, window_bits = -Zlib::MAX_WBITS)
40
+ major, minor = str[0], str[1]
41
+ if major && major.ord == Marshal::MAJOR_VERSION &&
42
+ minor && minor.ord <= Marshal::MINOR_VERSION
43
+ marshaled = str
44
+ else
45
+ begin
46
+ marshaled = Zlib::Inflate.new(window_bits).inflate(str)
47
+ rescue Zlib::DataError
48
+ marshaled = str
49
+ end
50
+ end
51
+ Marshal.load(marshaled)
52
+ end
53
+
30
54
  # Public: Use gzip to compress data.
31
55
  #
32
56
  # str - String data
@@ -106,7 +106,7 @@ module Sprockets
106
106
  @data['files'] ||= {}
107
107
  end
108
108
 
109
- # Internal: Compile logical path matching filter into a proc that can be
109
+ # Deprecated: Compile logical path matching filter into a proc that can be
110
110
  # passed to logical_paths.select(&proc).
111
111
  #
112
112
  # compile_match_filter(proc { |logical_path|
@@ -139,7 +139,7 @@ module Sprockets
139
139
  end
140
140
  end
141
141
 
142
- # Public: Filter logical paths in environment. Useful for selecting what
142
+ # Deprecated: Filter logical paths in environment. Useful for selecting what
143
143
  # files you want to compile.
144
144
  #
145
145
  # Returns an Enumerator.
@@ -150,6 +150,29 @@ module Sprockets
150
150
  end
151
151
  end
152
152
 
153
+ # Public: Find all assets matching pattern set in environment.
154
+ #
155
+ # Returns Enumerator of Assets.
156
+ def find(*args)
157
+ unless environment
158
+ raise Error, "manifest requires environment for compilation"
159
+ end
160
+
161
+ return to_enum(__method__, *args) unless block_given?
162
+
163
+ filters = args.flatten.map { |arg| self.class.compile_match_filter(arg) }
164
+
165
+ environment.logical_paths do |logical_path, filename|
166
+ if filters.any? { |f| f.call(logical_path, filename) }
167
+ environment.find_all_linked_assets(filename) do |asset|
168
+ yield asset
169
+ end
170
+ end
171
+ end
172
+
173
+ nil
174
+ end
175
+
153
176
  # Deprecated alias.
154
177
  alias_method :find_logical_paths, :filter_logical_paths
155
178
 
@@ -167,28 +190,26 @@ module Sprockets
167
190
 
168
191
  filenames = []
169
192
 
170
- filter_logical_paths(*args).each do |_, filename|
171
- find_assets(filename) do |asset|
172
- files[asset.digest_path] = {
173
- 'logical_path' => asset.logical_path,
174
- 'mtime' => asset.mtime.iso8601,
175
- 'size' => asset.bytesize,
176
- 'digest' => asset.hexdigest,
177
- 'integrity' => asset.integrity
178
- }
179
- assets[asset.logical_path] = asset.digest_path
180
-
181
- target = File.join(dir, asset.digest_path)
182
-
183
- if File.exist?(target)
184
- logger.debug "Skipping #{target}, already exists"
185
- else
186
- logger.info "Writing #{target}"
187
- asset.write_to target
188
- end
193
+ find(*args) do |asset|
194
+ files[asset.digest_path] = {
195
+ 'logical_path' => asset.logical_path,
196
+ 'mtime' => asset.mtime.iso8601,
197
+ 'size' => asset.bytesize,
198
+ 'digest' => asset.hexdigest,
199
+ 'integrity' => asset.integrity
200
+ }
201
+ assets[asset.logical_path] = asset.digest_path
202
+
203
+ target = File.join(dir, asset.digest_path)
189
204
 
190
- filenames << filename
205
+ if File.exist?(target)
206
+ logger.debug "Skipping #{target}, already exists"
207
+ else
208
+ logger.info "Writing #{target}"
209
+ asset.write_to target
191
210
  end
211
+
212
+ filenames << asset.filename
192
213
  end
193
214
  save
194
215
 
@@ -249,18 +270,6 @@ module Sprockets
249
270
  end
250
271
 
251
272
  protected
252
- # Basic wrapper around Environment#find_asset. Logs compile time.
253
- def find_assets(path)
254
- start = Utils.benchmark_start
255
- environment.find_all_linked_assets(path) do |asset|
256
- logger.debug do
257
- "Compiled #{asset.logical_path} (#{Utils.benchmark_end(start)}ms)"
258
- end
259
- yield asset
260
- start = Utils.benchmark_start
261
- end
262
- end
263
-
264
273
  # Persist manfiest back to FS
265
274
  def save
266
275
  FileUtils.mkdir_p File.dirname(filename)
@@ -61,7 +61,9 @@ module Sprockets
61
61
 
62
62
  paths = options[:load_paths] || self.paths
63
63
 
64
- if absolute_path?(path)
64
+ if AssetURI.valid?(path)
65
+ return path
66
+ elsif absolute_path?(path)
65
67
  path = File.expand_path(path)
66
68
  if paths_split(paths, path) && file?(path)
67
69
  mime_type = parse_path_extnames(path)[1]
@@ -46,6 +46,13 @@ module Sprockets
46
46
  options = {}
47
47
  options[:bundle] = !body_only?(env)
48
48
 
49
+ # 2.x/3.x compatibility hack. Just ignore fingerprints on ?body=1 requests.
50
+ # 3.x/4.x prefers strong validation of fingerprint to body contents, but
51
+ # 2.x just ignored it.
52
+ if options[:bundle] == false
53
+ fingerprint = nil
54
+ end
55
+
49
56
  if fingerprint
50
57
  if_match = fingerprint
51
58
  elsif env['HTTP_IF_MATCH']
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "3.0.0.beta.5"
2
+ VERSION = "3.0.0.beta.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta.5
4
+ version: 3.0.0.beta.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-29 00:00:00.000000000 Z
12
+ date: 2014-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack