sprockets 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprockets might be problematic. Click here for more details.

data/README.md CHANGED
@@ -110,6 +110,10 @@ way to do this is with the `map` method in `config.ru`:
110
110
  environment.append_path 'app/assets/stylesheets'
111
111
  run environment
112
112
  end
113
+
114
+ map '/' do
115
+ run YourRackApp
116
+ end
113
117
 
114
118
  ### Accessing Assets Programmatically ###
115
119
 
@@ -49,6 +49,8 @@ module Sprockets
49
49
  path = engine_extensions.inject(path) { |p, ext| p.sub(ext, '') }
50
50
  path = "#{path}#{engine_format_extension}" unless format_extension
51
51
  path
52
+ else
53
+ raise FileOutsidePaths, "#{pathname} isn't in paths: #{environment.paths.join(', ')}"
52
54
  end
53
55
  end
54
56
 
@@ -130,8 +132,7 @@ module Sprockets
130
132
  if old_digest = path_fingerprint
131
133
  pathname.sub(old_digest, digest).to_s
132
134
  else
133
- basename = "#{pathname.basename(extensions.join)}-#{digest}#{extensions.join}"
134
- pathname.dirname.to_s == '.' ? basename : pathname.dirname.join(basename).to_s
135
+ pathname.to_s.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
135
136
  end
136
137
  end
137
138
 
@@ -110,11 +110,34 @@ module Sprockets
110
110
  find_asset(*args)
111
111
  end
112
112
 
113
+ def each_entry(root, &block)
114
+ return to_enum(__method__, root) unless block_given?
115
+ root = Pathname.new(root) unless root.is_a?(Pathname)
116
+
117
+ paths = []
118
+ entries(root).sort.each do |filename|
119
+ path = root.join(filename)
120
+ paths << path
121
+
122
+ if stat(path).directory?
123
+ each_entry(path) do |subpath|
124
+ paths << subpath
125
+ end
126
+ end
127
+ end
128
+
129
+ paths.sort_by(&:to_s).each(&block)
130
+
131
+ nil
132
+ end
133
+
113
134
  def each_file
114
135
  return to_enum(__method__) unless block_given?
115
- paths.each do |base_path|
116
- Dir["#{base_path}/**/*"].each do |filename|
117
- yield filename unless File.directory?(filename)
136
+ paths.each do |root|
137
+ each_entry(root) do |path|
138
+ if !stat(path).directory?
139
+ yield path
140
+ end
118
141
  end
119
142
  end
120
143
  nil
@@ -258,17 +258,18 @@ module Sprockets
258
258
  if relative?(path)
259
259
  root = pathname.dirname.join(path).expand_path
260
260
 
261
- unless root.directory?
261
+ unless (stats = stat(root)) && stats.directory?
262
262
  raise ArgumentError, "require_tree argument must be a directory"
263
263
  end
264
264
 
265
265
  context.depend_on(root)
266
266
 
267
- Dir["#{root}/*"].sort.each do |filename|
268
- if filename == self.file
267
+ entries(root).each do |pathname|
268
+ pathname = root.join(pathname)
269
+ if pathname.to_s == self.file
269
270
  next
270
- elsif context.asset_requirable?(filename)
271
- context.require_asset(filename)
271
+ elsif context.asset_requirable?(pathname)
272
+ context.require_asset(pathname)
272
273
  end
273
274
  end
274
275
  else
@@ -286,19 +287,19 @@ module Sprockets
286
287
  if relative?(path)
287
288
  root = pathname.dirname.join(path).expand_path
288
289
 
289
- unless root.directory?
290
+ unless (stats = stat(root)) && stats.directory?
290
291
  raise ArgumentError, "require_tree argument must be a directory"
291
292
  end
292
293
 
293
294
  context.depend_on(root)
294
295
 
295
- Dir["#{root}/**/*"].sort.each do |filename|
296
- if filename == self.file
296
+ each_entry(root) do |pathname|
297
+ if pathname.to_s == self.file
297
298
  next
298
- elsif File.directory?(filename)
299
- context.depend_on(filename)
300
- elsif context.asset_requirable?(filename)
301
- context.require_asset(filename)
299
+ elsif stat(pathname).directory?
300
+ context.depend_on(pathname)
301
+ elsif context.asset_requirable?(pathname)
302
+ context.require_asset(pathname)
302
303
  end
303
304
  end
304
305
  else
@@ -359,8 +360,8 @@ module Sprockets
359
360
  # compat mode is on.
360
361
  def constants
361
362
  if compat?
362
- path = File.join(context.root_path, "constants.yml")
363
- File.exist?(path) ? YAML.load_file(path) : {}
363
+ pathname = Pathname.new(context.root_path).join("constants.yml")
364
+ stat(pathname) ? YAML.load_file(pathname) : {}
364
365
  else
365
366
  {}
366
367
  end
@@ -376,5 +377,17 @@ module Sprockets
376
377
  def relative?(path)
377
378
  path =~ /^\.($|\.?\/)/
378
379
  end
380
+
381
+ def stat(path)
382
+ context.environment.stat(path)
383
+ end
384
+
385
+ def entries(path)
386
+ context.environment.entries(path)
387
+ end
388
+
389
+ def each_entry(root, &block)
390
+ context.environment.each_entry(root, &block)
391
+ end
379
392
  end
380
393
  end
@@ -6,6 +6,7 @@ module Sprockets
6
6
  class ContentTypeMismatch < Error; end
7
7
  class EncodingError < Error; end
8
8
  class FileNotFound < Error; end
9
+ class FileOutsidePaths < Error; end
9
10
 
10
11
  module EngineError
11
12
  attr_accessor :sprockets_annotation
@@ -60,7 +60,7 @@ module Sprockets
60
60
  # argument is supplied, the processors registered under that
61
61
  # extension will be returned.
62
62
  #
63
- # Postprocessors are ran after Postprocessors and Engine processors.
63
+ # Postprocessors are ran after Preprocessors and Engine processors.
64
64
  #
65
65
  # All `Processor`s must follow the `Tilt::Template` interface. It is
66
66
  # recommended to subclass `Tilt::Template`.
@@ -1,5 +1,5 @@
1
- require 'rack/request'
2
1
  require 'time'
2
+ require 'uri'
3
3
 
4
4
  module Sprockets
5
5
  # `Server` is a concern mixed into `Environment` and
@@ -36,7 +36,7 @@ module Sprockets
36
36
  env['rack.session.options'][:skip] = true
37
37
 
38
38
  # Extract the path from everything after the leading slash
39
- path = env['PATH_INFO'].to_s.sub(/^\//, '')
39
+ path = unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
40
40
 
41
41
  # Look up the asset.
42
42
  asset = find_asset(path)
@@ -81,47 +81,6 @@ module Sprockets
81
81
  end
82
82
  end
83
83
 
84
- # Deprecated: `path` is a url helper that looks up an asset given a
85
- # `logical_path` and returns a path String. By default, the
86
- # asset's digest fingerprint is spliced into the filename.
87
- #
88
- # /assets/application-3676d55f84497cbeadfc614c1b1b62fc.js
89
- #
90
- # A third `prefix` argument can be pass along to be prepended to
91
- # the string.
92
- def path(logical_path, fingerprint = true, prefix = nil)
93
- logger.warn "Sprockets::Environment#path is deprecated\n#{caller[0..2].join("\n")}"
94
- if fingerprint && asset = find_asset(logical_path.to_s.sub(/^\//, ''))
95
- url = asset.digest_path
96
- else
97
- url = logical_path
98
- end
99
-
100
- url = File.join(prefix, url) if prefix
101
- url = "/#{url}" unless url =~ /^\//
102
-
103
- url
104
- end
105
-
106
- # Deprecated: Similar to `path`, `url` returns a full url given a Rack `env`
107
- # Hash and a `logical_path`.
108
- def url(env, logical_path, fingerprint = true, prefix = nil)
109
- logger.warn "Sprockets::Environment#url is deprecated\n#{caller[0..2].join("\n")}"
110
- req = Rack::Request.new(env)
111
-
112
- url = req.scheme + "://"
113
- url << req.host
114
-
115
- if req.scheme == "https" && req.port != 443 ||
116
- req.scheme == "http" && req.port != 80
117
- url << ":#{req.port}"
118
- end
119
-
120
- url << path(logical_path, fingerprint, prefix)
121
-
122
- url
123
- end
124
-
125
84
  private
126
85
  def forbidden_request?(env)
127
86
  # Prevent access to files elsewhere on the file system
@@ -264,6 +223,20 @@ module Sprockets
264
223
  end
265
224
  end
266
225
 
226
+ # URI.unescape is deprecated on 1.9. We need to use URI::Parser
227
+ # if its available.
228
+ if defined? URI::DEFAULT_PARSER
229
+ def unescape(str)
230
+ str = URI::DEFAULT_PARSER.unescape(str)
231
+ str.force_encoding(Encoding.default_internal) if Encoding.default_internal
232
+ str
233
+ end
234
+ else
235
+ def unescape(str)
236
+ URI.unescape(str)
237
+ end
238
+ end
239
+
267
240
  # Helper to quote the assets digest for use as an ETag.
268
241
  def etag(asset)
269
242
  %("#{asset.digest}")
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-29 00:00:00 -05:00
19
+ date: 2011-09-30 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  requirements: []
245
245
 
246
246
  rubyforge_project: sprockets
247
- rubygems_version: 1.5.2
247
+ rubygems_version: 1.6.2
248
248
  signing_key:
249
249
  specification_version: 3
250
250
  summary: Rack-based asset packaging system