Skip to content

kanasubs/shakkuri

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shakkuri

Shakkuri brings custom tags to Hiccup, a library for representing HTML in Clojure. It uses vectors to represent elements, and maps to represent an element's attributes.

Install

Add the following dependency to your project.clj file:

clojars version

The version number will always match Hiccup's.

Why?

After reading this discussion I got interested on these custom tags. I think they are awesome because they are abstracted as vectors, just like any other tags. Furthermore, I don't like as much to see () representing custom tags because it feels as do something, but [] really feels as something. The map of transform fns proposal is probably a sound improvement because it's independent and explicit about where the custom tags come from. Maybe in the future I'll implement that proposal which only requires adding the map of transform fns to the html fn in the user code.

Syntax

Examples for custom tags are here and here.

Here is a basic example of Hiccup syntax:

user=> (use 'hiccup.core)
nil
user=> (html [:span {:class "foo"} "bar"])
"<span class=\"foo\">bar</span>"

The first element of the vector is used as the element name. The second attribute can optionally be a map, in which case it is used to supply the element's attributes. Every other element is considered part of the tag's body.

Hiccup is intelligent enough to render different HTML elements in different ways, in order to accommodate browser quirks:

user=> (html [:script])
"<script></script>"
user=> (html [:p])
"<p />"

And provides a CSS-like shortcut for denoting id and class attributes:

user=> (html [:div#foo.bar.baz "bang"])
"<div id=\"foo\" class=\"bar baz\">bang</div>"

If the body of the element is a seq, its contents will be expanded out into the element body. This makes working with forms like map and for more convenient:

user=> (html [:ul
               (for [x (range 1 4)]
                 [:li x])])
"<ul><li>1</li><li>2</li><li>3</li></ul>"

Something is missing?

Ask me :)

Feature requests are welcome!

Contributors

License

Copyright (C) 2014 Carlos C. Fontes.

Double licensed under the Eclipse Public License (the same as Clojure) or the Apache Public License 2.0.

About

Fast library for rendering HTML in Clojure

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 100.0%