g1.js is some work toward an implementation of GRDDL in JavaScript, with an HTML form test/demo interface. It's also an expedition into the world of JavaScript by a python hacker.
Any number of times I have had an itch where scratching it involved JavaScript, so I'd google for "JavaScript tutorial". The top hits are full of suggestions to do things that no self-respecting software engineer should do:
Worst of all, why do so many tutorials fail to cite whatever sources they are based on? They don't claim to be exhaustive or authoritative, so I expected a "for more details, see ..." link. No joy. For example, the w3schools javascript tutorial says to use text/javascript but the IETF spec deprecates that in favor of application/javascript.
Last week, I finally got over the hump. (See #swig notes 2007-08-10, version control change log.) Recall from my Feb 2006 item, python, javascript, and PHP, oh my!:
Another important way that python is self-documenting is that it meets the unambiguity requirement: you can pick up any .py file and trace every identifier back to what it refers to by following your nose...
JavaScript doesn't have that nice follow-your-nose property. Douglas Crockford concurs:
JavaScript's biggest problem is its dependence on global variables, particularly on implied global variables.
JSLint -- The JavaScript Verifier, 2002
JSLint will gripe about undeclared globals and supports a "yes, I'm using this as an implicit global on purpose" syntax: /*extern functionXYZ */. So the globals I'm using are:
emacs users, note: jslint recommends indenting 4 spaces, but emacs c-mode indents 2. See Karl Landström's JavaScript mode for Emacs 2006-12-26.
I tried an XMLHttpRequest for the 1st input document from the GRDDL test cases, http://www.w3.org/2001/sw/grddl-wg/td/xmlWithGrddlAttribute.xml, but I got:
Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
I found a work-around:
The same-origin policy does not apply to HTML files run from the local filesystem.
Wikipedia on Same origin policy
So I made a symlink to my local copy of the test cases and I'm using relative links, e.g. td/xmlWithGrddlAttribute.xml
The GRDDL spec has four main sections to implement:
After getting support for grddl:transformation working and tested fairly thoroughly, adding support for rel="transformation" was pretty easy.
But it's all synchronous. Before attacking the recursive cases, I think I'd better fix it to be asynchronous.