sprockets 3.0.0.beta.4 → 3.0.0.beta.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
2
  SHA1:
3
- metadata.gz: bfc75742a9bbe41f39e393933281cc8210d2e2f2
4
- data.tar.gz: ceaf8d045782996a37e7e00f48084bf8fbbd7355
3
+ metadata.gz: 6a6bee17ca558f25cc69850e82405f479f3d3af3
4
+ data.tar.gz: b513251bb8582e5fc2d30ccf3b0a65336e14edd9
5
5
  SHA512:
6
- metadata.gz: c59092430bb9da574a2fcbb28b1e2d3ef69dfcfc38103e6e95da4de969e8ce6526d24e2900041bd76d9327453f385386e8225684ea8ade1fa20d740cbdf44897
7
- data.tar.gz: 95594832c3a2911d30d3e467271d66fc1f367472b4617e4b5137ed70e2c30aa6124cadf6a4a06bced8f00874a9a5481d2a21a7e45813d5f652e77b7772424946
6
+ metadata.gz: 2b16c9ea238f143f8b9e0881c74748446ae160179db5895195d00075e72eb7982630270ab8e1609ed93d05a86259d48b21c29723d9c9e90749b6010fa6599b89
7
+ data.tar.gz: 02c9e685bb2b994590402d7761b5476dc6c67afb49563ea04b6493c5b89a16d17069176ab4c3d7900367b41176ee059d2f653416d002dc4b7393c64ce9622794
@@ -1,6 +1,7 @@
1
1
  require 'digest/md5'
2
2
  require 'fileutils'
3
3
  require 'logger'
4
+ require 'zlib'
4
5
 
5
6
  module Sprockets
6
7
  class Cache
@@ -52,7 +53,13 @@ module Sprockets
52
53
 
53
54
  value = safe_open(path) do |f|
54
55
  begin
55
- Marshal.load(f)
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
63
  rescue Exception => e
57
64
  @logger.error do
58
65
  "#{self.class}[#{path}] could not be unmarshaled: " +
@@ -85,9 +92,26 @@ module Sprockets
85
92
  # Check if cache exists before writing
86
93
  exists = File.exist?(path)
87
94
 
95
+ # Serialize value
96
+ marshaled = Marshal.dump(value)
97
+
98
+ # Compress if larger than 4KB
99
+ if marshaled.bytesize > 4 * 1024
100
+ deflater = Zlib::Deflate.new(
101
+ Zlib::BEST_COMPRESSION,
102
+ Zlib::MAX_WBITS,
103
+ Zlib::MAX_MEM_LEVEL,
104
+ Zlib::DEFAULT_STRATEGY
105
+ )
106
+ deflater << marshaled
107
+ raw = deflater.finish
108
+ else
109
+ raw = marshaled
110
+ end
111
+
88
112
  # Write data
89
113
  PathUtils.atomic_write(path) do |f|
90
- Marshal.dump(value, f)
114
+ f.write(raw)
91
115
  @size += f.size unless exists
92
116
  end
93
117
 
@@ -21,6 +21,9 @@ module Sprockets
21
21
  class Context
22
22
  attr_reader :environment, :filename, :pathname
23
23
 
24
+ # Deprecated
25
+ attr_accessor :__LINE__
26
+
24
27
  def initialize(input)
25
28
  @environment = input[:environment]
26
29
  @metadata = input[:metadata]
@@ -67,6 +70,7 @@ module Sprockets
67
70
  attr_reader :content_type
68
71
 
69
72
  # Internal
73
+ # TODO: Cleanup relative resolver logic shared between directive processor.
70
74
  def _resolve(method, path, options = {})
71
75
  options[:content_type] = self.content_type if options[:content_type] == :self
72
76
  options[:accept] = options.delete(:content_type)
@@ -337,6 +337,71 @@ module Sprockets
337
337
  end
338
338
  end
339
339
 
340
+ # `link_directory` links all the files inside a single
341
+ # directory. It's similar to `path/*` since it does not follow
342
+ # nested directories.
343
+ #
344
+ # //= link_directory "./fonts"
345
+ #
346
+ def process_link_directory_directive(path = ".")
347
+ if @environment.relative_path?(path)
348
+ root = expand_relative_path(path)
349
+
350
+ unless (stats = @environment.stat(root)) && stats.directory?
351
+ raise ArgumentError, "link_directory argument must be a directory"
352
+ end
353
+
354
+ @dependency_paths << root
355
+
356
+ @environment.stat_directory(root).each do |subpath, stat|
357
+ if subpath == @filename
358
+ next
359
+ elsif stat.directory?
360
+ next
361
+ elsif uri = @environment.locate(subpath)
362
+ asset = @environment.load(uri)
363
+ @dependency_paths.merge(asset.metadata[:dependency_paths])
364
+ @links << asset.uri
365
+ end
366
+ end
367
+ else
368
+ # The path must be relative and start with a `./`.
369
+ raise ArgumentError, "link_directory argument must be a relative path"
370
+ end
371
+ end
372
+
373
+ # `link_tree` links all the nested files in a directory.
374
+ # Its glob equivalent is `path/**/*`.
375
+ #
376
+ # //= link_tree "./images"
377
+ #
378
+ def process_link_tree_directive(path = ".")
379
+ if @environment.relative_path?(path)
380
+ root = expand_relative_path(path)
381
+
382
+ unless (stats = @environment.stat(root)) && stats.directory?
383
+ raise ArgumentError, "link_tree argument must be a directory"
384
+ end
385
+
386
+ @dependency_paths << root
387
+
388
+ @environment.stat_sorted_tree(root).each do |subpath, stat|
389
+ if subpath == @filename
390
+ next
391
+ elsif stat.directory?
392
+ @dependency_paths << subpath
393
+ elsif uri = @environment.locate(subpath)
394
+ asset = @environment.load(uri)
395
+ @dependency_paths.merge(asset.metadata[:dependency_paths])
396
+ @links << asset.uri
397
+ end
398
+ end
399
+ else
400
+ # The path must be relative and start with a `./`.
401
+ raise ArgumentError, "link_tree argument must be a relative path"
402
+ end
403
+ end
404
+
340
405
  private
341
406
  def expand_relative_path(path)
342
407
  File.expand_path(path, @dirname)
@@ -350,6 +415,7 @@ module Sprockets
350
415
  _resolve(:resolve, path, options)
351
416
  end
352
417
 
418
+ # TODO: Cleanup relative resolver logic shared between context.
353
419
  def _resolve(method, path, options = {})
354
420
  if @environment.absolute_path?(path)
355
421
  raise FileOutsidePaths, "can't require absolute file: #{path}"
@@ -53,6 +53,14 @@ module Sprockets
53
53
  nil
54
54
  end
55
55
 
56
+ def cache_get(key)
57
+ cache._get(key)
58
+ end
59
+
60
+ def cache_set(key, value)
61
+ cache._set(key, value)
62
+ end
63
+
56
64
  private
57
65
  # Deprecated: Seriously.
58
66
  def matches_filter(filters, logical_path, filename)
@@ -144,7 +144,6 @@ module Sprockets
144
144
  )
145
145
  else
146
146
  asset[:metadata] = {
147
- encoding: Encoding::BINARY,
148
147
  digest: file_digest(asset[:filename]),
149
148
  length: self.stat(asset[:filename]).size
150
149
  }
@@ -0,0 +1,2 @@
1
+ # Deprecated: Require sprockets/sass_template instead
2
+ require 'sprockets/sass_template'
@@ -0,0 +1,2 @@
1
+ # Deprecated: Require sprockets/sass_template instead
2
+ require 'sprockets/sass_template'
@@ -0,0 +1,2 @@
1
+ # Deprecated: Require sprockets/sass_template instead
2
+ require 'sprockets/sass_template'
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "3.0.0.beta.4"
2
+ VERSION = "3.0.0.beta.5"
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.4
4
+ version: 3.0.0.beta.5
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-24 00:00:00.000000000 Z
12
+ date: 2014-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -260,7 +260,10 @@ files:
260
260
  - lib/sprockets/paths.rb
261
261
  - lib/sprockets/processing.rb
262
262
  - lib/sprockets/resolve.rb
263
+ - lib/sprockets/sass_cache_store.rb
263
264
  - lib/sprockets/sass_compressor.rb
265
+ - lib/sprockets/sass_functions.rb
266
+ - lib/sprockets/sass_importer.rb
264
267
  - lib/sprockets/sass_template.rb
265
268
  - lib/sprockets/server.rb
266
269
  - lib/sprockets/transformers.rb