Dojo / JSON-RPC support for Zope 3

This is mostly a convenience package that configures a <resourceDirectory> for using dojo with Zope 3. It also provides Zope 3 infrastructure for using dojo's json-rpc client.

Installation:

  1. Unzip this package somewhere on the Python Path. [zope3 instance]/lib/python is a good choice.

  2. Get a Dojo distribution from http://download.dojotoolkit.org/ and unpack it into this folder. You must rename the folder or symlink it so that the main dojo folder is called "dojo". The folder structure should look like:

    [this folder] -> [dojo] -> dojo.js, [src], etc.
    
  3. Copy the dojosupport-configure.zcml file to [zope3 instance]/etc/package-includes.

Problems:

Zope 3 will sometimes assign an incorrect content-type for these files. This will cause occasional problems when dojo's parser depends on the content-type for parsing decisions. Mainly, if "<html>" is not early enough in a file, Zope 3 will not recognize the file as html and mark it as text/plain.

A work-around for this, presuming that Zope 3's behavior is intended, is to use another means to make dojo's files available.

One such method involves the WSGI capabilities of Zope 3/Twisted.

  1. Install Paste and PasteDeploy. These are available from the easy_install command.
  2. Install zope.paste, available in the same svn repository as Zope 3.
  3. In a zope3 instance's etc/paste.ini file, use Paste#urlmap and Paste#static to map the dojo directory referred to above to /@@/dojo
  4. Comment-out the <resourceDirectory> statement in this package's configure.zcml file.

Sample etc/paste.ini file:

[pipeline:zope]
pipeline = gzipper main

[composite:Paste.Main]
use = egg:Paste#urlmap
/ = zope
/@@/dojo = dojo

[app:main]
paste.app_factory = zope.paste.application:zope_publisher_app_factory

[app:dojo]
use=egg:Paste#static
document_root=/path/to/dojo/directory
filter-with = gzipper

[filter:gzipper]
paste.filter_factory=gzipper.gzipper:filter_factory
nocompress=jp gz zip
tempfile=0
# exclude=src

#[filter:printdebug]
#use=egg:Paste#printdebug
#[filter:lint]
#use=egg:Paste#lint

Usage:

Include the following in the <head> section of your html document.

<script type="text/javascript" src="/@@/dojo/dojo.js"></script>

JSON-RPC:

If jsonserver is installed, dojosupport provides a view called "jsonrpc.smd" for any traversable object. This provides a JSON-formatted breakdown of JSON-RPC methods available for that object.

This makes it possible to instanciate a json-rpc proxy in Dojo with the following javascript statements:

dojo.require("dojo.rpc.JsonService");
var proxy = new dojo.rpc.JsonService("jsonrpc.smd");