• Stars
    star
    206
  • Rank 184,085 (Top 4 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created almost 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A ClojureScript port of Hiccup - a fast library for rendering HTML in ClojureScript

Hiccups

Hiccups is a ClojureScript port of the Hiccup HTML generation library. It uses vectors to represent tags, and maps to represent a tag's attributes.

The goal is to provide similar performance to Closure Templates with a much more Clojure friendly syntax.

Differences from Hiccup

  • In ClojureScript, macros need to be defined in separate Clojure namespaces. Because of this, core functionality is split into two files: core.clj contains the macros and compile-time only functions, and runtime.cljs contains functions that are also available at runtime. The contents of runtime.cljs are also used at compile-time, so the goal is to keep it portable between ClojureScript and Clojure.
  • Unit tests are run in a PhantomJS browser using lein-cljsbuild and Closure's testing libs.
  • Not everything has been ported yet. See ToDo.

Alternatives

  • Crate is an alternative Hiccup style library for ClojureScript. The main difference between Crate and Hiccups is that Crate generates DOM nodes and Hiccups generates strings. There are a few reasons why you might consider Hiccups over Crate (YMMV, of course):
    • As with the original Hiccup, Hiccups tries to do as much as possible at compile time, with macro expansion.
    • Working with strings can be much more performant than working with DOM nodes, especially with large amounts of markup, and especially with older browsers.
    • Easier to use in headless environments like Node.js
  • Closure Templates is Google's Closure templating library.

Install

Add the following dependency to your project.clj file:

[hiccups "0.3.0"]

Usage

Require both the core macros and the runtime functions in your namespace declaration:

(ns myns
  (:require-macros [hiccups.core :as hiccups :refer [html]])
  (:require [hiccups.runtime :as hiccupsrt]))

(hiccups/defhtml my-template []
  [:div
    [:a {:href "https://github.com/weavejester/hiccup"}
      "Hiccup"]])

Syntax

Here is a basic example of Hiccups syntax:

(html [:span {:class "foo"} "bar"])
"<span class=\"foo\">bar</span>"

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

Hiccups is intelligent enough to render different HTML tags in different ways, in order to accommodate browser quirks:

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

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

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

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

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

Note that while lists are considered to be seqs in Clojure(Script), vectors and sets are not. As a consequence, Hiccups will bail out if a vector is passed in without a tag: [[:div] [:div]].

See the Hiccup wiki for more information.

ToDo

  • Catch up with recent changes in Hiccup.
  • Form helpers
  • Page helpers
  • Figure out if the runtime can be pulled in without an explicit require by the user
  • Explore potential performance improvements using Google's StringBuffer et al.

More Repositories

1

redux-voting-server

Server app for the Full-Stack Redux Tutorial
JavaScript
585
star
2

build-your-own-angularjs

Source Code & Errata for the "Build Your Own AngularJS" book. http://teropa.info/build-your-own-angular
JavaScript
584
star
3

redux-voting-client

Client app for the Full-Stack Redux Tutorial
JavaScript
372
star
4

angular-virtual-dom

A Virtual DOM based AngularJS view renderer designed to be used with immutable data structures
JavaScript
225
star
5

harmonics-explorer

A UI for exploring the harmonic series of sine waves. Done with Angular 2, @ngrx, Immutable.js
TypeScript
213
star
6

to-sting

Object.toSting() polyfill
206
star
7

weq8

A parametric EQ for Web Audio
TypeScript
176
star
8

in-c

A realization of Terry Riley's 1964 composition "In C" as an interactive web app
HTML
117
star
9

nlp

My explorations in natural language processing
Clojure
103
star
10

musicforairports.js

JavaScript
63
star
11

windchimes

TypeScript
60
star
12

schmangular.js

An ad hoc, informally-specified, bug-ridden, slow implementation of half of AngularJS
JavaScript
56
star
13

discreetmusic.js

JavaScript
38
star
14

itsgonnarain.js

JavaScript
36
star
15

ng-gfx-demos

Demos for my NG-BE talk about SVG and Canvas graphics and animations in Angular 2.
TypeScript
36
star
16

generative-music-workshop

A simple seed repo for a workshop on making generative music with Tone.js
JavaScript
24
star
17

elseq

An Angular 2 animation experiment, inspired by the cover art of "elseq" by Autechre
TypeScript
15
star
18

triangle-tessellation

A JavaScript implementation of the triangle tessellation algorithm from the OpenGL specification for tessellation shaders.
TypeScript
15
star
19

lein-flyway

A Leiningen plugin for the Flyway database migration framework
Clojure
14
star
20

metabubbles

A generative art experiment in Angular 2
TypeScript
14
star
21

ngrx-hotload-rc5

minimum viable hot loading setup for Angular rc.5 and @ngrx/store
TypeScript
14
star
22

spectrum-analyser

A Web Audio spectrum analyser
TypeScript
11
star
23

ng-fractals

Angular version of https://swizec.com/blog/animating-svg-nodes-react-preact-inferno-vue/swizec/7311
TypeScript
10
star
24

oscilloscope

A Web Audio oscilloscope
TypeScript
8
star
25

drumkit

JavaScript
8
star
26

sproutcore-tutorial-compojure

Sample project of a Compojure / MongoDB backend for the SproutCore ToDos tutorial
Clojure
6
star
27

zombie-pandemic-tracker

They're coming
Java
4
star
28

redux-space-clockwork

A little generative art experiment with Redux and Immutable.
JavaScript
4
star
29

prolefeed

A simple Clojure library for fetching RSS/Atom feeds
Clojure
4
star
30

web-audio-from-the-ground-up-demos

Demo code for the article series "Web Audio From the Ground Up"
TypeScript
4
star
31

failurous-java

Failurous Java client
Java
3
star
32

failurous-ring

Clojure/Ring client for Failurous
Clojure
3
star
33

pickaxe-notes

Some notes to self from re-reading Pickaxe for Ruby 1.9
Ruby
3
star
34

chime-call-response

JavaScript
3
star
35

lein-gwt

A Leiningen plugin for the GWT compiler
Clojure
3
star
36

stem

A fork of the Eclipse Spatiotemporal Epidemiological Modeler project trunk
Java
2
star
37

rails_learning_specs

Learning Rails internals by writing specs
Ruby
2
star
38

rails-int-hh

Rails Intermediate Course for Haaga-Helia
Ruby
2
star
39

gwt-mxhr

A GWT port of the DUI.Stream library
Java
2
star
40

globetrotter

An HTML canvas based slippy map client for GWT
Java
1
star
41

bitrate-magenta-workshop

JavaScript
1
star
42

saddle

An experimental pure JavaScript port of the GWT layout constraint system
JavaScript
1
star
43

isbn_validator

Ruby
1
star
44

presentations

Presentations I've given / am giving
1
star
45

paip-clj

My explorations of "Paradigms of Artificial Intelligence Programming" in Clojure
Clojure
1
star
46

building-angular

Building angular-like framework for much clearer understanding of the core.
JavaScript
1
star
47

closure-study

Learning Closure libs
JavaScript
1
star