Module: Sprockets::Exporting

Included in:
Configuration
Defined in:
lib/sprockets/exporting.rb

Overview

‘Exporting` is an internal mixin whose public methods are exposed on the `Environment` and `CachedEnvironment` classes.

Instance Method Summary collapse

Instance Method Details

#export_concurrentObject

Public: Checks if concurrent exporting is allowed



59
60
61
# File 'lib/sprockets/exporting.rb', line 59

def export_concurrent
  config[:export_concurrent]
end

#export_concurrent=(export_concurrent) ⇒ Object

Public: Enable or disable the concurrently exporting files

Defaults to true.

environment.export_concurrent = false


69
70
71
# File 'lib/sprockets/exporting.rb', line 69

def export_concurrent=(export_concurrent)
  self.config = config.merge(export_concurrent: export_concurrent).freeze
end

#exportersObject

Exporters are ran on the assets:precompile task



6
7
8
# File 'lib/sprockets/exporting.rb', line 6

def exporters
  config[:exporters]
end

#register_exporter(mime_types, klass = nil) ⇒ Object

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`



19
20
21
22
23
24
25
26
27
# File 'lib/sprockets/exporting.rb', line 19

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

#unregister_exporter(mime_types, exporter = nil) ⇒ Object

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`.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sprockets/exporting.rb', line 38

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