Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install khufu-javascript

How to install khufu_javascript

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install khufu-javascript
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0a1 Available View build log
0.1 Available View build log
Windows (64-bit)
1.0a1 Available View build log
0.1 Available View build log
Mac OS X (10.5+)
1.0a1 Available View build log
0.1 Available View build log
Linux (32-bit)
1.0a1 Available View build log
0.1 Available View build log
Linux (64-bit)
1.0a1 Available View build log
0.1 Available View build log
 
Author
License
BSD
Dependencies
Lastest release
version 1.0a1 on Nov 18th, 2011

Introduction

khufu_javascript provides various ways for including Javascript and stylesheet resources into your Khufu/Pyramid app. It currently requires Python 2.7 or higher (Python 3.x not tested).

Usage - Resource Registry

khufu_javascript.ResourceRegistry is a helper utility for managing Javascript and Stylesheet resources.

The curent ResourceRegistry can be looked up by calling (after including khufu_javascript with the configurator):

>>> from khufu_javascript import get_resource_registry
>>> config.include('khufu_javascript')
>>> helper = get_resource_registry(config)
>>> helper.add_javascript('/static/foobar.js')
>>> helper.add_stylesheet('http://someplace.com/style.css')

And inside a view (since khufu_javascript sets up a template-accessible khufu_resources object):

<!-- templates/foo.jinja2 -->
<html>
  <head>
    {{ khufu_resources.render()|safe }}
  </head>
  <body>
    yes sir!
  </body>
</html>
Usage - Dojo

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
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.

System Message: WARNING/2 (<string>, line 49); backlink

Inline emphasis start-string without end-string.

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.

Here's an example.

# views.py
from khufu_javascript.dojo import get_script_registry
from khufu_javascript import RequestRenderable

@view_config('myview', renderer='templates/foo.jinja2',
             context=Root)
def myview(request):
    dojo = RequestRenderable(get_script_registry(request), request)
    return {'dojo': dojo}

<!-- templates/foo.jinja2 -->
<html>
  <head>
    {{ dojo.render()|safe }}
  </head>
  <body>
    yes sir!
  </body>
</html>

The dojo.render() 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.2 (unreleased)
  • Now sets up resource helper for compiling list of javascripts/stylesheets
0.1 (Jul-10-2011)
  • first release

Subscribe to package updates

Last updated Nov 18th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.