sprockets 2.2.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +68 -0
  3. data/README.md +482 -255
  4. data/bin/sprockets +20 -7
  5. data/lib/rake/sprocketstask.rb +28 -15
  6. data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
  7. data/lib/sprockets/asset.rb +142 -207
  8. data/lib/sprockets/autoload/babel.rb +8 -0
  9. data/lib/sprockets/autoload/closure.rb +8 -0
  10. data/lib/sprockets/autoload/coffee_script.rb +8 -0
  11. data/lib/sprockets/autoload/eco.rb +8 -0
  12. data/lib/sprockets/autoload/ejs.rb +8 -0
  13. data/lib/sprockets/autoload/jsminc.rb +8 -0
  14. data/lib/sprockets/autoload/sass.rb +8 -0
  15. data/lib/sprockets/autoload/sassc.rb +8 -0
  16. data/lib/sprockets/autoload/uglifier.rb +8 -0
  17. data/lib/sprockets/autoload/yui.rb +8 -0
  18. data/lib/sprockets/autoload/zopfli.rb +7 -0
  19. data/lib/sprockets/autoload.rb +16 -0
  20. data/lib/sprockets/babel_processor.rb +66 -0
  21. data/lib/sprockets/base.rb +89 -249
  22. data/lib/sprockets/bower.rb +61 -0
  23. data/lib/sprockets/bundle.rb +105 -0
  24. data/lib/sprockets/cache/file_store.rb +190 -14
  25. data/lib/sprockets/cache/memory_store.rb +75 -0
  26. data/lib/sprockets/cache/null_store.rb +54 -0
  27. data/lib/sprockets/cache.rb +271 -0
  28. data/lib/sprockets/cached_environment.rb +64 -0
  29. data/lib/sprockets/closure_compressor.rb +48 -0
  30. data/lib/sprockets/coffee_script_processor.rb +39 -0
  31. data/lib/sprockets/compressing.rb +134 -0
  32. data/lib/sprockets/configuration.rb +79 -0
  33. data/lib/sprockets/context.rb +204 -135
  34. data/lib/sprockets/dependencies.rb +74 -0
  35. data/lib/sprockets/digest_utils.rb +200 -0
  36. data/lib/sprockets/directive_processor.rb +224 -216
  37. data/lib/sprockets/eco_processor.rb +33 -0
  38. data/lib/sprockets/ejs_processor.rb +32 -0
  39. data/lib/sprockets/encoding_utils.rb +262 -0
  40. data/lib/sprockets/environment.rb +23 -68
  41. data/lib/sprockets/erb_processor.rb +37 -0
  42. data/lib/sprockets/errors.rb +6 -13
  43. data/lib/sprockets/exporters/base.rb +72 -0
  44. data/lib/sprockets/exporters/file_exporter.rb +24 -0
  45. data/lib/sprockets/exporters/zlib_exporter.rb +33 -0
  46. data/lib/sprockets/exporters/zopfli_exporter.rb +14 -0
  47. data/lib/sprockets/exporting.rb +73 -0
  48. data/lib/sprockets/file_reader.rb +16 -0
  49. data/lib/sprockets/http_utils.rb +135 -0
  50. data/lib/sprockets/jsminc_compressor.rb +32 -0
  51. data/lib/sprockets/jst_processor.rb +36 -19
  52. data/lib/sprockets/loader.rb +343 -0
  53. data/lib/sprockets/manifest.rb +231 -96
  54. data/lib/sprockets/manifest_utils.rb +48 -0
  55. data/lib/sprockets/mime.rb +80 -32
  56. data/lib/sprockets/npm.rb +52 -0
  57. data/lib/sprockets/path_dependency_utils.rb +77 -0
  58. data/lib/sprockets/path_digest_utils.rb +48 -0
  59. data/lib/sprockets/path_utils.rb +367 -0
  60. data/lib/sprockets/paths.rb +82 -0
  61. data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
  62. data/lib/sprockets/processing.rb +140 -192
  63. data/lib/sprockets/processor_utils.rb +169 -0
  64. data/lib/sprockets/resolve.rb +295 -0
  65. data/lib/sprockets/sass_cache_store.rb +30 -0
  66. data/lib/sprockets/sass_compressor.rb +63 -0
  67. data/lib/sprockets/sass_functions.rb +3 -0
  68. data/lib/sprockets/sass_importer.rb +3 -0
  69. data/lib/sprockets/sass_processor.rb +313 -0
  70. data/lib/sprockets/sassc_compressor.rb +56 -0
  71. data/lib/sprockets/sassc_processor.rb +297 -0
  72. data/lib/sprockets/server.rb +138 -90
  73. data/lib/sprockets/source_map_processor.rb +66 -0
  74. data/lib/sprockets/source_map_utils.rb +483 -0
  75. data/lib/sprockets/transformers.rb +173 -0
  76. data/lib/sprockets/uglifier_compressor.rb +66 -0
  77. data/lib/sprockets/unloaded_asset.rb +139 -0
  78. data/lib/sprockets/uri_tar.rb +99 -0
  79. data/lib/sprockets/uri_utils.rb +191 -0
  80. data/lib/sprockets/utils/gzip.rb +99 -0
  81. data/lib/sprockets/utils.rb +186 -53
  82. data/lib/sprockets/version.rb +2 -1
  83. data/lib/sprockets/yui_compressor.rb +56 -0
  84. data/lib/sprockets.rb +217 -52
  85. metadata +250 -59
  86. data/LICENSE +0 -21
  87. data/lib/sprockets/asset_attributes.rb +0 -126
  88. data/lib/sprockets/bundled_asset.rb +0 -79
  89. data/lib/sprockets/caching.rb +0 -96
  90. data/lib/sprockets/charset_normalizer.rb +0 -41
  91. data/lib/sprockets/eco_template.rb +0 -38
  92. data/lib/sprockets/ejs_template.rb +0 -37
  93. data/lib/sprockets/engines.rb +0 -74
  94. data/lib/sprockets/index.rb +0 -99
  95. data/lib/sprockets/processed_asset.rb +0 -152
  96. data/lib/sprockets/processor.rb +0 -32
  97. data/lib/sprockets/safety_colons.rb +0 -28
  98. data/lib/sprockets/static_asset.rb +0 -57
  99. data/lib/sprockets/trail.rb +0 -90
@@ -1,69 +1,202 @@
1
+ # frozen_string_literal: true
2
+ require 'set'
3
+
1
4
  module Sprockets
2
- # `Utils`, we didn't know where else to put it!
5
+ # Internal: Utils, we didn't know where else to put it! Functions may
6
+ # eventually be shuffled into more specific drawers.
3
7
  module Utils
4
- # If theres encoding support (aka Ruby 1.9)
5
- if "".respond_to?(:valid_encoding?)
6
- # Define UTF-8 BOM pattern matcher.
7
- # Avoid using a Regexp literal because it inheirts the files
8
- # encoding and we want to avoid syntax errors in other interpreters.
9
- UTF8_BOM_PATTERN = Regexp.new("\\A\uFEFF".encode('utf-8'))
10
-
11
- def self.read_unicode(pathname, external_encoding = Encoding.default_external)
12
- pathname.open("r:#{external_encoding}") do |f|
13
- f.read.tap do |data|
14
- # Eager validate the file's encoding. In most cases we
15
- # expect it to be UTF-8 unless `default_external` is set to
16
- # something else. An error is usually raised if the file is
17
- # saved as UTF-16 when we expected UTF-8.
18
- if !data.valid_encoding?
19
- raise EncodingError, "#{pathname} has a invalid " +
20
- "#{data.encoding} byte sequence"
21
-
22
- # If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
23
- elsif data.encoding.name == "UTF-8" && data =~ UTF8_BOM_PATTERN
24
- data.sub!(UTF8_BOM_PATTERN, "")
25
- end
26
- end
27
- end
8
+ extend self
9
+
10
+ # Internal: Check if object can safely be .dup'd.
11
+ #
12
+ # Similar to ActiveSupport #duplicable? check.
13
+ #
14
+ # obj - Any Object
15
+ #
16
+ # Returns false if .dup would raise a TypeError, otherwise true.
17
+ def duplicable?(obj)
18
+ case obj
19
+ when NilClass, FalseClass, TrueClass, Symbol, Numeric
20
+ false
21
+ else
22
+ true
28
23
  end
24
+ end
29
25
 
30
- else
31
- # Define UTF-8 and UTF-16 BOM pattern matchers.
32
- # Avoid using a Regexp literal to prevent syntax errors in other interpreters.
33
- UTF8_BOM_PATTERN = Regexp.new("\\A\\xEF\\xBB\\xBF")
34
- UTF16_BOM_PATTERN = Regexp.new("\\A(\\xFE\\xFF|\\xFF\\xFE)")
35
-
36
- def self.read_unicode(pathname)
37
- pathname.read.tap do |data|
38
- # If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
39
- if data =~ UTF8_BOM_PATTERN
40
- data.sub!(UTF8_BOM_PATTERN, "")
41
-
42
- # If we find a UTF-16 BOM, theres nothing we can do on
43
- # 1.8. Only UTF-8 is supported.
44
- elsif data =~ UTF16_BOM_PATTERN
45
- raise EncodingError, "#{pathname} has a UTF-16 BOM. " +
46
- "Resave the file as UTF-8 or upgrade to Ruby 1.9."
47
- end
26
+ # Internal: Duplicate and store key/value on new frozen hash.
27
+ #
28
+ # Seperated for recursive calls, always use hash_reassoc(hash, *keys).
29
+ #
30
+ # hash - Hash
31
+ # key - Object key
32
+ #
33
+ # Returns Hash.
34
+ def hash_reassoc1(hash, key)
35
+ hash = hash.dup if hash.frozen?
36
+ old_value = hash[key]
37
+ old_value = old_value.dup if duplicable?(old_value)
38
+ new_value = yield old_value
39
+ new_value.freeze if duplicable?(new_value)
40
+ hash.store(key, new_value)
41
+ hash.freeze
42
+ end
43
+
44
+ # Internal: Duplicate and store key/value on new frozen hash.
45
+ #
46
+ # Similar to Hash#store for nested frozen hashes.
47
+ #
48
+ # hash - Hash
49
+ # key_a - Object key. Use multiple keys for nested hashes.
50
+ # key_b - Object key. Use multiple keys for nested hashes.
51
+ # block - Receives current value at key.
52
+ #
53
+ # Examples
54
+ #
55
+ # config = {paths: ["/bin", "/sbin"]}.freeze
56
+ # new_config = hash_reassoc(config, :paths) do |paths|
57
+ # paths << "/usr/local/bin"
58
+ # end
59
+ #
60
+ # Returns duplicated frozen Hash.
61
+ def hash_reassoc(hash, key_a, key_b = nil, &block)
62
+ if key_b
63
+ hash_reassoc1(hash, key_a) do |value|
64
+ hash_reassoc(value, key_b, &block)
48
65
  end
66
+ else
67
+ hash_reassoc1(hash, key_a, &block)
49
68
  end
50
69
  end
51
70
 
52
- # Prepends a leading "." to an extension if its missing.
71
+ WHITESPACE_ORDINALS = {0x0A => "\n", 0x20 => " ", 0x09 => "\t"}
72
+ private_constant :WHITESPACE_ORDINALS
73
+
74
+ # Internal: Check if string has a trailing semicolon.
53
75
  #
54
- # normalize_extension("js")
55
- # # => ".js"
76
+ # str - String
56
77
  #
57
- # normalize_extension(".css")
58
- # # => ".css"
78
+ # Returns true or false.
79
+ def string_end_with_semicolon?(str)
80
+ i = str.size - 1
81
+ while i >= 0
82
+ c = str[i].ord
83
+ i -= 1
84
+
85
+ next if WHITESPACE_ORDINALS[c]
86
+
87
+ return c === 0x3B
88
+ end
89
+
90
+ true
91
+ end
92
+
93
+ # Internal: Accumulate asset source to buffer and append a trailing
94
+ # semicolon if necessary.
95
+ #
96
+ # buf - String buffer to append to
97
+ # source - String source to append
59
98
  #
60
- def self.normalize_extension(extension)
61
- extension = extension.to_s
62
- if extension[/^\./]
63
- extension
99
+ # Returns buf String.
100
+ def concat_javascript_sources(buf, source)
101
+ return buf if source.bytesize <= 0
102
+
103
+ buf << source
104
+ # If the source contains non-ASCII characters, indexing on it becomes O(N).
105
+ # This will lead to O(N^2) performance in string_end_with_semicolon?, so we should use 32 bit encoding to make sure indexing stays O(1)
106
+ source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
107
+ return buf if string_end_with_semicolon?(source)
108
+
109
+ # If the last character in the string was whitespace,
110
+ # such as a newline, then we want to put the semicolon
111
+ # before the whitespace. Otherwise append a semicolon.
112
+ if whitespace = WHITESPACE_ORDINALS[source[-1].ord]
113
+ buf[-1] = ";#{whitespace}"
64
114
  else
65
- ".#{extension}"
115
+ buf << ";"
116
+ end
117
+
118
+ buf
119
+ end
120
+
121
+ # Internal: Inject into target module for the duration of the block.
122
+ #
123
+ # mod - Module
124
+ #
125
+ # Returns result of block.
126
+ def module_include(base, mod)
127
+ old_methods = {}
128
+
129
+ mod.instance_methods.each do |sym|
130
+ old_methods[sym] = base.instance_method(sym) if base.method_defined?(sym)
131
+ end
132
+
133
+ mod.instance_methods.each do |sym|
134
+ method = mod.instance_method(sym)
135
+ base.send(:define_method, sym, method)
136
+ end
137
+
138
+ yield
139
+ ensure
140
+ mod.instance_methods.each do |sym|
141
+ base.send(:undef_method, sym) if base.method_defined?(sym)
142
+ end
143
+ old_methods.each do |sym, method|
144
+ base.send(:define_method, sym, method)
145
+ end
146
+ end
147
+
148
+ # Internal: Post-order Depth-First search algorithm.
149
+ #
150
+ # Used for resolving asset dependencies.
151
+ #
152
+ # initial - Initial Array of nodes to traverse.
153
+ # block -
154
+ # node - Current node to get children of
155
+ #
156
+ # Returns a Set of nodes.
157
+ def dfs(initial)
158
+ nodes, seen = Set.new, Set.new
159
+ stack = Array(initial).reverse
160
+
161
+ while node = stack.pop
162
+ if seen.include?(node)
163
+ nodes.add(node)
164
+ else
165
+ seen.add(node)
166
+ stack.push(node)
167
+ stack.concat(Array(yield node).reverse)
168
+ end
66
169
  end
170
+
171
+ nodes
172
+ end
173
+
174
+ # Internal: Post-order Depth-First search algorithm that gathers all paths
175
+ # along the way.
176
+ #
177
+ # TODO: Rename function.
178
+ #
179
+ # path - Initial Array node path
180
+ # block -
181
+ # node - Current node to get children of
182
+ #
183
+ # Returns an Array of node Arrays.
184
+ def dfs_paths(path)
185
+ paths = []
186
+ stack = [path]
187
+ seen = Set.new
188
+
189
+ while path = stack.pop
190
+ seen.add(path.last)
191
+ paths << path
192
+
193
+ children = yield path.last
194
+ children.reverse_each do |node|
195
+ stack.push(path + [node]) unless seen.include?(node)
196
+ end
197
+ end
198
+
199
+ paths
67
200
  end
68
201
  end
69
202
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
- VERSION = "2.2.3"
3
+ VERSION = "4.0.0"
3
4
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require 'sprockets/autoload'
3
+ require 'sprockets/digest_utils'
4
+
5
+ module Sprockets
6
+ # Public: YUI compressor.
7
+ #
8
+ # To accept the default options
9
+ #
10
+ # environment.register_bundle_processor 'application/javascript',
11
+ # Sprockets::YUICompressor
12
+ #
13
+ # Or to pass options to the YUI::JavaScriptCompressor class.
14
+ #
15
+ # environment.register_bundle_processor 'application/javascript',
16
+ # Sprockets::YUICompressor.new(munge: true)
17
+ #
18
+ class YUICompressor
19
+ VERSION = '1'
20
+
21
+ # Public: Return singleton instance with default options.
22
+ #
23
+ # Returns YUICompressor object.
24
+ def self.instance
25
+ @instance ||= new
26
+ end
27
+
28
+ def self.call(input)
29
+ instance.call(input)
30
+ end
31
+
32
+ def self.cache_key
33
+ instance.cache_key
34
+ end
35
+
36
+ attr_reader :cache_key
37
+
38
+ def initialize(options = {})
39
+ @options = options
40
+ @cache_key = "#{self.class.name}:#{Autoload::YUI::Compressor::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
41
+ end
42
+
43
+ def call(input)
44
+ data = input[:data]
45
+
46
+ case input[:content_type]
47
+ when 'application/javascript'
48
+ Autoload::YUI::JavaScriptCompressor.new(@options).compress(data)
49
+ when 'text/css'
50
+ Autoload::YUI::CssCompressor.new(@options).compress(data)
51
+ else
52
+ data
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/sprockets.rb CHANGED
@@ -1,64 +1,229 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'sprockets/version'
5
+ require 'sprockets/cache'
6
+ require 'sprockets/environment'
7
+ require 'sprockets/errors'
8
+ require 'sprockets/manifest'
2
9
 
3
10
  module Sprockets
4
- # Environment
5
- autoload :Base, "sprockets/base"
6
- autoload :Engines, "sprockets/engines"
7
- autoload :Environment, "sprockets/environment"
8
- autoload :Index, "sprockets/index"
9
- autoload :Manifest, "sprockets/manifest"
10
-
11
- # Assets
12
- autoload :Asset, "sprockets/asset"
13
- autoload :BundledAsset, "sprockets/bundled_asset"
14
- autoload :ProcessedAsset, "sprockets/processed_asset"
15
- autoload :StaticAsset, "sprockets/static_asset"
16
-
17
- # Processing
18
- autoload :CharsetNormalizer, "sprockets/charset_normalizer"
19
- autoload :Context, "sprockets/context"
20
- autoload :DirectiveProcessor, "sprockets/directive_processor"
21
- autoload :EcoTemplate, "sprockets/eco_template"
22
- autoload :EjsTemplate, "sprockets/ejs_template"
23
- autoload :JstProcessor, "sprockets/jst_processor"
24
- autoload :Processor, "sprockets/processor"
25
- autoload :SafetyColons, "sprockets/safety_colons"
26
-
27
- # Internal utilities
28
- autoload :ArgumentError, "sprockets/errors"
29
- autoload :AssetAttributes, "sprockets/asset_attributes"
30
- autoload :CircularDependencyError, "sprockets/errors"
31
- autoload :ContentTypeMismatch, "sprockets/errors"
32
- autoload :EngineError, "sprockets/errors"
33
- autoload :Error, "sprockets/errors"
34
- autoload :FileNotFound, "sprockets/errors"
35
- autoload :Utils, "sprockets/utils"
36
-
37
- module Cache
38
- autoload :FileStore, "sprockets/cache/file_store"
39
- end
11
+ require 'sprockets/processor_utils'
12
+ extend ProcessorUtils
40
13
 
41
14
  # Extend Sprockets module to provide global registry
42
- extend Engines
43
- @engines = {}
15
+ require 'sprockets/configuration'
16
+ require 'sprockets/context'
17
+ require 'digest/sha2'
18
+ extend Configuration
19
+
20
+ self.config = {
21
+ bundle_processors: Hash.new { |h, k| [].freeze }.freeze,
22
+ bundle_reducers: Hash.new { |h, k| {}.freeze }.freeze,
23
+ compressors: Hash.new { |h, k| {}.freeze }.freeze,
24
+ dependencies: Set.new.freeze,
25
+ dependency_resolvers: {}.freeze,
26
+ digest_class: Digest::SHA256,
27
+ mime_exts: {}.freeze,
28
+ mime_types: {}.freeze,
29
+ paths: [].freeze,
30
+ pipelines: {}.freeze,
31
+ pipeline_exts: {}.freeze,
32
+ postprocessors: Hash.new { |h, k| [].freeze }.freeze,
33
+ preprocessors: Hash.new { |h, k| [].freeze }.freeze,
34
+ registered_transformers: [].freeze,
35
+ root: __dir__.dup.freeze,
36
+ transformers: Hash.new { |h, k| {}.freeze }.freeze,
37
+ exporters: Hash.new { |h, k| Set.new.freeze }.freeze,
38
+ version: "",
39
+ gzip_enabled: true,
40
+ export_concurrent: true
41
+ }.freeze
42
+
43
+ @context_class = Context
44
+
45
+ require 'logger'
46
+ @logger = Logger.new($stderr)
47
+ @logger.level = Logger::FATAL
48
+
49
+ # Common asset text types
50
+ register_mime_type 'application/javascript', extensions: ['.js'], charset: :unicode
51
+ register_mime_type 'application/json', extensions: ['.json'], charset: :unicode
52
+ register_mime_type 'application/ruby', extensions: ['.rb']
53
+ register_mime_type 'application/xml', extensions: ['.xml']
54
+ register_mime_type 'text/css', extensions: ['.css'], charset: :css
55
+ register_mime_type 'text/html', extensions: ['.html', '.htm'], charset: :html
56
+ register_mime_type 'text/plain', extensions: ['.txt', '.text']
57
+ register_mime_type 'text/yaml', extensions: ['.yml', '.yaml'], charset: :unicode
58
+
59
+ # Common image types
60
+ register_mime_type 'image/x-icon', extensions: ['.ico']
61
+ register_mime_type 'image/bmp', extensions: ['.bmp']
62
+ register_mime_type 'image/gif', extensions: ['.gif']
63
+ register_mime_type 'image/webp', extensions: ['.webp']
64
+ register_mime_type 'image/png', extensions: ['.png']
65
+ register_mime_type 'image/jpeg', extensions: ['.jpg', '.jpeg']
66
+ register_mime_type 'image/tiff', extensions: ['.tiff', '.tif']
67
+ register_mime_type 'image/svg+xml', extensions: ['.svg']
68
+
69
+ # Common audio/video types
70
+ register_mime_type 'video/webm', extensions: ['.webm']
71
+ register_mime_type 'audio/basic', extensions: ['.snd', '.au']
72
+ register_mime_type 'audio/aiff', extensions: ['.aiff']
73
+ register_mime_type 'audio/mpeg', extensions: ['.mp3', '.mp2', '.m2a', '.m3a']
74
+ register_mime_type 'application/ogg', extensions: ['.ogx']
75
+ register_mime_type 'audio/ogg', extensions: ['.ogg', '.oga']
76
+ register_mime_type 'audio/midi', extensions: ['.midi', '.mid']
77
+ register_mime_type 'video/avi', extensions: ['.avi']
78
+ register_mime_type 'audio/wave', extensions: ['.wav', '.wave']
79
+ register_mime_type 'video/mp4', extensions: ['.mp4', '.m4v']
80
+ register_mime_type 'audio/aac', extensions: ['.aac']
81
+ register_mime_type 'audio/mp4', extensions: ['.m4a']
82
+ register_mime_type 'audio/flac', extensions: ['.flac']
83
+
84
+ # Common font types
85
+ register_mime_type 'application/vnd.ms-fontobject', extensions: ['.eot']
86
+ register_mime_type 'application/x-font-opentype', extensions: ['.otf']
87
+ register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
88
+ register_mime_type 'application/font-woff', extensions: ['.woff']
89
+ register_mime_type 'application/font-woff2', extensions: ['.woff2']
44
90
 
45
- # Cherry pick the default Tilt engines that make sense for
46
- # Sprockets. We don't need ones that only generate html like HAML.
91
+ require 'sprockets/source_map_processor'
92
+ register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map']
93
+ register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map']
94
+ register_transformer 'application/javascript', 'application/js-sourcemap+json', SourceMapProcessor
95
+ register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapProcessor
96
+
97
+ register_pipeline :source do |env|
98
+ []
99
+ end
100
+
101
+ register_pipeline :self do |env, type, file_type|
102
+ env.self_processors_for(type, file_type)
103
+ end
104
+
105
+ register_pipeline :default do |env, type, file_type|
106
+ env.default_processors_for(type, file_type)
107
+ end
108
+
109
+ require 'sprockets/add_source_map_comment_to_asset_processor'
110
+ register_pipeline :debug do
111
+ [AddSourceMapCommentToAssetProcessor]
112
+ end
113
+
114
+ require 'sprockets/directive_processor'
115
+ register_preprocessor 'text/css', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
116
+ register_preprocessor 'application/javascript', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
117
+
118
+ require 'sprockets/bundle'
119
+ register_bundle_processor 'application/javascript', Bundle
120
+ register_bundle_processor 'text/css', Bundle
121
+
122
+ register_bundle_metadata_reducer '*/*', :data, proc { +"" }, :concat
123
+ register_bundle_metadata_reducer 'application/javascript', :data, proc { +"" }, Utils.method(:concat_javascript_sources)
124
+ register_bundle_metadata_reducer '*/*', :links, :+
125
+ register_bundle_metadata_reducer '*/*', :sources, proc { [] }, :+
126
+
127
+ require 'sprockets/closure_compressor'
128
+ require 'sprockets/sass_compressor'
129
+ require 'sprockets/sassc_compressor'
130
+ require 'sprockets/jsminc_compressor'
131
+ require 'sprockets/uglifier_compressor'
132
+ require 'sprockets/yui_compressor'
133
+ register_compressor 'text/css', :sass, SassCompressor
134
+ register_compressor 'text/css', :sassc, SasscCompressor
135
+ register_compressor 'text/css', :scss, SassCompressor
136
+ register_compressor 'text/css', :scssc, SasscCompressor
137
+ register_compressor 'text/css', :yui, YUICompressor
138
+ register_compressor 'application/javascript', :closure, ClosureCompressor
139
+ register_compressor 'application/javascript', :jsmin, JSMincCompressor
140
+ register_compressor 'application/javascript', :jsminc, JSMincCompressor
141
+ register_compressor 'application/javascript', :uglifier, UglifierCompressor
142
+ register_compressor 'application/javascript', :uglify, UglifierCompressor
143
+ register_compressor 'application/javascript', :yui, YUICompressor
144
+
145
+ # Babel, TheFuture™ is now
146
+ require 'sprockets/babel_processor'
147
+ register_mime_type 'application/ecmascript-6', extensions: ['.es6'], charset: :unicode
148
+ register_transformer 'application/ecmascript-6', 'application/javascript', BabelProcessor
149
+ register_preprocessor 'application/ecmascript-6', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
47
150
 
48
151
  # Mmm, CoffeeScript
49
- register_engine '.coffee', Tilt::CoffeeScriptTemplate
152
+ require 'sprockets/coffee_script_processor'
153
+ register_mime_type 'text/coffeescript', extensions: ['.coffee', '.js.coffee']
154
+ register_transformer 'text/coffeescript', 'application/javascript', CoffeeScriptProcessor
155
+ register_preprocessor 'text/coffeescript', DirectiveProcessor.new(comments: ["#", ["###", "###"]])
156
+
157
+ # JST processors
158
+ require 'sprockets/eco_processor'
159
+ require 'sprockets/ejs_processor'
160
+ require 'sprockets/jst_processor'
161
+ register_mime_type 'text/eco', extensions: ['.eco', '.jst.eco']
162
+ register_mime_type 'text/ejs', extensions: ['.ejs', '.jst.ejs']
163
+ register_transformer 'text/eco', 'application/javascript+function', EcoProcessor
164
+ register_transformer 'text/ejs', 'application/javascript+function', EjsProcessor
165
+ register_transformer 'application/javascript+function', 'application/javascript', JstProcessor
166
+
167
+ # CSS processors
168
+ require 'sprockets/sassc_processor'
169
+ register_mime_type 'text/sass', extensions: ['.sass', '.css.sass']
170
+ register_mime_type 'text/scss', extensions: ['.scss', '.css.scss']
171
+ register_transformer 'text/sass', 'text/css', SasscProcessor
172
+ register_transformer 'text/scss', 'text/css', ScsscProcessor
173
+ register_preprocessor 'text/sass', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
174
+ register_preprocessor 'text/scss', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
175
+ register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
176
+
177
+ # ERB
178
+ require 'sprockets/erb_processor'
179
+ register_transformer_suffix(%w(
180
+ application/ecmascript-6
181
+ application/javascript
182
+ application/json
183
+ application/xml
184
+ text/coffeescript
185
+ text/css
186
+ text/html
187
+ text/plain
188
+ text/sass
189
+ text/scss
190
+ text/yaml
191
+ text/eco
192
+ ), 'application/\2+ruby', '.erb', ERBProcessor)
193
+
194
+ register_mime_type 'application/html+ruby', extensions: ['.html.erb', '.erb', '.rhtml'], charset: :html
195
+ register_mime_type 'application/xml+ruby', extensions: ['.xml.erb', '.rxml']
196
+
197
+ require 'sprockets/exporters/file_exporter'
198
+ require 'sprockets/exporters/zlib_exporter'
199
+ require 'sprockets/exporters/zopfli_exporter'
200
+ register_exporter '*/*', Exporters::FileExporter
201
+ register_exporter '*/*', Exporters::ZlibExporter
202
+
203
+ register_dependency_resolver 'environment-version' do |env|
204
+ env.version
205
+ end
206
+ register_dependency_resolver 'environment-paths' do |env|
207
+ env.paths.map {|path| env.compress_from_root(path) }
208
+ end
209
+ register_dependency_resolver 'file-digest' do |env, str|
210
+ env.file_digest(env.parse_file_digest_uri(str))
211
+ end
212
+ register_dependency_resolver 'processors' do |env, str|
213
+ env.resolve_processors_cache_key_uri(str)
214
+ end
215
+ register_dependency_resolver 'env' do |env, str|
216
+ _, var = str.split(':', 2)
217
+ ENV[var]
218
+ end
50
219
 
51
- # JST engines
52
- register_engine '.jst', JstProcessor
53
- register_engine '.eco', EcoTemplate
54
- register_engine '.ejs', EjsTemplate
220
+ depend_on 'environment-version'
221
+ depend_on 'environment-paths'
55
222
 
56
- # CSS engines
57
- register_engine '.less', Tilt::LessTemplate
58
- register_engine '.sass', Tilt::SassTemplate
59
- register_engine '.scss', Tilt::ScssTemplate
223
+ require 'sprockets/preprocessors/default_source_map'
224
+ register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new
225
+ register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new
60
226
 
61
- # Other
62
- register_engine '.erb', Tilt::ERBTemplate
63
- register_engine '.str', Tilt::StringTemplate
227
+ register_bundle_metadata_reducer 'text/css', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
228
+ register_bundle_metadata_reducer 'application/javascript', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
64
229
  end