class Sprockets::Exporters::Base
writes a gzip copy of the asset to disk.
writes the asset to it’s destination. The Exporters::Zlib class
to a file system. For example the Exporters::File class
An exporter is responsible for exporting a Sprockets::Asset
Convienence class for all exporters to inherit from
def call
`call` method. This method takes no arguments and should only use
If the exporter is not skipped it then Sprockets will execute it's
Public: Contains logic for writing "exporting" asset to disk
def call raise "Must subclass and implement call" end
def initialize(asset: nil, environment: nil, directory: nil)
+target+ will be available which is the target directory and
These will all be stored as accessible values. In addition a
- directory: String representing the target directory to write to.
- environment: An instance of Sprockets::Environment.
- asset: An instance of Sprockets::Asset.
keyword arguments:
Initialize will be called with
Public: Creates new instance
def initialize(asset: nil, environment: nil, directory: nil) @asset = asset @environment = environment @directory = directory @target = ::File.join(directory, asset.digest_path) setup end
def setup
Any setup that needs to be done can be performed in the +setup+
Public: Callback that is executed after intialization
def setup end
def skip?(logger)
method is the only place expected to write to a logger, any other
takes a `logger` that responds to +debug+ and +info+. The `skip?`
If `skip?` returns truthy it will not continue. This method
The `skip?` will be called before anything will be written.
Public: Handles logic for skipping exporter and notifying logger
def skip?(logger) false end
def write(filename = target)
`filename`. Defaults to the `target`. Method
Public: Yields a file that can be written to with the input
def write(filename = target) FileUtils.mkdir_p File.dirname(filename) PathUtils.atomic_write(filename) do |f| yield f end end