sprockets 3.0.0.beta.6 → 3.0.0.beta.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +171 -100
  3. data/lib/rake/sprocketstask.rb +2 -2
  4. data/lib/sprockets.rb +69 -63
  5. data/lib/sprockets/asset.rb +2 -61
  6. data/lib/sprockets/autoload_processor.rb +48 -0
  7. data/lib/sprockets/base.rb +4 -6
  8. data/lib/sprockets/bower.rb +8 -5
  9. data/lib/sprockets/bundle.rb +9 -13
  10. data/lib/sprockets/cache.rb +19 -14
  11. data/lib/sprockets/cache/file_store.rb +2 -1
  12. data/lib/sprockets/cached_environment.rb +15 -68
  13. data/lib/sprockets/closure_compressor.rb +17 -4
  14. data/lib/sprockets/coffee_script_processor.rb +26 -0
  15. data/lib/sprockets/coffee_script_template.rb +3 -20
  16. data/lib/sprockets/compressing.rb +10 -4
  17. data/lib/sprockets/configuration.rb +21 -37
  18. data/lib/sprockets/context.rb +37 -67
  19. data/lib/sprockets/dependencies.rb +73 -0
  20. data/lib/sprockets/digest_utils.rb +8 -2
  21. data/lib/sprockets/directive_processor.rb +122 -165
  22. data/lib/sprockets/eco_processor.rb +32 -0
  23. data/lib/sprockets/eco_template.rb +3 -26
  24. data/lib/sprockets/ejs_processor.rb +31 -0
  25. data/lib/sprockets/ejs_template.rb +3 -25
  26. data/lib/sprockets/encoding_utils.rb +9 -21
  27. data/lib/sprockets/engines.rb +25 -27
  28. data/lib/sprockets/environment.rb +9 -1
  29. data/lib/sprockets/erb_processor.rb +30 -0
  30. data/lib/sprockets/erb_template.rb +3 -20
  31. data/lib/sprockets/file_reader.rb +15 -0
  32. data/lib/sprockets/http_utils.rb +2 -0
  33. data/lib/sprockets/jst_processor.rb +9 -2
  34. data/lib/sprockets/legacy.rb +212 -3
  35. data/lib/sprockets/legacy_tilt_processor.rb +1 -1
  36. data/lib/sprockets/loader.rb +95 -89
  37. data/lib/sprockets/manifest.rb +23 -59
  38. data/lib/sprockets/mime.rb +28 -41
  39. data/lib/sprockets/path_dependency_utils.rb +76 -0
  40. data/lib/sprockets/path_utils.rb +21 -1
  41. data/lib/sprockets/paths.rb +23 -8
  42. data/lib/sprockets/processing.rb +102 -91
  43. data/lib/sprockets/processor_utils.rb +97 -0
  44. data/lib/sprockets/resolve.rb +110 -97
  45. data/lib/sprockets/sass_cache_store.rb +2 -2
  46. data/lib/sprockets/sass_compressor.rb +17 -4
  47. data/lib/sprockets/sass_functions.rb +2 -2
  48. data/lib/sprockets/sass_importer.rb +2 -2
  49. data/lib/sprockets/sass_processor.rb +305 -0
  50. data/lib/sprockets/sass_template.rb +4 -286
  51. data/lib/sprockets/server.rb +1 -13
  52. data/lib/sprockets/transformers.rb +62 -25
  53. data/lib/sprockets/uglifier_compressor.rb +17 -4
  54. data/lib/sprockets/uri_utils.rb +190 -0
  55. data/lib/sprockets/utils.rb +87 -6
  56. data/lib/sprockets/version.rb +1 -1
  57. data/lib/sprockets/yui_compressor.rb +17 -4
  58. metadata +14 -5
  59. data/lib/sprockets/asset_uri.rb +0 -80
  60. data/lib/sprockets/lazy_processor.rb +0 -15
@@ -16,10 +16,23 @@ module Sprockets
16
16
  class UglifierCompressor
17
17
  VERSION = '1'
18
18
 
19
- def self.call(*args)
20
- new.call(*args)
19
+ # Public: Return singleton instance with default options.
20
+ #
21
+ # Returns UglifierCompressor object.
22
+ def self.instance
23
+ @instance ||= new
21
24
  end
22
25
 
26
+ def self.call(input)
27
+ instance.call(input)
28
+ end
29
+
30
+ def self.cache_key
31
+ instance.cache_key
32
+ end
33
+
34
+ attr_reader :cache_key
35
+
23
36
  def initialize(options = {})
24
37
  # Feature detect Uglifier 2.0 option support
25
38
  if Uglifier::DEFAULTS[:copyright]
@@ -33,11 +46,11 @@ module Sprockets
33
46
  @uglifier = ::Uglifier.new(options)
34
47
 
35
48
  @cache_key = [
36
- 'UglifierCompressor',
49
+ self.class.name,
37
50
  ::Uglifier::VERSION,
38
51
  VERSION,
39
52
  options
40
- ]
53
+ ].freeze
41
54
  end
42
55
 
43
56
  def call(input)
@@ -0,0 +1,190 @@
1
+ require 'uri'
2
+
3
+ module Sprockets
4
+ # Internal: Asset URI related parsing utilities. Mixed into Environment.
5
+ #
6
+ # An Asset URI identifies the compiled Asset result. It shares the file:
7
+ # scheme and requires an absolute path.
8
+ #
9
+ # Other query parameters
10
+ #
11
+ # type - String output content type. Otherwise assumed from file extension.
12
+ # This maybe different than the extension if the asset is transformed
13
+ # from one content type to another. For an example .coffee -> .js.
14
+ #
15
+ # id - Unique fingerprint of the entire asset and all its metadata. Assets
16
+ # will only have the same id if they serialize to an identical value.
17
+ #
18
+ # skip_bundle - Boolean if bundle processors should be skipped.
19
+ #
20
+ # encoding - A content encoding such as "gzip" or "deflate". NOT a charset
21
+ # like "utf-8".
22
+ #
23
+ module URIUtils
24
+ extend self
25
+
26
+ # Internal: Parse URI into component parts.
27
+ #
28
+ # uri - String uri
29
+ #
30
+ # Returns Array of components.
31
+ def split_uri(uri)
32
+ URI.split(uri)
33
+ end
34
+
35
+ # Internal: Join URI component parts into String.
36
+ #
37
+ # Returns String.
38
+ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragment)
39
+ URI::Generic.new(scheme, userinfo, host, port, registry, path, opaque, query, fragment).to_s
40
+ end
41
+
42
+ # Internal: Parse file: URI into component parts.
43
+ #
44
+ # uri - String uri
45
+ #
46
+ # Returns [scheme, host, path, query].
47
+ def split_file_uri(uri)
48
+ scheme, _, host, _, _, path, _, query, _ = URI.split(uri)
49
+
50
+ path = URI::Generic::DEFAULT_PARSER.unescape(path)
51
+ path.force_encoding(Encoding::UTF_8)
52
+
53
+ # Hack for parsing Windows "file:///C:/Users/IEUser" paths
54
+ path = path.gsub(/^\/([a-zA-Z]:)/, '\1')
55
+
56
+ [scheme, host, path, query]
57
+ end
58
+
59
+ # Internal: Join file: URI component parts into String.
60
+ #
61
+ # Returns String.
62
+ def join_file_uri(scheme, host, path, query)
63
+ str = "#{scheme}://"
64
+ str << host if host
65
+ path = "/#{path}" unless path.start_with?("/")
66
+ str << URI::Generic::DEFAULT_PARSER.escape(path)
67
+ str << "?#{query}" if query
68
+ str
69
+ end
70
+
71
+ # Internal: Check if String is a valid Asset URI.
72
+ #
73
+ # str - Possible String asset URI.
74
+ #
75
+ # Returns true or false.
76
+ def valid_asset_uri?(str)
77
+ # Quick prefix check before attempting a full parse
78
+ str.start_with?("file://") && parse_asset_uri(str) ? true : false
79
+ rescue URI::InvalidURIError
80
+ false
81
+ end
82
+
83
+ # Internal: Parse Asset URI.
84
+ #
85
+ # Examples
86
+ #
87
+ # parse("file:///tmp/js/application.coffee?type=application/javascript")
88
+ # # => "/tmp/js/application.coffee", {type: "application/javascript"}
89
+ #
90
+ # uri - String asset URI
91
+ #
92
+ # Returns String path and Hash of symbolized parameters.
93
+ def parse_asset_uri(uri)
94
+ scheme, _, path, query = split_file_uri(uri)
95
+
96
+ unless scheme == 'file'
97
+ raise URI::InvalidURIError, "expected file:// scheme: #{uri}"
98
+ end
99
+
100
+ return path, parse_uri_query_params(query)
101
+ end
102
+
103
+ # Internal: Build Asset URI.
104
+ #
105
+ # Examples
106
+ #
107
+ # build("/tmp/js/application.coffee", type: "application/javascript")
108
+ # # => "file:///tmp/js/application.coffee?type=application/javascript"
109
+ #
110
+ # path - String file path
111
+ # params - Hash of optional parameters
112
+ #
113
+ # Returns String URI.
114
+ def build_asset_uri(path, params = {})
115
+ join_file_uri("file", nil, path, encode_uri_query_params(params))
116
+ end
117
+
118
+ # Internal: Parse file-digest dependency URI.
119
+ #
120
+ # Examples
121
+ #
122
+ # parse("file-digest:/tmp/js/application.js")
123
+ # # => "/tmp/js/application.js"
124
+ #
125
+ # uri - String file-digest URI
126
+ #
127
+ # Returns String path.
128
+ def parse_file_digest_uri(uri)
129
+ scheme, _, path, _ = split_file_uri(uri)
130
+
131
+ unless scheme == 'file-digest'
132
+ raise URI::InvalidURIError, "expected file-digest scheme: #{uri}"
133
+ end
134
+
135
+ path
136
+ end
137
+
138
+ # Internal: Build file-digest dependency URI.
139
+ #
140
+ # Examples
141
+ #
142
+ # build("/tmp/js/application.js")
143
+ # # => "file-digest:/tmp/js/application.js"
144
+ #
145
+ # path - String file path
146
+ #
147
+ # Returns String URI.
148
+ def build_file_digest_uri(path)
149
+ join_file_uri("file-digest", nil, path, nil)
150
+ end
151
+
152
+ # Internal: Serialize hash of params into query string.
153
+ #
154
+ # params - Hash of params to serialize
155
+ #
156
+ # Returns String query or nil if empty.
157
+ def encode_uri_query_params(params)
158
+ query = []
159
+
160
+ params.each do |key, value|
161
+ case value
162
+ when Integer
163
+ query << "#{key}=#{value}"
164
+ when String
165
+ query << "#{key}=#{URI::Generic::DEFAULT_PARSER.escape(value)}"
166
+ when TrueClass
167
+ query << "#{key}"
168
+ when FalseClass, NilClass
169
+ else
170
+ raise TypeError, "unexpected type: #{value.class}"
171
+ end
172
+ end
173
+
174
+ "#{query.join('&')}" if query.any?
175
+ end
176
+
177
+ # Internal: Parse query string into hash of params
178
+ #
179
+ # query - String query string
180
+ #
181
+ # Return Hash of params.
182
+ def parse_uri_query_params(query)
183
+ query.to_s.split('&').reduce({}) do |h, p|
184
+ k, v = p.split('=', 2)
185
+ v = URI::Generic::DEFAULT_PARSER.unescape(v) if v
186
+ h.merge(k.to_sym => v || true)
187
+ end
188
+ end
189
+ end
190
+ end
@@ -1,10 +1,71 @@
1
1
  require 'set'
2
2
 
3
3
  module Sprockets
4
- # `Utils`, we didn't know where else to put it!
4
+ # Internal: Utils, we didn't know where else to put it! Functions may
5
+ # eventually be shuffled into more specific drawers.
5
6
  module Utils
6
7
  extend self
7
8
 
9
+ # Internal: Check if object can safely be .dup'd.
10
+ #
11
+ # Similar to ActiveSupport #duplicable? check.
12
+ #
13
+ # obj - Any Object
14
+ #
15
+ # Returns false if .dup would raise a TypeError, otherwise true.
16
+ def duplicable?(obj)
17
+ case obj
18
+ when NilClass, FalseClass, TrueClass, Symbol, Numeric
19
+ false
20
+ else
21
+ true
22
+ end
23
+ end
24
+
25
+ # Internal: Duplicate and store key/value on new frozen hash.
26
+ #
27
+ # Seperated for recursive calls, always use hash_reassoc(hash, *keys).
28
+ #
29
+ # hash - Hash
30
+ # key - Object key
31
+ #
32
+ # Returns Hash.
33
+ def hash_reassoc1(hash, key)
34
+ hash = hash.dup if hash.frozen?
35
+ old_value = hash[key]
36
+ old_value = old_value.dup if duplicable?(old_value)
37
+ new_value = yield old_value
38
+ new_value.freeze if duplicable?(new_value)
39
+ hash.store(key, new_value)
40
+ hash.freeze
41
+ end
42
+
43
+ # Internal: Duplicate and store key/value on new frozen hash.
44
+ #
45
+ # Similar to Hash#store for nested frozen hashes.
46
+ #
47
+ # hash - Hash
48
+ # key - Object keys. Use multiple keys for nested hashes.
49
+ # block - Receives current value at key.
50
+ #
51
+ # Examples
52
+ #
53
+ # config = {paths: ["/bin", "/sbin"]}.freeze
54
+ # new_config = hash_reassoc(config, :paths) do |paths|
55
+ # paths << "/usr/local/bin"
56
+ # end
57
+ #
58
+ # Returns duplicated frozen Hash.
59
+ def hash_reassoc(hash, *keys, &block)
60
+ if keys.size == 1
61
+ hash_reassoc1(hash, keys[0], &block)
62
+ else
63
+ hash_reassoc1(hash, keys[0]) do |value|
64
+ hash_reassoc(value, *keys[1..-1], &block)
65
+ end
66
+ end
67
+ end
68
+
8
69
  # Internal: Check if string has a trailing semicolon.
9
70
  #
10
71
  # str - String
@@ -126,12 +187,32 @@ module Sprockets
126
187
  nodes
127
188
  end
128
189
 
129
- def benchmark_start
130
- Time.now.to_f
131
- end
190
+ # Internal: Post-order Depth-First search algorithm that gathers all paths
191
+ # along the way.
192
+ #
193
+ # TODO: Rename function.
194
+ #
195
+ # path - Initial Array node path
196
+ # block -
197
+ # node - Current node to get children of
198
+ #
199
+ # Returns an Array of node Arrays.
200
+ def dfs_paths(path)
201
+ paths = []
202
+ stack, seen = [path], Set.new
203
+
204
+ while path = stack.pop
205
+ if !seen.include?(path.last)
206
+ seen.add(path.last)
207
+ paths << path if path.size > 1
208
+
209
+ Array(yield path.last).reverse_each do |node|
210
+ stack.push(path + [node])
211
+ end
212
+ end
213
+ end
132
214
 
133
- def benchmark_end(start_time)
134
- ((Time.now.to_f - start_time) * 1000).to_i
215
+ paths
135
216
  end
136
217
  end
137
218
  end
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "3.0.0.beta.6"
2
+ VERSION = "3.0.0.beta.7"
3
3
  end
@@ -16,18 +16,31 @@ module Sprockets
16
16
  class YUICompressor
17
17
  VERSION = '1'
18
18
 
19
- def self.call(*args)
20
- new.call(*args)
19
+ # Public: Return singleton instance with default options.
20
+ #
21
+ # Returns YUICompressor object.
22
+ def self.instance
23
+ @instance ||= new
21
24
  end
22
25
 
26
+ def self.call(input)
27
+ instance.call(input)
28
+ end
29
+
30
+ def self.cache_key
31
+ instance.cache_key
32
+ end
33
+
34
+ attr_reader :cache_key
35
+
23
36
  def initialize(options = {})
24
37
  @options = options
25
38
  @cache_key = [
26
- 'YUICompressor',
39
+ self.class.name,
27
40
  ::YUI::Compressor::VERSION,
28
41
  VERSION,
29
42
  options
30
- ]
43
+ ].freeze
31
44
  end
32
45
 
33
46
  def call(input)
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.6
4
+ version: 3.0.0.beta.7
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-12-03 00:00:00.000000000 Z
12
+ date: 2015-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -223,7 +223,7 @@ files:
223
223
  - lib/rake/sprocketstask.rb
224
224
  - lib/sprockets.rb
225
225
  - lib/sprockets/asset.rb
226
- - lib/sprockets/asset_uri.rb
226
+ - lib/sprockets/autoload_processor.rb
227
227
  - lib/sprockets/base.rb
228
228
  - lib/sprockets/bower.rb
229
229
  - lib/sprockets/bundle.rb
@@ -233,41 +233,50 @@ files:
233
233
  - lib/sprockets/cache/null_store.rb
234
234
  - lib/sprockets/cached_environment.rb
235
235
  - lib/sprockets/closure_compressor.rb
236
+ - lib/sprockets/coffee_script_processor.rb
236
237
  - lib/sprockets/coffee_script_template.rb
237
238
  - lib/sprockets/compressing.rb
238
239
  - lib/sprockets/configuration.rb
239
240
  - lib/sprockets/context.rb
241
+ - lib/sprockets/dependencies.rb
240
242
  - lib/sprockets/digest_utils.rb
241
243
  - lib/sprockets/directive_processor.rb
244
+ - lib/sprockets/eco_processor.rb
242
245
  - lib/sprockets/eco_template.rb
246
+ - lib/sprockets/ejs_processor.rb
243
247
  - lib/sprockets/ejs_template.rb
244
248
  - lib/sprockets/encoding_utils.rb
245
249
  - lib/sprockets/engines.rb
246
250
  - lib/sprockets/environment.rb
251
+ - lib/sprockets/erb_processor.rb
247
252
  - lib/sprockets/erb_template.rb
248
253
  - lib/sprockets/errors.rb
254
+ - lib/sprockets/file_reader.rb
249
255
  - lib/sprockets/http_utils.rb
250
256
  - lib/sprockets/jst_processor.rb
251
- - lib/sprockets/lazy_processor.rb
252
257
  - lib/sprockets/legacy.rb
253
258
  - lib/sprockets/legacy_proc_processor.rb
254
259
  - lib/sprockets/legacy_tilt_processor.rb
255
260
  - lib/sprockets/loader.rb
256
261
  - lib/sprockets/manifest.rb
257
262
  - lib/sprockets/mime.rb
263
+ - lib/sprockets/path_dependency_utils.rb
258
264
  - lib/sprockets/path_digest_utils.rb
259
265
  - lib/sprockets/path_utils.rb
260
266
  - lib/sprockets/paths.rb
261
267
  - lib/sprockets/processing.rb
268
+ - lib/sprockets/processor_utils.rb
262
269
  - lib/sprockets/resolve.rb
263
270
  - lib/sprockets/sass_cache_store.rb
264
271
  - lib/sprockets/sass_compressor.rb
265
272
  - lib/sprockets/sass_functions.rb
266
273
  - lib/sprockets/sass_importer.rb
274
+ - lib/sprockets/sass_processor.rb
267
275
  - lib/sprockets/sass_template.rb
268
276
  - lib/sprockets/server.rb
269
277
  - lib/sprockets/transformers.rb
270
278
  - lib/sprockets/uglifier_compressor.rb
279
+ - lib/sprockets/uri_utils.rb
271
280
  - lib/sprockets/utils.rb
272
281
  - lib/sprockets/version.rb
273
282
  - lib/sprockets/yui_compressor.rb
@@ -291,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
300
  version: 1.3.1
292
301
  requirements: []
293
302
  rubyforge_project: sprockets
294
- rubygems_version: 2.2.2
303
+ rubygems_version: 2.4.5
295
304
  signing_key:
296
305
  specification_version: 4
297
306
  summary: Rack-based asset packaging system