Use html pages as templates for your clojurescript applications.
The library is based on html being the defining source for both the visual
appearance of you application, and the events that drive it. Events are
delivered via core.async
channels.
EXPERIMENTAL
Papadom uses custom attributes to recognise templates and elements that should generate events when the user interacts with them. See the example todo app page.
There is also an introductory blog post.
t-content
: declares a template scope that will be passed a map of values that may be used
in mustache type template expressions. The value of thet-content
is the name
of the template.
t-template
: declares a template scope that will be passed a sequence of values. For each
element in the sequnce, the contents of the element with the t-template
attribute will be rendered. The element of the sequence becomes the current
expression for mustache type template expressions. The value of the
t-template
is both the name of the expression to iterate over, and the name
of the template.
t-scope
: within a t-content
or t-template
element, this can be used to further
narrow the current expression for mustache type template expressions.
t-event
: used to indicate that the element should generate an event. The attribute
value becomes the name of the event.
t-id
: used with elements having a t-event
attribute. Specifies a comma
separated list of attribute names to be passed in the event data.
The papadom.template
namespace provides functions for interacting with the
templates from within your application. See the example
todo app code.
The compile-templates
function must be called first, in order to compile the
templates in the current page.
The template-events
is called with a core.async
channel which is configured
to receive events from t-event
annotated elements. You're application reads
events from the event channel, modifies it's internal state, calling render
to re-display the templates based on that state.
Papadom uses handlebars.js and jQuery. Since we use jQuery via jayq, it has to
be specified as a <script>
tag in the browser.
You can provide handlebars.js
in several ways.
See Luke Vanderhart's post for a general introduction to using Javascript libraries in Clojurescript.
You can add a <script>
links in the applications web page to provide
handlebars.js. In this case you should create an empty papadom.js.jquery
namespace.
To use :optimizations
other than :whitespace
with this approach, you will
need to add :externs
to the :compiler
map in you cljsbuild definitions.
To use the versions of the handlebars.js included with Papadom, add the
following to your lein-cljsbuild :compiler
configuration maps.
:foreign-libs
[{:file "papadom/js/handlebars.js"
:provides ["papadom.js.handlebars"]}]
Add your own versions of handlebars.js as a resource, and add
:foreign-libs
definitions as above, but with the :file
value pointing to the
classpath relative path for your versions of the libraries.
Copyright © 2013 Hugo Duncan
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.