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
@@ -0,0 +1,32 @@
1
+ require 'eco'
2
+
3
+ module Sprockets
4
+ # Processor engine class for the Eco compiler. Depends on the `eco` gem.
5
+ #
6
+ # For more infomation see:
7
+ #
8
+ # https://github.com/sstephenson/ruby-eco
9
+ # https://github.com/sstephenson/eco
10
+ #
11
+ module EcoProcessor
12
+ VERSION = '1'
13
+
14
+ def self.cache_key
15
+ @cache_key ||= [name, ::Eco::Source::VERSION, VERSION].freeze
16
+ end
17
+
18
+ # Compile template data with Eco compiler.
19
+ #
20
+ # Returns a JS function definition String. The result should be
21
+ # assigned to a JS variable.
22
+ #
23
+ # # => "function(...) {...}"
24
+ #
25
+ def self.call(input)
26
+ data = input[:data]
27
+ input[:cache].fetch(cache_key + [data]) do
28
+ ::Eco.compile(data)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,29 +1,6 @@
1
- require 'eco'
1
+ require 'sprockets/eco_processor'
2
2
 
3
3
  module Sprockets
4
- # Template engine class for the Eco compiler. Depends on the `eco` gem.
5
- #
6
- # For more infomation see:
7
- #
8
- # https://github.com/sstephenson/ruby-eco
9
- # https://github.com/sstephenson/eco
10
- #
11
- module EcoTemplate
12
- VERSION = '1'
13
-
14
- # Compile template data with Eco compiler.
15
- #
16
- # Returns a JS function definition String. The result should be
17
- # assigned to a JS variable.
18
- #
19
- # # => "function(...) {...}"
20
- #
21
- def self.call(input)
22
- data = input[:data]
23
- key = ['EcoTemplate', ::Eco::Source::VERSION, VERSION, data]
24
- input[:cache].fetch(key) do
25
- ::Eco.compile(data)
26
- end
27
- end
28
- end
4
+ # Deprecated
5
+ EcoTemplate = EcoProcessor
29
6
  end
@@ -0,0 +1,31 @@
1
+ require 'ejs'
2
+
3
+ module Sprockets
4
+ # Processor engine class for the EJS compiler. Depends on the `ejs` gem.
5
+ #
6
+ # For more infomation see:
7
+ #
8
+ # https://github.com/sstephenson/ruby-ejs
9
+ #
10
+ module EjsProcessor
11
+ VERSION = '1'
12
+
13
+ def self.cache_key
14
+ @cache_key ||= [name, VERSION].freeze
15
+ end
16
+
17
+ # Compile template data with EJS compiler.
18
+ #
19
+ # Returns a JS function definition String. The result should be
20
+ # assigned to a JS variable.
21
+ #
22
+ # # => "function(obj){...}"
23
+ #
24
+ def self.call(input)
25
+ data = input[:data]
26
+ input[:cache].fetch(cache_key + [data]) do
27
+ ::EJS.compile(data)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,28 +1,6 @@
1
- require 'ejs'
1
+ require 'sprockets/ejs_processor'
2
2
 
3
3
  module Sprockets
4
- # Template engine class for the EJS compiler. Depends on the `ejs` gem.
5
- #
6
- # For more infomation see:
7
- #
8
- # https://github.com/sstephenson/ruby-ejs
9
- #
10
- module EjsTemplate
11
- VERSION = '1'
12
-
13
- # Compile template data with EJS compiler.
14
- #
15
- # Returns a JS function definition String. The result should be
16
- # assigned to a JS variable.
17
- #
18
- # # => "function(obj){...}"
19
- #
20
- def self.call(input)
21
- data = input[:data]
22
- key = ['EjsTemplate', VERSION, data]
23
- input[:cache].fetch(key) do
24
- ::EJS.compile(data)
25
- end
26
- end
27
- end
4
+ # Deprecated
5
+ EjsTemplate = EjsProcessor
28
6
  end
@@ -3,6 +3,8 @@ require 'stringio'
3
3
  require 'zlib'
4
4
 
5
5
  module Sprockets
6
+ # Internal: HTTP transport encoding and charset detecting related functions.
7
+ # Mixed into Environment.
6
8
  module EncodingUtils
7
9
  extend self
8
10
 
@@ -24,9 +26,6 @@ module Sprockets
24
26
  deflater.finish
25
27
  end
26
28
 
27
- # Public: Alias for CodingUtils.deflate
28
- DEFLATE = method(:deflate)
29
-
30
29
  # Internal: Unmarshal optionally deflated data.
31
30
  #
32
31
  # Checks leading marshal header to see if the bytes are uncompressed
@@ -65,9 +64,6 @@ module Sprockets
65
64
  io.string
66
65
  end
67
66
 
68
- # Public: Alias for CodingUtils.gzip
69
- GZIP = method(:gzip)
70
-
71
67
  # Public: Use base64 to encode data.
72
68
  #
73
69
  # str - String data
@@ -77,12 +73,12 @@ module Sprockets
77
73
  Base64.strict_encode64(str)
78
74
  end
79
75
 
80
- # Public: Alias for CodingUtils.base64
81
- BASE64 = method(:base64)
82
-
83
76
 
84
77
  ## Charset encodings ##
85
78
 
79
+ # Internal: Shorthand aliases for detecter functions.
80
+ CHARSET_DETECT = {}
81
+
86
82
  # Internal: Mapping unicode encodings to byte order markers.
87
83
  BOM = {
88
84
  Encoding::UTF_32LE => [0xFF, 0xFE, 0x00, 0x00],
@@ -115,9 +111,7 @@ module Sprockets
115
111
 
116
112
  str
117
113
  end
118
-
119
- # Public: Alias for EncodingUtils.detect_unicode
120
- DETECT = method(:detect)
114
+ CHARSET_DETECT[:default] = method(:detect)
121
115
 
122
116
  # Internal: Use Charlock Holmes to detect encoding.
123
117
  #
@@ -151,9 +145,7 @@ module Sprockets
151
145
 
152
146
  str
153
147
  end
154
-
155
- # Public: Alias for EncodingUtils.detect_unicode
156
- DETECT_UNICODE = method(:detect_unicode)
148
+ CHARSET_DETECT[:unicode] = method(:detect_unicode)
157
149
 
158
150
  # Public: Detect and strip BOM from possible unicode string.
159
151
  #
@@ -201,9 +193,7 @@ module Sprockets
201
193
 
202
194
  str
203
195
  end
204
-
205
- # Public: Alias for EncodingUtils.detect_css
206
- DETECT_CSS = method(:detect_css)
196
+ CHARSET_DETECT[:css] = method(:detect_css)
207
197
 
208
198
  # Internal: @charset bytes
209
199
  CHARSET_START = [0x40, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x20, 0x22]
@@ -263,8 +253,6 @@ module Sprockets
263
253
 
264
254
  str
265
255
  end
266
-
267
- # Public: Alias for EncodingUtils.detect_html
268
- DETECT_HTML = method(:detect_html)
256
+ CHARSET_DETECT[:html] = method(:detect_html)
269
257
  end
270
258
  end
@@ -1,4 +1,3 @@
1
- require 'sprockets/lazy_processor'
2
1
  require 'sprockets/legacy_tilt_processor'
3
2
  require 'sprockets/utils'
4
3
 
@@ -7,11 +6,11 @@ module Sprockets
7
6
  #
8
7
  # An engine is a type of processor that is bound to a filename
9
8
  # extension. `application.js.coffee` indicates that the
10
- # `CoffeeScriptTemplate` engine will be ran on the file.
9
+ # `CoffeeScriptProcessor` engine will be ran on the file.
11
10
  #
12
11
  # Extensions can be stacked and will be evaulated from right to
13
- # left. `application.js.coffee.erb` will first run `ERBTemplate`
14
- # then `CoffeeScriptTemplate`.
12
+ # left. `application.js.coffee.erb` will first run `ERBProcessor`
13
+ # then `CoffeeScriptProcessor`.
15
14
  #
16
15
  # All `Engine`s must follow the `Template` interface. It is
17
16
  # recommended to subclass `Template`.
@@ -23,63 +22,62 @@ module Sprockets
23
22
  #
24
23
  # The global registry is exposed for plugins to register themselves.
25
24
  #
26
- # Sprockets.register_engine '.sass', SassTemplate
25
+ # Sprockets.register_engine '.sass', SassProcessor
27
26
  #
28
27
  module Engines
28
+ include Utils
29
+
29
30
  # Returns a `Hash` of `Engine`s registered on the `Environment`.
30
31
  # If an `ext` argument is supplied, the `Engine` associated with
31
32
  # that extension will be returned.
32
33
  #
33
34
  # environment.engines
34
- # # => {".coffee" => CoffeeScriptTemplate, ".sass" => SassTemplate, ...}
35
+ # # => {".coffee" => CoffeeScriptProcessor, ".sass" => SassProcessor, ...}
35
36
  #
36
- attr_reader :engines
37
+ def engines
38
+ config[:engines]
39
+ end
37
40
 
38
41
  # Internal: Returns a `Hash` of engine extensions to mime types.
39
42
  #
40
43
  # # => { '.coffee' => 'application/javascript' }
41
- attr_reader :engine_mime_types
42
-
43
- # Internal: Find and load engines by extension.
44
- #
45
- # extnames - Array of String extnames
46
- #
47
- # Returns Array of Procs.
48
- def unwrap_engines(extnames)
49
- extnames.map { |ext|
50
- engines[ext]
51
- }.map { |engine|
52
- unwrap_processor(engine)
53
- }
44
+ def engine_mime_types
45
+ config[:engine_mime_types]
54
46
  end
55
47
 
56
48
  # Registers a new Engine `klass` for `ext`. If the `ext` already
57
49
  # has an engine registered, it will be overridden.
58
50
  #
59
- # environment.register_engine '.coffee', CoffeeScriptTemplate
51
+ # environment.register_engine '.coffee', CoffeeScriptProcessor
60
52
  #
61
53
  def register_engine(ext, klass, options = {})
62
54
  ext = Sprockets::Utils.normalize_extension(ext)
63
55
 
64
- if klass.class == Sprockets::LazyProcessor || klass.respond_to?(:call)
65
- mutate_config(:engines) do |engines|
56
+ if klass.class == Sprockets::AutoloadProcessor || klass.respond_to?(:call)
57
+ processor = klass
58
+ self.config = hash_reassoc(config, :engines) do |engines|
66
59
  engines.merge(ext => klass)
67
60
  end
68
61
  if options[:mime_type]
69
- mutate_config(:engine_mime_types) do |mime_types|
62
+ self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
70
63
  mime_types.merge(ext.to_s => options[:mime_type])
71
64
  end
72
65
  end
73
66
  else
74
- mutate_config(:engines) do |engines|
75
- engines.merge(ext => LegacyTiltProcessor.new(klass))
67
+ processor = LegacyTiltProcessor.new(klass)
68
+ self.config = hash_reassoc(config, :engines) do |engines|
69
+ engines.merge(ext => processor)
76
70
  end
77
71
  if klass.respond_to?(:default_mime_type) && klass.default_mime_type
78
- mutate_config(:engine_mime_types) do |mime_types|
72
+ self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
79
73
  mime_types.merge(ext.to_s => klass.default_mime_type)
80
74
  end
81
75
  end
82
76
  end
77
+
78
+ self.config = hash_reassoc(config, :_extnames) do
79
+ compute_extname_map
80
+ end
83
81
  end
84
82
  end
85
83
  end
@@ -11,7 +11,7 @@ module Sprockets
11
11
  #
12
12
  def initialize(root = ".")
13
13
  initialize_configuration(Sprockets)
14
- @root = File.expand_path(root)
14
+ self.root = root
15
15
  self.cache = Cache::MemoryStore.new
16
16
  yield self if block_given?
17
17
  end
@@ -29,5 +29,13 @@ module Sprockets
29
29
  def find_asset(*args)
30
30
  cached.find_asset(*args)
31
31
  end
32
+
33
+ def find_all_linked_assets(*args, &block)
34
+ cached.find_all_linked_assets(*args, &block)
35
+ end
36
+
37
+ def load(*args)
38
+ cached.load(*args)
39
+ end
32
40
  end
33
41
  end
@@ -0,0 +1,30 @@
1
+ require 'erb'
2
+
3
+ module Sprockets
4
+ class ERBProcessor
5
+ # Public: Return singleton instance with default options.
6
+ #
7
+ # Returns ERBProcessor object.
8
+ def self.instance
9
+ @instance ||= new
10
+ end
11
+
12
+ def self.call(input)
13
+ instance.call(input)
14
+ end
15
+
16
+ def initialize(&block)
17
+ @block = block
18
+ end
19
+
20
+ def call(input)
21
+ engine = ::ERB.new(input[:data], nil, '<>')
22
+ context = input[:environment].context_class.new(input)
23
+ klass = (class << context; self; end)
24
+ klass.class_eval(&@block) if @block
25
+ engine.def_method(klass, :_evaluate_template, input[:filename])
26
+ data = context._evaluate_template
27
+ context.metadata.merge(data: data)
28
+ end
29
+ end
30
+ end
@@ -1,23 +1,6 @@
1
- require 'erb'
1
+ require 'sprockets/erb_processor'
2
2
 
3
3
  module Sprockets
4
- class ERBTemplate
5
- def self.call(input)
6
- new.call(input)
7
- end
8
-
9
- def initialize(&block)
10
- @block = block
11
- end
12
-
13
- def call(input)
14
- engine = ::ERB.new(input[:data], nil, '<>')
15
- context = input[:environment].context_class.new(input)
16
- klass = (class << context; self; end)
17
- klass.class_eval(&@block) if @block
18
- engine.def_method(klass, :_evaluate_template, input[:filename])
19
- data = context._evaluate_template
20
- context.metadata.merge(data: data)
21
- end
22
- end
4
+ # Deprecated
5
+ ERBTemplate = ERBProcessor
23
6
  end
@@ -0,0 +1,15 @@
1
+ require 'set'
2
+
3
+ module Sprockets
4
+ # Internal: The first processor in the pipeline that reads the file into
5
+ # memory and passes it along as `input[:data]`.
6
+ class FileReader
7
+ def self.call(input)
8
+ env = input[:environment]
9
+ data = env.read_file(input[:filename], input[:content_type])
10
+ dependencies = Set.new(input[:metadata][:dependencies])
11
+ dependencies += [env.build_file_digest_uri(input[:filename])]
12
+ { data: data, dependencies: dependencies }
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,6 @@
1
1
  module Sprockets
2
+ # Internal: HTTP URI utilities. Many adapted from Rack::Utils. Mixed into
3
+ # Environment.
2
4
  module HTTPUtils
3
5
  extend self
4
6
 
@@ -22,8 +22,15 @@ module Sprockets
22
22
  'this.JST'
23
23
  end
24
24
 
25
- def self.call(*args)
26
- new.call(*args)
25
+ # Public: Return singleton instance with default options.
26
+ #
27
+ # Returns JstProcessor object.
28
+ def self.instance
29
+ @instance ||= new
30
+ end
31
+
32
+ def self.call(input)
33
+ instance.call(input)
27
34
  end
28
35
 
29
36
  def initialize(options = {})