John Baylor experiments

Scrappy

Update: Ignore all the great ideas below. @defunkt pointed me to jaml, which does a big chunk of what I was interested in.

I’ve followed the work of @hcatlin, @defunkt and @justinbmeyer on templating languages (haml, mustache and javascriptMVC) and have looked for something that met my needs. Here is an idea that seems simpler than javascriptMVC but has more power than haml or mustache – hopefully the sweet spot I’ve been looking for.

The initial idea, inspired by haml but not needing a text parser, was to represent markup as JSON:

Which would generate:

However, this provides no support for interaction with the markup. When considering generating a set of dialogs for user interaction I really wanted field validation built in, like this:

Eventually I realized that wrapping all the functionality as a filter, in essence creating a tiny scrap of functionality, was what I was looking for:

I could see wrapping a form scrap in a larger dialog-handling scrap that knew enough to validate its internal scraps before allowing the OK button to save the data. It should work – I just wish it could be as pretty as the others – but I don’t see that as possible, given the semantics of JSON.

The true test will be when I actually implement the code to support such a construct. Look for a johnb/scrappy project on Github. Until then, I’ll just assume it works! ;-)

Blog format shamelessly lifted from Mojombo, creator of Jekyll