Composing HTML rendering functions

31 views
Skip to first unread message

Thorsten Wilms

unread,
Oct 7, 2011, 4:13:08 PM10/7/11
to clojure...@googlegroups.com
Hi!

Initially I created a mess of interlinked functions for rendering HTML
via hiccup.

I have few pages with parts that may vary or may be present or not based
on whether the user is logged in as admin.

With the desire to test for the role in a single place and for composing
the views in a uniform way, I created a little framework and now wonder
if I'm thinking too complicated, or if this seems sound. Can you suggest
improvements or alternatives?


The outcome is that I can define my views via defviews:
https://github.com/thorwil/tlog-clj-gae/blob/4440f729001ef14ea63115c69f0c868bc59e4686/src/tlog/views/views.clj

The roles are cumulative.

Every view defined in this way expects a role and a map (from the
datastore). The maps is handed through all elements in the vector
(except if it happens to be a def). The html is assembled as value to
:buildup. Every element may read and update/add arbitrary key-vals.

All the somewhat complicated business happens here:

https://github.com/thorwil/tlog-clj-gae/blob/4440f729001ef14ea63115c69f0c868bc59e4686/src/tlog/views/compose.clj

To allow the rather straightforward parts:

https://github.com/thorwil/tlog-clj-gae/blob/4440f729001ef14ea63115c69f0c868bc59e4686/src/tlog/views/parts.clj

The {:keys} specified are like slots. If one is nil, Hiccup makes it
fall out.


--
Thorsten Wilms

thorwil's design for free software:
http://thorwil.wordpress.com/

Reply all
Reply to author
Forward
0 new messages