-
Notifications
You must be signed in to change notification settings - Fork 788
/
exporting.rb
73 lines (67 loc) · 2.28 KB
/
exporting.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Sprockets
# `Exporting` is an internal mixin whose public methods are exposed on
# the `Environment` and `CachedEnvironment` classes.
module Exporting
# Exporters are ran on the assets:precompile task
def exporters
config[:exporters]
end
# Public: Registers a new Exporter `klass` for `mime_type`.
#
# If your exporter depends on one or more other exporters you can
# specify this via the `depend_on` keyword.
#
# register_exporter '*/*', Sprockets::Exporters::ZlibExporter
#
# This ensures that `Sprockets::Exporters::File` will always execute before
# `Sprockets::Exporters::Zlib`
def register_exporter(mime_types, klass = nil)
mime_types = Array(mime_types)
mime_types.each do |mime_type|
self.config = hash_reassoc(config, :exporters, mime_type) do |_exporters|
_exporters << klass
end
end
end
# Public: Remove Exporting processor `klass` for `mime_type`.
#
# environment.unregister_exporter '*/*', Sprockets::Exporters::ZlibExporter
#
# Can be called without a mime type
#
# environment.unregister_exporter Sprockets::Exporters::ZlibExporter
#
# Does not remove any exporters that depend on `klass`.
def unregister_exporter(mime_types, exporter = nil)
unless mime_types.is_a? Array
if mime_types.is_a? String
mime_types = [mime_types]
else # called with no mime type
exporter = mime_types
mime_types = nil
end
end
self.config = hash_reassoc(config, :exporters) do |_exporters|
_exporters.each do |mime_type, exporters_array|
next if mime_types && !mime_types.include?(mime_type)
if exporters_array.include? exporter
_exporters[mime_type] = exporters_array.dup.delete exporter
end
end
end
end
# Public: Checks if concurrent exporting is allowed
def export_concurrent
config[:export_concurrent]
end
# Public: Enable or disable the concurrently exporting files
#
# Defaults to true.
#
# environment.export_concurrent = false
#
def export_concurrent=(export_concurrent)
self.config = config.merge(export_concurrent: export_concurrent).freeze
end
end
end