score.js

This small module just defines the ‘application/javascript’ mime type for score.tpl and configures some parameters for javascript rendering.

Quickstart

Usually, it is sufficient to add this module to your initialization list:

[score.init]
modules =
    score.tpl
    score.js

Configuration

score.js.init(confdict, tpl)[source]

Initializes this module acoording to our module initialization guidelines with the following configuration keys:

minifier None
The minifier to use for minification. Will be initialized using score.init.parse_object(). See score.tpl.minifier for available minifiers.
tpl.register_minifier False
Whether javascript templates should be minified. Setting this to True will register a postprocessor for the ‘application/javascript’ file type in score.tpl.
tpl.html_escape escape_json
An optional function, that will be registered as a global function in ‘text/html’ templates.

Details

Minification

The minifier package provides means for reducing the size of javascript code without altering its semantics. If one does not care, how the code is minified, one can just use the functions minify_string() and minify_file().

Currently, the following minification backends are supported:

  • slimit: Provides good minification, but is quite slow. Does not preserve licensing information.
  • jsmin: Very fast, but not the best minification. Does not preserve licensing information.
  • uglifyjs: Moderate speed and good minification. Preserves licensing information; dependends on node.js.
  • yui compressor: Fast but moderate compression. Preserves licensing information; depends on java.

API

Configuration

score.js.init(confdict, tpl)[source]

Initializes this module acoording to our module initialization guidelines with the following configuration keys:

minifier None
The minifier to use for minification. Will be initialized using score.init.parse_object(). See score.tpl.minifier for available minifiers.
tpl.register_minifier False
Whether javascript templates should be minified. Setting this to True will register a postprocessor for the ‘application/javascript’ file type in score.tpl.
tpl.html_escape escape_json
An optional function, that will be registered as a global function in ‘text/html’ templates.
class score.js.ConfiguredJsModule(tpl, minifier, extensions)[source]

This module’s configuration object.

score_webassets_proxy()[source]

Provides a WebassetsProxy for score.webassets.

Minifier

score.js.minifier.minify_string(js, outfile=None)[source]

Minifies given js string using uglifyjs, as this is the only configuration-free backend that preserves licensing information.

By default, this function returns the minified string. It is also possible to provide an outfile to write the result to, instead of returning it.

score.js.minifier.minify_file(file, outfile=None)[source]

Does the same as minify_string(), but operates on an input file, instead of a string.

class score.js.minifier.MinifierBackend(shortname)[source]

Abstract base class for minifier backends.

minify_file(file, outfile=None)[source]

Backend-specific implementation of the global function minify_file().

minify_string(string, outfile=None, *, path=None)[source]

Backend-specific implementation of the global function minify_string().

class score.js.minifier.Slimit[source]

MinifierBackend using slimit.

class score.js.minifier.Jsmin[source]

MinifierBackend using jsmin.

class score.js.minifier.Uglifyjs(uglify_path='uglifyjs')[source]

MinifierBackend using uglifyjs.

class score.js.minifier.YuiCompressor(jar_path)[source]

MinifierBackend using yui compressor. Constructor needs the path to yuicompressor’s jar file.