Skip to main content

Khufu/Pyramid component for managing javascript resources

Project description


*khufu_javascript* provides various ways for including Javascript into
your Khufu/Pyramid app.

Dojo Support

``khufu_javascript.dojo`` provides support for working with Dojo.


Setting up khufu_javascript.dojo is easy.

# config must be an instance of pyramid.config.Configurator

The previous example will iterate over all *.js files in the ``javascripts``
directory relative to the ``myproject`` package (``register_script_dir`` takes
an asset spec). For each .js file found it scans for a "dojo.provides('foo')"
entry and registers that module with khufu_javascript.

After having registered scripts, they can be accessed via the ``dojo`` view
at the root of the site. If one of the javascripts found has
"dojo.provides('')" then the dojo view will provide::

Anyone working with Dojo modules knows that there still needs to a way
to tell Dojo to look at */dojo/whatever* when looking up non-core modules.
Dojo handles this with *djConfig* which can be used to setup module load

After having registered scripts, inside of your views you can simply call

from khufu_javascript.dojo import render_header

@view_config('myview', renderer='templates/foo.jinja2',
def myview(request):
dojo_header = render_header(request)
return {'dojo_header': dojo_header}

<!-- templates/foo.jinja2 -->
{{ dojo_header|safe }}
yes sir!

The ``render_header`` method will generate the appropriate *<link>*, *<style>*,
and *<script>* elements for loading Dojo. It will also generate
the appropriate *djConfig* object that configures the module loading path
to work with our /dojo view.


0.1 (Jul-10-2011)

* first release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for khufu_javascript, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size khufu_javascript-0.1.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page