Giter VIP home page Giter VIP logo

python-neuronjs's Introduction

Build Status

python-neuronjs

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

Install

$ pip install neuronjs

Usage

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.

  • dependency_tree dict the json.loads()ed dependency tree
  • resolve function(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.
  • debug 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.
    • if debug is callable, neuronjs will use the return value of method debug
    • if debug is a boolean value, and debug is true, the debug mode will be on.
  • cache 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 key
    • cache.set(key, value) sets the value by key
  • version str only works if cache is defined. neuronjs will uses version to generate the key to cache the output result

module id

<name>@<version><path>  # for example: '[email protected]/jquery.js'

n.facade(entry, data=None, defer=False)

  • entry str id of the entry module
  • data dict=None the data of the facade, which will be passed to the entry module.
  • defer 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

n.combo(id...)

Makes packages of ids to combine into a single file.

  • id 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 ''

n.css(id)

Registers an css module, and tell neuronjs to output it on the page.

Returns ''

n.src(id)

Returns the absolute path of the corresponding module.


Methods below are used in base template.

n.output_scripts()

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

n.output_facades()

Outputs the initialization of facades.

Returns str

n.output_css()

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

License

MIT

python-neuronjs's People

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

pombredanne

python-neuronjs's Issues

1.1.0: facade(id, defer=True)

in python

neuron.facade('home', defer = True)

Then it will output configurations for js neuron.config.

When running

neuron.facade('home')

in javascript

The specific scripts will be loaded and excuted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.