sprockets 2.2.3 → 2.12.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
- SHA1:
3
- metadata.gz: be373494a4e64c06e55a9ad11e2c9efae09f1492
4
- data.tar.gz: b683ce4b0ed64e683ea98d0b5af268bdeca3f584
2
+ SHA256:
3
+ metadata.gz: 80bdc30a8aea68bb04398d467eea5a5e4cfe9b7dcef6ee41e2902debcec63342
4
+ data.tar.gz: 55a0f0b58e3e55c08ccfb30476017b814894b7ec98cf3bd22eecbc8bdcbe5c39
5
5
  SHA512:
6
- metadata.gz: fa430704b4ef87304b8a128cb83fbb64c66e24d0bdae3d9e9e343bbebd56bf8823f65cba4a0ad1eb33204308c814910ebdd9c2b570c33fbbf89a2fadd2383b33
7
- data.tar.gz: 785eb7a9f36afa38e6f010a573240768a9620ed216f4b20614835ffe9564d258a0e5340c9e8dbf3b538e8b960d9f7fd22342581b5e597dbbfc4e892bac7f7d3a
6
+ metadata.gz: a3ee63f44b0391509f3e80b1c6b403abf52168a66910da726221b7b45c6c51187f86a7896df45e8b6c7bed68d5218ad7915fa79602e3cf7a23c32622d23ab8a5
7
+ data.tar.gz: da30a4f95ef0691cec504b73b1d832cec2577aa0b2905050e74ad9a89322c6568e3ec250a760ac3a6f2080f738e8ed1580e3ae7ff2a53e8623820d98fea00b2d
data/README.md CHANGED
@@ -159,9 +159,9 @@ variables, mixins, operations and functions.
159
159
 
160
160
  If the `less` gem is available to your application, you can use LESS
161
161
  to write CSS assets in Sprockets. Note that the LESS compiler is
162
- written in JavaScript, and at the time of this writing, the `less` gem
163
- depends on `therubyracer` which embeds the V8 JavaScript runtime in
164
- Ruby.
162
+ written in JavaScript and the `less` gem (on MRI) uses `therubyracer`
163
+ which embeds the V8 JavaScript runtime in Ruby, while on JRuby you're
164
+ going to need `therubyrhino` gem installed.
165
165
 
166
166
  To write CSS assets with LESS, use the extension `.css.less`.
167
167
 
@@ -336,6 +336,18 @@ source file before any subsequent `require` or `include` directives.
336
336
  including it in the bundle. This is useful when you need to expire an
337
337
  asset's cache in response to a change in another file.
338
338
 
339
+ ### The `depend_on_asset` Directive ###
340
+
341
+ `depend_on_asset` *path* works like `depend_on`, but operates
342
+ recursively reading the the file and following the directives found.
343
+
344
+ ### The `stub` Directive ###
345
+
346
+ `stub` *path* allows dependency to be excluded from the asset bundle.
347
+ The *path* must be a valid asset and may or may not already be part
348
+ of the bundle. Once stubbed, it is blacklisted and can't be brought
349
+ back by any other `require`.
350
+
339
351
  # Development #
340
352
 
341
353
  ## Contributing ##
@@ -354,7 +366,126 @@ submit a pull request.
354
366
 
355
367
  ## Version History ##
356
368
 
357
- **2.2.0** (Unreleased)
369
+ **2.12.3** (October 28, 2014)
370
+
371
+ * Security: Fix directory traversal bug in development mode server.
372
+
373
+ **2.12.2** (September 5, 2014)
374
+
375
+ * Ensure internal asset lookups calls are still restricted to load paths within
376
+ asset compiles. Though, you should not depend on internal asset resolves to be
377
+ completely restricted for security reasons. Assets themselves should be
378
+ considered full scripting environments with filesystem access.
379
+
380
+ **2.12.1** (April 17, 2014)
381
+
382
+ * Fix making manifest target directory when its different than the output directory.
383
+
384
+ **2.12.0** (March 13, 2014)
385
+
386
+ * Avoid context reference in SassImporter hack so its Marshallable. Fixes
387
+ issues with Sass 3.3.x.
388
+
389
+ **2.11.0** (February 19, 2014)
390
+
391
+ * Support for `.bower.json`
392
+
393
+ **2.10.0** (May 24, 2013)
394
+
395
+ * Support for `bower.json`
396
+
397
+ **2.9.3** (April 20, 2013)
398
+
399
+ * Fixed sass caching bug
400
+
401
+ **2.9.2** (April 8, 2013)
402
+
403
+ * Improve file freshness check performance
404
+ * Directive processor encoding fixes
405
+
406
+ **2.9.1** (April 6, 2013)
407
+
408
+ * Support for Uglifier 2.x
409
+
410
+ **2.9.0** (February 25, 2013)
411
+
412
+ * Write out gzipped variants of bundled assets.
413
+
414
+ **2.8.2** (December 10, 2012)
415
+
416
+ * Fixed top level Sass constant references
417
+ * Fixed manifest logger when environment is disabled
418
+
419
+ **2.8.1** (October 31, 2012)
420
+
421
+ * Fixed Sass importer bug
422
+
423
+ **2.8.0** (October 16, 2012)
424
+
425
+ * Allow manifest location to be seperated from output directory
426
+ * Pass logical path and absolute path to each_logical_path iterator
427
+
428
+ **2.7.0** (October 10, 2012)
429
+
430
+ * Added --css-compressor and --js-compressor command line flags
431
+ * Added css/js compressor shorthand
432
+ * Change default manifest.json filename to be a randomized manifest-16HEXBYTES.json
433
+ * Allow nil environment to be passed to manifest
434
+ * Allow manifest instance to be set on rake task
435
+
436
+ **2.6.0** (September 19, 2012)
437
+
438
+ * Added bower component.json require support
439
+
440
+ **2.5.0** (September 4, 2012)
441
+
442
+ * Fixed Ruby 2.0 RegExp warning
443
+ * Provide stubbed implementation of context *_path helpers
444
+ * Add SassCompressor
445
+
446
+ **2.4.5** (July 10, 2012)
447
+
448
+ * Tweaked some logger levels
449
+
450
+ **2.4.4** (July 2, 2012)
451
+
452
+ * Canonicalize logical path extensions
453
+ * Check absolute paths passed to depend_on
454
+
455
+ **2.4.3** (May 16, 2012)
456
+
457
+ * Exposed :sprockets in sass options
458
+ * Include dependency paths in asset mtime
459
+
460
+ **2.4.2** (May 7, 2012)
461
+
462
+ * Fixed MultiJson feature detect
463
+
464
+ **2.4.1** (April 26, 2012)
465
+
466
+ * Fixed MultiJson API change
467
+ * Fixed gzip mtime
468
+
469
+ **2.4.0** (March 27, 2012)
470
+
471
+ * Added global path registry
472
+ * Added global processor registry
473
+
474
+ **2.3.2** (March 26, 2012)
475
+
476
+ * Fix Context#logical_path with dots
477
+
478
+ **2.3.1** (February 11, 2012)
479
+
480
+ * Added bytesize to manifest
481
+ * Added Asset#bytesize alias
482
+ * Security: Check path for forbidden access after unescaping
483
+
484
+ **2.3.0** (January 16, 2012)
485
+
486
+ * Added special Sass importer that automatically tracks any `@import`ed files.
487
+
488
+ **2.2.0** (January 10, 2012)
358
489
 
359
490
  * Added `sprockets` command line utility.
360
491
  * Added rake/sprocketstask.
data/bin/sprockets CHANGED
@@ -40,6 +40,14 @@ OptionParser.new do |opts|
40
40
  manifest = Sprockets::Manifest.new(environment, directory)
41
41
  end
42
42
 
43
+ opts.on("--css-compressor=COMPRESSOR", "Use CSS compressor") do |compressor|
44
+ environment.css_compressor = compressor.to_sym
45
+ end
46
+
47
+ opts.on("--js-compressor=COMPRESSOR", "Use JavaScript compressor") do |compressor|
48
+ environment.js_compressor = compressor.to_sym
49
+ end
50
+
43
51
  opts.on("--noenv", "Disables .sprocketsrc file") do
44
52
  end
45
53
 
@@ -37,6 +37,24 @@ module Rake
37
37
  end
38
38
  attr_writer :environment
39
39
 
40
+ # Returns cached indexed environment
41
+ def index
42
+ @index ||= environment.index if environment
43
+ end
44
+
45
+ # `Manifest` instance used for already compiled assets.
46
+ #
47
+ # Will be created by default if an environment and output
48
+ # directory are given
49
+ def manifest
50
+ if !@manifest.is_a?(Sprockets::Manifest) && @manifest.respond_to?(:call)
51
+ @manifest = @manifest.call
52
+ else
53
+ @manifest
54
+ end
55
+ end
56
+ attr_writer :manifest
57
+
40
58
  # Directory to write compiled assets too. As well as the manifest file.
41
59
  #
42
60
  # t.output = "./public/assets"
@@ -79,6 +97,7 @@ module Rake
79
97
  def initialize(name = :assets)
80
98
  @name = name
81
99
  @environment = lambda { Sprockets::Environment.new(Dir.pwd) }
100
+ @manifest = lambda { Sprockets::Manifest.new(index, output) }
82
101
  @logger = Logger.new($stderr)
83
102
  @logger.level = Logger::INFO
84
103
  @keep = 2
@@ -117,24 +136,16 @@ module Rake
117
136
  end
118
137
 
119
138
  private
120
- # Returns cached indexed environment
121
- def index
122
- @index ||= environment.index
123
- end
124
-
125
- # Returns manifest for tasks
126
- def manifest
127
- @manifest ||= Sprockets::Manifest.new(index, output)
128
- end
129
-
130
139
  # Sub out environment logger with our rake task logger that
131
140
  # writes to stderr.
132
141
  def with_logger
133
- old_logger = index.logger
134
- index.logger = @logger
142
+ if env = manifest.environment
143
+ old_logger = env.logger
144
+ env.logger = @logger
145
+ end
135
146
  yield
136
147
  ensure
137
- index.logger = old_logger
148
+ env.logger = old_logger if env
138
149
  end
139
150
  end
140
151
  end
data/lib/sprockets.rb CHANGED
@@ -3,7 +3,6 @@ require 'sprockets/version'
3
3
  module Sprockets
4
4
  # Environment
5
5
  autoload :Base, "sprockets/base"
6
- autoload :Engines, "sprockets/engines"
7
6
  autoload :Environment, "sprockets/environment"
8
7
  autoload :Index, "sprockets/index"
9
8
  autoload :Manifest, "sprockets/manifest"
@@ -15,14 +14,16 @@ module Sprockets
15
14
  autoload :StaticAsset, "sprockets/static_asset"
16
15
 
17
16
  # Processing
18
- autoload :CharsetNormalizer, "sprockets/charset_normalizer"
19
17
  autoload :Context, "sprockets/context"
20
- autoload :DirectiveProcessor, "sprockets/directive_processor"
21
18
  autoload :EcoTemplate, "sprockets/eco_template"
22
19
  autoload :EjsTemplate, "sprockets/ejs_template"
23
20
  autoload :JstProcessor, "sprockets/jst_processor"
24
21
  autoload :Processor, "sprockets/processor"
25
- autoload :SafetyColons, "sprockets/safety_colons"
22
+ autoload :SassCacheStore, "sprockets/sass_cache_store"
23
+ autoload :SassFunctions, "sprockets/sass_functions"
24
+ autoload :SassImporter, "sprockets/sass_importer"
25
+ autoload :SassTemplate, "sprockets/sass_template"
26
+ autoload :ScssTemplate, "sprockets/scss_template"
26
27
 
27
28
  # Internal utilities
28
29
  autoload :ArgumentError, "sprockets/errors"
@@ -39,8 +40,51 @@ module Sprockets
39
40
  end
40
41
 
41
42
  # Extend Sprockets module to provide global registry
42
- extend Engines
43
- @engines = {}
43
+ require 'hike'
44
+ require 'sprockets/engines'
45
+ require 'sprockets/mime'
46
+ require 'sprockets/processing'
47
+ require 'sprockets/compressing'
48
+ require 'sprockets/paths'
49
+ extend Engines, Mime, Processing, Compressing, Paths
50
+
51
+ @trail = Hike::Trail.new(File.expand_path('..', __FILE__))
52
+ @mime_types = {}
53
+ @engines = {}
54
+ @preprocessors = Hash.new { |h, k| h[k] = [] }
55
+ @postprocessors = Hash.new { |h, k| h[k] = [] }
56
+ @bundle_processors = Hash.new { |h, k| h[k] = [] }
57
+ @compressors = Hash.new { |h, k| h[k] = {} }
58
+
59
+ register_mime_type 'text/css', '.css'
60
+ register_mime_type 'application/javascript', '.js'
61
+
62
+ require 'sprockets/directive_processor'
63
+ register_preprocessor 'text/css', DirectiveProcessor
64
+ register_preprocessor 'application/javascript', DirectiveProcessor
65
+
66
+ require 'sprockets/safety_colons'
67
+ register_postprocessor 'application/javascript', SafetyColons
68
+
69
+ require 'sprockets/charset_normalizer'
70
+ register_bundle_processor 'text/css', CharsetNormalizer
71
+
72
+ require 'sprockets/sass_compressor'
73
+ register_compressor 'text/css', :sass, SassCompressor
74
+ register_compressor 'text/css', :scss, SassCompressor
75
+
76
+ require 'sprockets/yui_compressor'
77
+ register_compressor 'text/css', :yui, YUICompressor
78
+
79
+ require 'sprockets/closure_compressor'
80
+ register_compressor 'application/javascript', :closure, ClosureCompressor
81
+
82
+ require 'sprockets/uglifier_compressor'
83
+ register_compressor 'application/javascript', :uglifier, UglifierCompressor
84
+ register_compressor 'application/javascript', :uglify, UglifierCompressor
85
+
86
+ require 'sprockets/yui_compressor'
87
+ register_compressor 'application/javascript', :yui, YUICompressor
44
88
 
45
89
  # Cherry pick the default Tilt engines that make sense for
46
90
  # Sprockets. We don't need ones that only generate html like HAML.
@@ -55,8 +99,8 @@ module Sprockets
55
99
 
56
100
  # CSS engines
57
101
  register_engine '.less', Tilt::LessTemplate
58
- register_engine '.sass', Tilt::SassTemplate
59
- register_engine '.scss', Tilt::ScssTemplate
102
+ register_engine '.sass', SassTemplate
103
+ register_engine '.scss', ScssTemplate
60
104
 
61
105
  # Other
62
106
  register_engine '.erb', Tilt::ERBTemplate
@@ -30,13 +30,17 @@ module Sprockets
30
30
 
31
31
  attr_reader :logical_path, :pathname
32
32
  attr_reader :content_type, :mtime, :length, :digest
33
+ alias_method :bytesize, :length
33
34
 
34
35
  def initialize(environment, logical_path, pathname)
36
+ raise ArgumentError, "Asset logical path has no extension: #{logical_path}" if File.extname(logical_path) == ""
37
+
35
38
  @root = environment.root
36
39
  @logical_path = logical_path.to_s
37
40
  @pathname = Pathname.new(pathname)
38
41
  @content_type = environment.content_type_of(pathname)
39
- @mtime = environment.stat(pathname).mtime
42
+ # drop precision to 1 second, same pattern followed elsewhere
43
+ @mtime = Time.at(environment.stat(pathname).mtime.to_i)
40
44
  @length = environment.stat(pathname).size
41
45
  @digest = environment.file_digest(pathname).hexdigest
42
46
  end
@@ -55,8 +59,7 @@ module Sprockets
55
59
  end
56
60
 
57
61
  if mtime = coder['mtime']
58
- # Parse time string
59
- @mtime = Time.parse(mtime)
62
+ @mtime = Time.at(mtime)
60
63
  end
61
64
 
62
65
  if length = coder['length']
@@ -71,7 +74,7 @@ module Sprockets
71
74
  coder['logical_path'] = logical_path
72
75
  coder['pathname'] = relativize_root_path(pathname).to_s
73
76
  coder['content_type'] = content_type
74
- coder['mtime'] = mtime.iso8601
77
+ coder['mtime'] = mtime.to_i
75
78
  coder['length'] = length
76
79
  coder['digest'] = digest
77
80
  end
@@ -136,7 +139,9 @@ module Sprockets
136
139
  # Save asset to disk.
137
140
  def write_to(filename, options = {})
138
141
  # Gzip contents if filename has '.gz'
139
- options[:compress] ||= File.extname(filename) == '.gz'
142
+ unless options.key?(:compress)
143
+ options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz'
144
+ end
140
145
 
141
146
  FileUtils.mkdir_p File.dirname(filename)
142
147
 
@@ -144,12 +149,12 @@ module Sprockets
144
149
  if options[:compress]
145
150
  # Run contents through `Zlib`
146
151
  gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
152
+ gz.mtime = mtime.to_i
147
153
  gz.write to_s
148
154
  gz.close
149
155
  else
150
156
  # Write out as is
151
157
  f.write to_s
152
- f.close
153
158
  end
154
159
  end
155
160
 
@@ -233,7 +238,7 @@ module Sprockets
233
238
  return false
234
239
  end
235
240
 
236
- # Compare dependency mime to the actual mtime. If the
241
+ # Compare dependency mtime to the actual mtime. If the
237
242
  # dependency mtime is newer than the actual mtime, the file
238
243
  # hasn't changed since we created this `Asset` instance.
239
244
  #
@@ -241,7 +246,11 @@ module Sprockets
241
246
  # stale. Many deployment environments may recopy or recheckout
242
247
  # assets on each deploy. In this case the mtime would be the
243
248
  # time of deploy rather than modified time.
244
- if mtime >= stat.mtime
249
+ #
250
+ # Note: to_i is used in eql? and write_to we assume fidelity of 1 second
251
+ # if people save files more frequently than 1 second sprockets may
252
+ # not pick it up, by design
253
+ if mtime.to_i >= stat.mtime.to_i
245
254
  return true
246
255
  end
247
256
 
@@ -17,10 +17,21 @@ module Sprockets
17
17
  def search_paths
18
18
  paths = [pathname.to_s]
19
19
 
20
- if pathname.basename(extensions.join).to_s != 'index'
21
- path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') }
22
- index_path = path_without_extensions.join("index#{extensions.join}").to_s
23
- paths << index_path
20
+ extension = format_extension
21
+ path_without_extension = extension ?
22
+ pathname.sub(extension, '') :
23
+ pathname
24
+
25
+ # optimization: bower.json can only be nested one level deep
26
+ if !path_without_extension.to_s.index('/')
27
+ paths << path_without_extension.join(".bower.json").to_s
28
+ paths << path_without_extension.join("bower.json").to_s
29
+ # DEPRECATED bower configuration file
30
+ paths << path_without_extension.join("component.json").to_s
31
+ end
32
+
33
+ if pathname.basename(extension.to_s).to_s != 'index'
34
+ paths << path_without_extension.join("index#{extension}").to_s
24
35
  end
25
36
 
26
37
  paths