[ANN] Clout and Hiccup

106 views
Skip to first unread message

James Reeves

unread,
Nov 28, 2009, 7:11:07 PM11/28/09
to Clojure
Hi folks,

I've spun off some functionality of the Compojure web framework into
two standalone libraries, Clout and Hiccup.

Clout is a HTTP routing library. It uses a similar style to the routes
in Ruby web frameworks like Rails and Sinatra, and is based off the
compojure.http.routes code. However, I've expanded the functionality
to allow keywords to be bound to arbitrary regular expressions:

(route-compile "/user/:id" {:id #"\d+"})

More information and examples can be found on the GitHub page:
http://github.com/weavejester/clout

Hiccup is a HTML generation library, like clj-html. It's based off the
code in compojure.html, but I've improved its performance and tidied
things up a little. It comes with helper functions for generating
things like doctypes and forms:

(doctype :html4)

(form-to [:post "/bookmarks"]
(label :url "URL")
(text-field :url)
(submit-button "Add"))

Hiccup also watches out for HTML tags that require explicit closing
tags (like <script>), and handles nil and boolean attributes
intelligently:

user=> (html [:input {:type "checkbox", :name :example, :checked
true, :value nil}])
"<input checked=\"checked\" name=\"example\" type=\"checkbox\" />"

Hiccup also expands seqs into the body of the tag, allowing the 'for'
macro to be used for iteraction:

[:ul
(for [x items]
[:li x]))

Hiccup and Clout are still in development, but they are pretty much as
complete now as the equivalent libraries in Compojure. I'll be looking
to use Clout and Hiccup as dependencies for Compojure in future, but
these will be, in effect, completely independent libraries that can be
used in any Clojure web framework.

- James

Wilson MacGyver

unread,
Nov 28, 2009, 8:35:05 PM11/28/09
to clo...@googlegroups.com
Are there any plans to add these features back into compojure?

Thanks

James Reeves

unread,
Nov 28, 2009, 8:56:11 PM11/28/09
to Clojure
On Nov 29, 1:35 am, Wilson MacGyver <wmacgy...@gmail.com> wrote:
> Are there any plans to add these features back into compojure?

Yep. Compojure will use Hiccup and Clout in the near future for
handling routes and HTML generation. Most of the server stuff will be
handled by Ring, and I'll probably spin off the Jetty server stuff
into a "cljetty" library.

- James
Reply all
Reply to author
Forward
0 new messages