Khufu/Pyramid component for managing javascript resources
Project description
Introduction
============
*khufu_javascript* provides various ways for including Javascript into
your Khufu/Pyramid app.
Dojo Support
============
``khufu_javascript.dojo`` provides support for working with Dojo.
Usage
-----
Setting up khufu_javascript.dojo is easy.
::
# config must be an instance of pyramid.config.Configurator
config.include('khufu_javascript.dojo')
config.register_script_dir('myproject:javascripts')
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('foo.bar')" then the dojo view will provide::
http://127.0.0.1:8080/dojo/foo/bar.js
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
paths.
After having registered scripts, inside of your views you can simply call
``khufu_javascript.dojo.render_header``.
::
# views.py
from khufu_javascript.dojo import render_header
@view_config('myview', renderer='templates/foo.jinja2',
context=Root)
def myview(request):
dojo_header = render_header(request)
return {'dojo_header': dojo_header}
<!-- templates/foo.jinja2 -->
<html>
<head>
{{ dojo_header|safe }}
</head>
<body>
yes sir!
</body>
</html>
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.
Changes
=======
0.1 (Jul-10-2011)
-----------------
* first release
============
*khufu_javascript* provides various ways for including Javascript into
your Khufu/Pyramid app.
Dojo Support
============
``khufu_javascript.dojo`` provides support for working with Dojo.
Usage
-----
Setting up khufu_javascript.dojo is easy.
::
# config must be an instance of pyramid.config.Configurator
config.include('khufu_javascript.dojo')
config.register_script_dir('myproject:javascripts')
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('foo.bar')" then the dojo view will provide::
http://127.0.0.1:8080/dojo/foo/bar.js
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
paths.
After having registered scripts, inside of your views you can simply call
``khufu_javascript.dojo.render_header``.
::
# views.py
from khufu_javascript.dojo import render_header
@view_config('myview', renderer='templates/foo.jinja2',
context=Root)
def myview(request):
dojo_header = render_header(request)
return {'dojo_header': dojo_header}
<!-- templates/foo.jinja2 -->
<html>
<head>
{{ dojo_header|safe }}
</head>
<body>
yes sir!
</body>
</html>
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.
Changes
=======
0.1 (Jul-10-2011)
-----------------
* first release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
khufu_javascript-0.1.tar.gz
(6.2 kB
view details)
File details
Details for the file khufu_javascript-0.1.tar.gz
.
File metadata
- Download URL: khufu_javascript-0.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bc7956c6f269ef7e1f37708d46f38fccf564319cf234ca1e8687345841b74e1 |
|
MD5 | c85b328bddca3c38fe13440b4969e5fb |
|
BLAKE2b-256 | 30305efe607f9877ac90495d2f9966c9ae226fff9f3a98b8c588f16cfe9b7874 |