Python utilities and middleware for neuron.js
neuronjs analyzes the dependencies from user defined facades according to the dependency tree, and outputs <script>
tags and configurations for neuron.js
The dependency tree can be generated by neuron-package-dependency
$ pip install neuronjs
from neuronjs import Neuron
n = Neuron(
dependency_tree = dependency_tree, # must defined
resolve = resolve,
version = version,
cache = cache,
debug = False)
neuronjs
could be used either in template file or your python controller.
Here is a sample Jinja2 template file.
dict
the json.loads()
ed dependency treefunction(id)=
(optional) implements your own custom resolver. resolve
accepts one parameter id
which can be either a str
of module id or a list
of module ids. If a str
is passed in, the method should returns the resolved absolute url of the module id. If id
is a list
, an url of comboed script files should be returned.function|bool=False
tells neuronjs whether should switch on debug mode. When on debug mode, no javascript files of dependencies will be preloaded, and the output will not be compressed.
debug
is callable, neuronjs will use the return value of method debug
debug
is a boolean value, and debug
is true, the debug mode will be on.dict=None
if cache
is defined, it should contains 3 methods:
cache.has(key)
returns bool
cache.get(key)
looks up and returns the cached value by keycache.set(key, value)
sets the value by keystr
only works if cache
is defined. neuronjs will uses version
<name>@<version><path> # for example: '[email protected]/jquery.js'
str
id of the entry moduledict=None
the data of the facade, which will be passed to the entry module.bool=False
whether should defer the loading process of the facade. If True
, the script of the facade and its dependencies will not be loaded at the beginning of the page as much as possible.Registers a facade entry with data
. neuronjs will
Returns ''
(empty string), so you can use this method in python template
Makes packages of ids to combine into a single file.
str
the module id of commonjs module or css module.n.combo('jquery', 'underscore')
n.combo('app-home/style.css', 'app-user/user.css')
Returns ''
Registers an css module, and tell neuronjs to output it on the page.
Returns ''
Returns the absolute path of the corresponding module.
Methods below are used in base template.
Outputs neuron.js, neuron initial configurations and the html of script tags.
For most cases, this method should be used in the base template file, see example.
Returns str
Outputs the initialization of facades.
Returns str
Outputs the html of link elements of csses.
For most cases, this method should be used in the base template file, see example.
Returns str
MIT