sprockets 2.11.3 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +296 -0
  3. data/LICENSE +2 -2
  4. data/README.md +235 -242
  5. data/bin/sprockets +1 -0
  6. data/lib/rake/sprocketstask.rb +5 -4
  7. data/lib/sprockets/asset.rb +143 -210
  8. data/lib/sprockets/autoload/closure.rb +7 -0
  9. data/lib/sprockets/autoload/coffee_script.rb +7 -0
  10. data/lib/sprockets/autoload/eco.rb +7 -0
  11. data/lib/sprockets/autoload/ejs.rb +7 -0
  12. data/lib/sprockets/autoload/sass.rb +7 -0
  13. data/lib/sprockets/autoload/uglifier.rb +7 -0
  14. data/lib/sprockets/autoload/yui.rb +7 -0
  15. data/lib/sprockets/autoload.rb +11 -0
  16. data/lib/sprockets/base.rb +56 -393
  17. data/lib/sprockets/bower.rb +58 -0
  18. data/lib/sprockets/bundle.rb +69 -0
  19. data/lib/sprockets/cache/file_store.rb +168 -14
  20. data/lib/sprockets/cache/memory_store.rb +66 -0
  21. data/lib/sprockets/cache/null_store.rb +46 -0
  22. data/lib/sprockets/cache.rb +236 -0
  23. data/lib/sprockets/cached_environment.rb +69 -0
  24. data/lib/sprockets/closure_compressor.rb +35 -10
  25. data/lib/sprockets/coffee_script_processor.rb +25 -0
  26. data/lib/sprockets/coffee_script_template.rb +17 -0
  27. data/lib/sprockets/compressing.rb +44 -23
  28. data/lib/sprockets/configuration.rb +83 -0
  29. data/lib/sprockets/context.rb +86 -144
  30. data/lib/sprockets/dependencies.rb +73 -0
  31. data/lib/sprockets/deprecation.rb +90 -0
  32. data/lib/sprockets/digest_utils.rb +180 -0
  33. data/lib/sprockets/directive_processor.rb +207 -211
  34. data/lib/sprockets/eco_processor.rb +32 -0
  35. data/lib/sprockets/eco_template.rb +9 -30
  36. data/lib/sprockets/ejs_processor.rb +31 -0
  37. data/lib/sprockets/ejs_template.rb +9 -29
  38. data/lib/sprockets/encoding_utils.rb +261 -0
  39. data/lib/sprockets/engines.rb +53 -35
  40. data/lib/sprockets/environment.rb +17 -64
  41. data/lib/sprockets/erb_processor.rb +30 -0
  42. data/lib/sprockets/erb_template.rb +11 -0
  43. data/lib/sprockets/errors.rb +4 -13
  44. data/lib/sprockets/file_reader.rb +15 -0
  45. data/lib/sprockets/http_utils.rb +117 -0
  46. data/lib/sprockets/jst_processor.rb +35 -15
  47. data/lib/sprockets/legacy.rb +330 -0
  48. data/lib/sprockets/legacy_proc_processor.rb +35 -0
  49. data/lib/sprockets/legacy_tilt_processor.rb +29 -0
  50. data/lib/sprockets/loader.rb +325 -0
  51. data/lib/sprockets/manifest.rb +202 -127
  52. data/lib/sprockets/manifest_utils.rb +45 -0
  53. data/lib/sprockets/mime.rb +112 -31
  54. data/lib/sprockets/path_dependency_utils.rb +85 -0
  55. data/lib/sprockets/path_digest_utils.rb +47 -0
  56. data/lib/sprockets/path_utils.rb +287 -0
  57. data/lib/sprockets/paths.rb +42 -19
  58. data/lib/sprockets/processing.rb +178 -126
  59. data/lib/sprockets/processor_utils.rb +180 -0
  60. data/lib/sprockets/resolve.rb +211 -0
  61. data/lib/sprockets/sass_cache_store.rb +22 -17
  62. data/lib/sprockets/sass_compressor.rb +39 -15
  63. data/lib/sprockets/sass_functions.rb +2 -70
  64. data/lib/sprockets/sass_importer.rb +2 -29
  65. data/lib/sprockets/sass_processor.rb +292 -0
  66. data/lib/sprockets/sass_template.rb +12 -53
  67. data/lib/sprockets/server.rb +129 -84
  68. data/lib/sprockets/transformers.rb +145 -0
  69. data/lib/sprockets/uglifier_compressor.rb +39 -12
  70. data/lib/sprockets/unloaded_asset.rb +137 -0
  71. data/lib/sprockets/uri_tar.rb +98 -0
  72. data/lib/sprockets/uri_utils.rb +188 -0
  73. data/lib/sprockets/utils/gzip.rb +67 -0
  74. data/lib/sprockets/utils.rb +210 -44
  75. data/lib/sprockets/version.rb +1 -1
  76. data/lib/sprockets/yui_compressor.rb +39 -11
  77. data/lib/sprockets.rb +142 -81
  78. metadata +100 -80
  79. data/lib/sprockets/asset_attributes.rb +0 -137
  80. data/lib/sprockets/bundled_asset.rb +0 -78
  81. data/lib/sprockets/caching.rb +0 -96
  82. data/lib/sprockets/charset_normalizer.rb +0 -41
  83. data/lib/sprockets/index.rb +0 -100
  84. data/lib/sprockets/processed_asset.rb +0 -152
  85. data/lib/sprockets/processor.rb +0 -32
  86. data/lib/sprockets/safety_colons.rb +0 -28
  87. data/lib/sprockets/scss_template.rb +0 -13
  88. data/lib/sprockets/static_asset.rb +0 -58
@@ -1,37 +1,17 @@
1
- require 'tilt'
1
+ require 'sprockets/ejs_processor'
2
2
 
3
3
  module Sprockets
4
- # Tilt 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
- class EjsTemplate < Tilt::Template
11
- # Check to see if EJS is loaded
12
- def self.engine_initialized?
13
- defined? ::EJS
14
- end
15
-
16
- # Autoload ejs library. If the library isn't loaded, Tilt will produce
17
- # a thread safetly warning. If you intend to use `.ejs` files, you
18
- # should explicitly require it.
19
- def initialize_engine
20
- require_template_library 'ejs'
21
- end
4
+ # Deprecated
5
+ module EjsTemplate
6
+ VERSION = EjsProcessor::VERSION
22
7
 
23
- def prepare
8
+ def self.cache_key
9
+ EjsProcessor.cache_key
24
10
  end
25
11
 
26
- # Compile template data with EJS compiler.
27
- #
28
- # Returns a JS function definition String. The result should be
29
- # assigned to a JS variable.
30
- #
31
- # # => "function(obj){...}"
32
- #
33
- def evaluate(scope, locals, &block)
34
- EJS.compile(data)
12
+ def self.call(*args)
13
+ Deprecation.new.warn "EjsTemplate is deprecated please use EjsProcessor instead"
14
+ EjsProcessor.call(*args)
35
15
  end
36
16
  end
37
17
  end
@@ -0,0 +1,261 @@
1
+ require 'base64'
2
+ require 'stringio'
3
+ require 'zlib'
4
+
5
+ module Sprockets
6
+ # Internal: HTTP transport encoding and charset detecting related functions.
7
+ # Mixed into Environment.
8
+ module EncodingUtils
9
+ extend self
10
+
11
+ ## Binary encodings ##
12
+
13
+ # Public: Use deflate to compress data.
14
+ #
15
+ # str - String data
16
+ #
17
+ # Returns a compressed String
18
+ def deflate(str)
19
+ deflater = Zlib::Deflate.new(
20
+ Zlib::BEST_COMPRESSION,
21
+ -Zlib::MAX_WBITS,
22
+ Zlib::MAX_MEM_LEVEL,
23
+ Zlib::DEFAULT_STRATEGY
24
+ )
25
+ deflater << str
26
+ deflater.finish
27
+ end
28
+
29
+ # Internal: Unmarshal optionally deflated data.
30
+ #
31
+ # Checks leading marshal header to see if the bytes are uncompressed
32
+ # otherwise inflate the data an unmarshal.
33
+ #
34
+ # str - Marshaled String
35
+ # window_bits - Integer deflate window size. See ZLib::Inflate.new()
36
+ #
37
+ # Returns unmarshaled Object or raises an Exception.
38
+ def unmarshaled_deflated(str, window_bits = -Zlib::MAX_WBITS)
39
+ major, minor = str[0], str[1]
40
+ if major && major.ord == Marshal::MAJOR_VERSION &&
41
+ minor && minor.ord <= Marshal::MINOR_VERSION
42
+ marshaled = str
43
+ else
44
+ begin
45
+ marshaled = Zlib::Inflate.new(window_bits).inflate(str)
46
+ rescue Zlib::DataError
47
+ marshaled = str
48
+ end
49
+ end
50
+ Marshal.load(marshaled)
51
+ end
52
+
53
+ # Public: Use gzip to compress data.
54
+ #
55
+ # str - String data
56
+ #
57
+ # Returns a compressed String
58
+ def gzip(str)
59
+ io = StringIO.new
60
+ gz = Zlib::GzipWriter.new(io, Zlib::BEST_COMPRESSION)
61
+ gz.mtime = 1
62
+ gz << str
63
+ gz.finish
64
+ io.string
65
+ end
66
+
67
+ # Public: Use base64 to encode data.
68
+ #
69
+ # str - String data
70
+ #
71
+ # Returns a encoded String
72
+ def base64(str)
73
+ Base64.strict_encode64(str)
74
+ end
75
+
76
+
77
+ ## Charset encodings ##
78
+
79
+ # Internal: Shorthand aliases for detecter functions.
80
+ CHARSET_DETECT = {}
81
+
82
+ # Internal: Mapping unicode encodings to byte order markers.
83
+ BOM = {
84
+ Encoding::UTF_32LE => [0xFF, 0xFE, 0x00, 0x00],
85
+ Encoding::UTF_32BE => [0x00, 0x00, 0xFE, 0xFF],
86
+ Encoding::UTF_8 => [0xEF, 0xBB, 0xBF],
87
+ Encoding::UTF_16LE => [0xFF, 0xFE],
88
+ Encoding::UTF_16BE => [0xFE, 0xFF]
89
+ }
90
+
91
+ # Public: Basic string detecter.
92
+ #
93
+ # Attempts to parse any Unicode BOM otherwise falls back to the
94
+ # environment's external encoding.
95
+ #
96
+ # str - ASCII-8BIT encoded String
97
+ #
98
+ # Returns encoded String.
99
+ def detect(str)
100
+ str = detect_unicode_bom(str)
101
+
102
+ # Attempt Charlock detection
103
+ if str.encoding == Encoding::BINARY
104
+ charlock_detect(str)
105
+ end
106
+
107
+ # Fallback to environment's external encoding
108
+ if str.encoding == Encoding::BINARY
109
+ str.force_encoding(Encoding.default_external)
110
+ end
111
+
112
+ str
113
+ end
114
+ CHARSET_DETECT[:default] = method(:detect)
115
+
116
+ # Internal: Use Charlock Holmes to detect encoding.
117
+ #
118
+ # To enable this code path, require 'charlock_holmes'
119
+ #
120
+ # Returns encoded String.
121
+ def charlock_detect(str)
122
+ if defined? CharlockHolmes::EncodingDetector
123
+ if detected = CharlockHolmes::EncodingDetector.detect(str)
124
+ str.force_encoding(detected[:encoding]) if detected[:encoding]
125
+ end
126
+ end
127
+
128
+ str
129
+ end
130
+
131
+ # Public: Detect Unicode string.
132
+ #
133
+ # Attempts to parse Unicode BOM and falls back to UTF-8.
134
+ #
135
+ # str - ASCII-8BIT encoded String
136
+ #
137
+ # Returns encoded String.
138
+ def detect_unicode(str)
139
+ str = detect_unicode_bom(str)
140
+
141
+ # Fallback to UTF-8
142
+ if str.encoding == Encoding::BINARY
143
+ str.force_encoding(Encoding::UTF_8)
144
+ end
145
+
146
+ str
147
+ end
148
+ CHARSET_DETECT[:unicode] = method(:detect_unicode)
149
+
150
+ # Public: Detect and strip BOM from possible unicode string.
151
+ #
152
+ # str - ASCII-8BIT encoded String
153
+ #
154
+ # Returns UTF 8/16/32 encoded String without BOM or the original String if
155
+ # no BOM was present.
156
+ def detect_unicode_bom(str)
157
+ bom_bytes = str.byteslice(0, 4).bytes.to_a
158
+
159
+ BOM.each do |encoding, bytes|
160
+ if bom_bytes[0, bytes.size] == bytes
161
+ str = str.dup
162
+ str.force_encoding(Encoding::BINARY)
163
+ str.slice!(0, bytes.size)
164
+ str.force_encoding(encoding)
165
+ return str
166
+ end
167
+ end
168
+
169
+ return str
170
+ end
171
+
172
+ # Public: Detect and strip @charset from CSS style sheet.
173
+ #
174
+ # str - String.
175
+ #
176
+ # Returns a encoded String.
177
+ def detect_css(str)
178
+ str = detect_unicode_bom(str)
179
+
180
+ if name = scan_css_charset(str)
181
+ encoding = Encoding.find(name)
182
+ str = str.dup
183
+ str.force_encoding(encoding)
184
+ len = "@charset \"#{name}\";".encode(encoding).size
185
+ str.slice!(0, len)
186
+ str
187
+ end
188
+
189
+ # Fallback to UTF-8
190
+ if str.encoding == Encoding::BINARY
191
+ str.force_encoding(Encoding::UTF_8)
192
+ end
193
+
194
+ str
195
+ end
196
+ CHARSET_DETECT[:css] = method(:detect_css)
197
+
198
+ # Internal: @charset bytes
199
+ CHARSET_START = [0x40, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x20, 0x22]
200
+ CHARSET_SIZE = CHARSET_START.size
201
+
202
+ # Internal: Scan binary CSS string for @charset encoding name.
203
+ #
204
+ # str - ASCII-8BIT encoded String
205
+ #
206
+ # Returns encoding String name or nil.
207
+ def scan_css_charset(str)
208
+ buf = []
209
+ i = 0
210
+
211
+ str.each_byte.each do |byte|
212
+ # Halt on line breaks
213
+ break if byte == 0x0A || byte == 0x0D
214
+
215
+ # Only ascii bytes
216
+ next unless 0x0 < byte && byte <= 0xFF
217
+
218
+ if i < CHARSET_SIZE
219
+ elsif i == CHARSET_SIZE
220
+ if buf == CHARSET_START
221
+ buf = []
222
+ else
223
+ break
224
+ end
225
+ elsif byte == 0x22
226
+ return buf.pack('C*')
227
+ end
228
+
229
+ buf << byte
230
+ i += 1
231
+ end
232
+
233
+ nil
234
+ end
235
+
236
+ # Public: Detect charset from HTML document.
237
+ #
238
+ # Attempts to parse any Unicode BOM otherwise attempt Charlock detection
239
+ # and finally falls back to the environment's external encoding.
240
+ #
241
+ # str - String.
242
+ #
243
+ # Returns a encoded String.
244
+ def detect_html(str)
245
+ str = detect_unicode_bom(str)
246
+
247
+ # Attempt Charlock detection
248
+ if str.encoding == Encoding::BINARY
249
+ charlock_detect(str)
250
+ end
251
+
252
+ # Fallback to environment's external encoding
253
+ if str.encoding == Encoding::BINARY
254
+ str.force_encoding(Encoding.default_external)
255
+ end
256
+
257
+ str
258
+ end
259
+ CHARSET_DETECT[:html] = method(:detect_html)
260
+ end
261
+ end
@@ -1,22 +1,19 @@
1
- require 'sprockets/eco_template'
2
- require 'sprockets/ejs_template'
3
- require 'sprockets/jst_processor'
1
+ require 'sprockets/legacy_tilt_processor'
4
2
  require 'sprockets/utils'
5
- require 'tilt'
6
3
 
7
4
  module Sprockets
8
5
  # `Engines` provides a global and `Environment` instance registry.
9
6
  #
10
- # An engine is a type of processor that is bound to an filename
7
+ # An engine is a type of processor that is bound to a filename
11
8
  # extension. `application.js.coffee` indicates that the
12
- # `CoffeeScriptTemplate` engine will be ran on the file.
9
+ # `CoffeeScriptProcessor` engine will be ran on the file.
13
10
  #
14
11
  # Extensions can be stacked and will be evaulated from right to
15
- # left. `application.js.coffee.erb` will first run `ERBTemplate`
16
- # then `CoffeeScriptTemplate`.
12
+ # left. `application.js.coffee.erb` will first run `ERBProcessor`
13
+ # then `CoffeeScriptProcessor`.
17
14
  #
18
- # All `Engine`s must follow the `Tilt::Template` interface. It is
19
- # recommended to subclass `Tilt::Template`.
15
+ # All `Engine`s must follow the `Template` interface. It is
16
+ # recommended to subclass `Template`.
20
17
  #
21
18
  # Its recommended that you register engine changes on your local
22
19
  # `Environment` instance.
@@ -25,50 +22,71 @@ module Sprockets
25
22
  #
26
23
  # The global registry is exposed for plugins to register themselves.
27
24
  #
28
- # Sprockets.register_engine '.sass', SassTemplate
25
+ # Sprockets.register_engine '.sass', SassProcessor
29
26
  #
30
27
  module Engines
28
+ include Utils
29
+
31
30
  # Returns a `Hash` of `Engine`s registered on the `Environment`.
32
31
  # If an `ext` argument is supplied, the `Engine` associated with
33
32
  # that extension will be returned.
34
33
  #
35
34
  # environment.engines
36
- # # => {".coffee" => CoffeeScriptTemplate, ".sass" => SassTemplate, ...}
37
- #
38
- # environment.engines('.coffee')
39
- # # => CoffeeScriptTemplate
35
+ # # => {".coffee" => CoffeeScriptProcessor, ".sass" => SassProcessor, ...}
40
36
  #
41
- def engines(ext = nil)
42
- if ext
43
- ext = Sprockets::Utils.normalize_extension(ext)
44
- @engines[ext]
45
- else
46
- @engines.dup
47
- end
37
+ def engines
38
+ config[:engines]
48
39
  end
49
40
 
50
- # Returns an `Array` of engine extension `String`s.
41
+ # Internal: Returns a `Hash` of engine extensions to mime types.
51
42
  #
52
- # environment.engine_extensions
53
- # # => ['.coffee', '.sass', ...]
54
- def engine_extensions
55
- @engines.keys
43
+ # # => { '.coffee' => 'application/javascript' }
44
+ def engine_mime_types
45
+ config[:engine_mime_types]
56
46
  end
57
47
 
58
48
  # Registers a new Engine `klass` for `ext`. If the `ext` already
59
49
  # has an engine registered, it will be overridden.
60
50
  #
61
- # environment.register_engine '.coffee', CoffeeScriptTemplate
51
+ # environment.register_engine '.coffee', CoffeeScriptProcessor
62
52
  #
63
- def register_engine(ext, klass)
53
+ def register_engine(ext, klass, options = {})
54
+ unless options[:silence_deprecation]
55
+ msg = <<-MSG
56
+ Sprockets method `register_engine` is deprecated.
57
+ Please register a mime type using `register_mime_type` then
58
+ use `register_compressor` or `register_transformer`.
59
+ https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
60
+ MSG
61
+
62
+ Deprecation.new([caller.first]).warn(msg)
63
+ end
64
+
64
65
  ext = Sprockets::Utils.normalize_extension(ext)
65
- @engines[ext] = klass
66
- end
67
66
 
68
- private
69
- def deep_copy_hash(hash)
70
- initial = Hash.new { |h, k| h[k] = [] }
71
- hash.inject(initial) { |h, (k, a)| h[k] = a.dup; h }
67
+ self.computed_config = {}
68
+
69
+ if klass.respond_to?(:call)
70
+ processor = klass
71
+ self.config = hash_reassoc(config, :engines) do |engines|
72
+ engines.merge(ext => klass)
73
+ end
74
+ if options[:mime_type]
75
+ self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
76
+ mime_types.merge(ext.to_s => options[:mime_type])
77
+ end
78
+ end
79
+ else
80
+ processor = LegacyTiltProcessor.new(klass)
81
+ self.config = hash_reassoc(config, :engines) do |engines|
82
+ engines.merge(ext => processor)
83
+ end
84
+ if klass.respond_to?(:default_mime_type) && klass.default_mime_type
85
+ self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
86
+ mime_types.merge(ext.to_s => klass.default_mime_type)
87
+ end
88
+ end
72
89
  end
90
+ end
73
91
  end
74
92
  end
@@ -1,11 +1,6 @@
1
1
  require 'sprockets/base'
2
- require 'sprockets/context'
3
- require 'sprockets/index'
4
-
5
- require 'hike'
6
- require 'logger'
7
- require 'pathname'
8
- require 'tilt'
2
+ require 'sprockets/cache/memory_store'
3
+ require 'sprockets/cached_environment'
9
4
 
10
5
  module Sprockets
11
6
  class Environment < Base
@@ -15,74 +10,32 @@ module Sprockets
15
10
  # env = Environment.new(Rails.root)
16
11
  #
17
12
  def initialize(root = ".")
18
- @trail = Hike::Trail.new(root)
19
-
20
- self.logger = Logger.new($stderr)
21
- self.logger.level = Logger::FATAL
22
-
23
- if respond_to?(:default_external_encoding)
24
- self.default_external_encoding = Encoding::UTF_8
25
- end
26
-
27
- # Create a safe `Context` subclass to mutate
28
- @context_class = Class.new(Context)
29
-
30
- # Set MD5 as the default digest
31
- require 'digest/md5'
32
- @digest_class = ::Digest::MD5
33
- @version = ''
34
-
35
- @mime_types = Sprockets.registered_mime_types
36
- @engines = Sprockets.engines
37
- @preprocessors = Sprockets.preprocessors
38
- @postprocessors = Sprockets.postprocessors
39
- @bundle_processors = Sprockets.bundle_processors
40
- @compressors = Sprockets.compressors
41
-
42
- Sprockets.paths.each do |path|
43
- append_path(path)
44
- end
45
-
46
- @engines.each do |ext, klass|
47
- add_engine_to_trail(ext, klass)
48
- end
49
-
50
- @mime_types.each do |ext, type|
51
- @trail.append_extension(ext)
52
- end
53
-
54
- expire_index!
55
-
13
+ initialize_configuration(Sprockets)
14
+ self.root = root
15
+ self.cache = Cache::MemoryStore.new
56
16
  yield self if block_given?
57
17
  end
58
18
 
59
19
  # Returns a cached version of the environment.
60
20
  #
61
- # All its file system calls are cached which makes `index` much
21
+ # All its file system calls are cached which makes `cached` much
62
22
  # faster. This behavior is ideal in production since the file
63
23
  # system only changes between deploys.
64
- def index
65
- Index.new(self)
24
+ def cached
25
+ CachedEnvironment.new(self)
66
26
  end
27
+ alias_method :index, :cached
67
28
 
68
- # Cache `find_asset` calls
69
- def find_asset(path, options = {})
70
- options[:bundle] = true unless options.key?(:bundle)
29
+ def find_asset(*args)
30
+ cached.find_asset(*args)
31
+ end
71
32
 
72
- # Ensure inmemory cached assets are still fresh on every lookup
73
- if (asset = @assets[cache_key_for(path, options)]) && asset.fresh?(self)
74
- asset
75
- elsif asset = index.find_asset(path, options)
76
- # Cache is pushed upstream by Index#find_asset
77
- asset
78
- end
33
+ def find_all_linked_assets(*args, &block)
34
+ cached.find_all_linked_assets(*args, &block)
79
35
  end
80
36
 
81
- protected
82
- def expire_index!
83
- # Clear digest to be recomputed
84
- @digest = nil
85
- @assets = {}
86
- end
37
+ def load(*args)
38
+ cached.load(*args)
39
+ end
87
40
  end
88
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
@@ -0,0 +1,11 @@
1
+ require 'sprockets/erb_processor'
2
+
3
+ module Sprockets
4
+ # Deprecated
5
+ class ERBTemplate < ERBProcessor
6
+ def call(*args)
7
+ Deprecation.new.warn "ERBTemplate is deprecated please use ERBProcessor instead"
8
+ super
9
+ end
10
+ end
11
+ end
@@ -2,19 +2,10 @@
2
2
  module Sprockets
3
3
  class Error < StandardError; end
4
4
  class ArgumentError < Error; end
5
- class CircularDependencyError < Error; end
6
5
  class ContentTypeMismatch < Error; end
7
- class EncodingError < Error; end
8
- class FileNotFound < Error; end
9
- class FileOutsidePaths < Error; end
10
6
  class NotImplementedError < Error; end
11
- class UnserializeError < Error; end
12
-
13
- module EngineError
14
- attr_accessor :sprockets_annotation
15
-
16
- def message
17
- [super, sprockets_annotation].compact.join("\n")
18
- end
19
- end
7
+ class NotFound < Error; end
8
+ class ConversionError < NotFound; end
9
+ class FileNotFound < NotFound; end
10
+ class FileOutsidePaths < NotFound; end
20
11
  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