#!/usr/bin/env waul-1.2 # JQuery DOM combinators | Spencer Tipping # Licensed under the terms of the MIT source code license # Introduction. # DOM drivers are macro systems that transform HAML-like markup into underlying DOM calls. For instance: # | div.foo /jquery -> $('
').addClass('foo') # table(tr(td('hi')), tbody) /jquery -> $('').append($('').append($(''))) # None of the macroexpansions here rely on opaque syntax refs, so they can all be precompiled. Also, the generated code refers to jQuery rather than $ -- this gives you more flexibility about # setting noConflict(). If you need to set noConflict(true) (which removes the global jQuery variable), you can bind it locally to make the DOM stuff work: # | div.foo /jquery -where [jQuery = stashed_copy_of_jquery] # Notation. # Caterwaul didn't previously have a DOM plugin in its core distribution. The html[] macro in previous versions of caterwaul came from montenegro, a web framework I was developing in tandem with # caterwaul. However, it's useful to have DOM functionality so I'm including it in the main caterwaul distribution. # Most of the syntax is copied from the html[] macro in montenegro: # | element.class -> $('').addClass('class') # element *foo('bar') -> $('').attr('foo', 'bar') # element *!foo('bar') -> $('').data('foo', 'bar') <- new! # element /foo('bar') -> $('').foo('bar') # element /!foo(bar) -> $('').bind('foo', bar) <- new! # +element -> element <- new! # element %foo -> foo($('')) # element(child) -> $('').append(child /jquery) <- here the /jquery marker indicates that 'child' will be re-expanded # element(child1, child2) -> $('').append((child1 /jquery).add((child2 /jquery))) # element[child] -> $('').append(child) <- no re-expansion here # element[child1, child2] -> $('').append(child1.add(child2)) # element < tree -> $('').append(tree.toString()) <- used to build populated
').append('hi')).add($('