API

Asset Attributes

class gears.asset_attributes.AssetAttributes(environment, path)

Provides access to asset path properties. The attributes object is created with environment object and relative (or logical) asset path.

Some properties may be useful or not, depending on the type of passed path. If it is a relative asset path, you can use all properties except search_paths. In case of a logical asset path it makes sense to use only those properties that are not related to processors and compressor.

Parameters:
  • environment – an instance of Environment class.
  • path – a relative or logical path of the asset.
compiler_extensions

The list of compiler extensions. Example:

>>> attrs = AssetAttributes(environment, 'js/lib/external.min.js.coffee')
>>> attrs.suffix
['.coffee']
compilers

The list of compilers used to build asset.

compressor

The compressors used to compress the asset.

dirname = None

The relative path to the directory the asset.

environment = None

Used to access the registries of compilers, processors, etc. It can be also used by asset. See Environment for more information.

extensions

The list of asset extensions. Example:

>>> attrs = AssetAttributes(environment, 'js/models.js.coffee')
>>> attrs.extensions
['.js', '.coffee']

>>> attrs = AssetAttributes(environment, 'js/lib/external.min.js.coffee')
>>> attrs.format_extension
['.min', '.js', '.coffee']
format_extension

The format extension of asset. Example:

>>> attrs = AssetAttributes(environment, 'js/models.js.coffee')
>>> attrs.format_extension
'.js'

>>> attrs = AssetAttributes(environment, 'js/lib/external.min.js.coffee')
>>> attrs.format_extension
'.js'
logical_path

The logical path to asset. Example:

>>> attrs = AssetAttributes(environment, 'js/models.js.coffee')
>>> attrs.logical_path
'js/models.js'
mimetype

MIME-type of the asset.

path = None

The relative (or logical) path to asset.

path_without_suffix

The relative path to asset without suffix. Example:

>>> attrs = AssetAttributes(environment, 'js/app.js')
>>> attrs.path_without_suffix
'js/app'
postprocessors

The list of postprocessors used to build asset.

preprocessors

The list of preprocessors used to build asset.

processors

The list of all processors (preprocessors, compilers, postprocessors) used to build asset.

search_paths

The list of logical paths which are used to search for an asset. This property makes sense only if the attributes was created with logical path.

It is assumed that the logical path can be a directory containing a file named index with the same suffix.

Example:

>>> attrs = AssetAttributes(environment, 'js/app.js')
>>> attrs.search_paths
['js/app.js', 'js/app/index.js']

>>> attrs = AssetAttributes(environment, 'js/app/index.js')
>>> attrs.search_paths
['js/models/index.js']
suffix

The list of asset extensions starting from the format extension. Example:

>>> attrs = AssetAttributes(environment, 'js/lib/external.min.js.coffee')
>>> attrs.suffix
['.js', '.coffee']

Asset Handlers

class gears.asset_handler.BaseAssetHandler

Base class for all asset handlers (processors, compilers and compressors). A subclass has to implement __call__() which is called with asset as argument.

__call__(asset)

Subclasses have to override this method to implement the actual handler function code. This method is called with asset as argument. Depending on the type of the handler, this method must change asset state (as it does in Directivesprocessor) or return some value (in case of asset compressors).

classmethod as_handler(**initkwargs)

Converts the class into an actual handler function that can be used when registering different types of processors in Environment class instance.

The arguments passed to as_handler() are forwarded to the constructor of the class.

class gears.asset_handler.ExecMixin

Provides the ability to process asset through external command.

executable = None

The name of the executable to run. It must be a command name, if it is available in the PATH environment variable, or a path to the executable.

get_args()

Returns the list of subprocess.Popen arguments.

get_process()

Returns subprocess.Popen instance with args from get_args() result and piped stdin, stdout and stderr.

params = []

The list of executable parameters.

run(input)

Runs executable with input as stdin. AssetHandlerError exception is raised, if execution is failed, otherwise stdout is returned.

Processors

class gears.processors.base.BaseProcessor

Base class for all asset processors. Subclass’s __call__() method must change asset’s processed_source attribute.

Compilers

class gears.compilers.base.BaseCompiler

Base class for all asset compilers. Subclass’s __call__() method must change asset’s processed_source attribute.

result_mimetype = None

MIME-type of the asset source code after compiling.

Project Versions

Table Of Contents

Previous topic

Installation

Next topic

Changelog

This Page