Database Reference
In-Depth Information
How it works…
The Hiccup DSL is quite simple, and we can see examples of almost all of its syntax in this
recipe, as shown here:
1.
We have an HTML tag with some text content, as shown here:
[:title "Web Charts"]
2.
We have nested elements:
[:head
[:title "Web Charts"]]
3.
We can include attributes as a hashmap after the tag-name keyword:
[:h1 {:id "web-charts"} "Web Charts"]
4.
Irrespective of the structure, we eventually pass it to one of the rendering functions.
In this case, we're displaying it as HTML5, so we use this builder function:
(html5
Hiccup also has a number of functions that can be used to insert links to CSS iles and script
elements. We'll see examples of these in the
Creating scatter plots with NVD3
recipe.
There's more…
good starting point to use Hiccup
F
In order to actually write HTML pages using Hiccup, the page on its syntax at
particularly useful
Setting up to use ClojureScript
The only thing that's missing is JavaScript. We can also generate this with ClojureScript
Clojure that compiles to JavaScript.
Why will we want to write JavaScript in Clojure? First, it simpliies your project when both
the client and the server are written in the same language. It also allows you to share code
between the two sides of your application, which can cut down the complexity of your code
as well as the lines of code.