Heist Template Abstractions in a Nutshell

In the last post I discussed how logic and control flow can (and I argue should) be done in splices where types, higher order functions, and the full power of Haskell can be applied to the problem. In this post I want to take some time to think about the raw materials that are available in templates.

At the lowest level, we have just Text (...which is certainly /= Nothing). The templates are read in as Text and parsed into HTML DOM structures: elements, children, and attributes. Heist's abstractions for these entities are roughly analogous to the lambda calculus. The lambda calculus primitives are function definition and function application. HTML structures don't have any kind of representation for functions, so Heist uses lists of DOM tree nodes as the fundamental unit. Two different ways of representing them are splices and templates. The following table summarizes Heist's HTML abstraction tools.

Definition Application
Splices <bind> use the tag
Templates file on disk <apply>

To define a splice, use the bind tag. To define a template, create a file on disk. To apply/evaluate a splice, just use the tag that you bound. To apply/evaluate a template, use the apply tag. The Heist tutorial has the details on how to use <bind> and <apply>. Splices and templates can both be thought of as functions because their methods of application allow data to be passed in to modify the output.

We've consciously avoided introducing generalized control flow that requires expressions and types--things that HTML is not suited for. But the abstractions that are available in templates work well with the primitives naturally available in the domain. This yields a powerful template system with syntax that designers already understand and can manipulate with existing tools.


Popular posts from this blog

Ember.js is driving me crazy

Dependent Types are a Runtime Maybe

Setting Up A Private Nix Cache