Repository: teropa/hiccups
Branch: master
Commit: 8cdfb79ee308
Files: 13
Total size: 44.4 KB
Directory structure:
gitextract_9f1bfi2j/
├── .gitignore
├── LICENSE.html
├── README.md
├── build.boot
├── dev-resources/
│ ├── public/
│ │ └── index.html
│ └── tools/
│ ├── http/
│ │ └── ring/
│ │ └── server.clj
│ └── repl/
│ └── brepl/
│ └── connect.cljs
├── profiles.clj
├── project.clj
├── src/
│ ├── clj/
│ │ └── hiccups/
│ │ ├── core.clj
│ │ └── runtime.clj
│ └── cljs/
│ └── hiccups/
│ └── runtime.cljs
└── test/
└── cljs/
└── hiccups/
└── core_test.cljs
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.jar
resources/private/js/*
classes/
out/
target/
pom.xml
.lein*
.repl
/classes
/checkouts
pom.xml.asc
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
/.idea
*.iml
.envrc
/out
================================================
FILE: LICENSE.html
================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Eclipse Public License - Version 1.0</title>
<style type="text/css">
body {
size: 8.5in 11.0in;
margin: 0.25in 0.5in 0.25in 0.5in;
tab-interval: 0.5in;
}
p {
margin-left: auto;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
p.list {
margin-left: 0.5in;
margin-top: 0.05em;
margin-bottom: 0.05em;
}
</style>
</head>
<body lang="EN-US">
<p align=center><b>Eclipse Public License - v 1.0</b></p>
<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
AGREEMENT.</p>
<p><b>1. DEFINITIONS</b></p>
<p>"Contribution" means:</p>
<p class="list">a) in the case of the initial Contributor, the initial
code and documentation distributed under this Agreement, and</p>
<p class="list">b) in the case of each subsequent Contributor:</p>
<p class="list">i) changes to the Program, and</p>
<p class="list">ii) additions to the Program;</p>
<p class="list">where such changes and/or additions to the Program
originate from and are distributed by that particular Contributor. A
Contribution 'originates' from a Contributor if it was added to the
Program by such Contributor itself or anyone acting on such
Contributor's behalf. Contributions do not include additions to the
Program which: (i) are separate modules of software distributed in
conjunction with the Program under their own license agreement, and (ii)
are not derivative works of the Program.</p>
<p>"Contributor" means any person or entity that distributes
the Program.</p>
<p>"Licensed Patents" mean patent claims licensable by a
Contributor which are necessarily infringed by the use or sale of its
Contribution alone or when combined with the Program.</p>
<p>"Program" means the Contributions distributed in accordance
with this Agreement.</p>
<p>"Recipient" means anyone who receives the Program under
this Agreement, including all Contributors.</p>
<p><b>2. GRANT OF RIGHTS</b></p>
<p class="list">a) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free copyright license to reproduce, prepare derivative works
of, publicly display, publicly perform, distribute and sublicense the
Contribution of such Contributor, if any, and such derivative works, in
source code and object code form.</p>
<p class="list">b) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free patent license under Licensed Patents to make, use, sell,
offer to sell, import and otherwise transfer the Contribution of such
Contributor, if any, in source code and object code form. This patent
license shall apply to the combination of the Contribution and the
Program if, at the time the Contribution is added by the Contributor,
such addition of the Contribution causes such combination to be covered
by the Licensed Patents. The patent license shall not apply to any other
combinations which include the Contribution. No hardware per se is
licensed hereunder.</p>
<p class="list">c) Recipient understands that although each Contributor
grants the licenses to its Contributions set forth herein, no assurances
are provided by any Contributor that the Program does not infringe the
patent or other intellectual property rights of any other entity. Each
Contributor disclaims any liability to Recipient for claims brought by
any other entity based on infringement of intellectual property rights
or otherwise. As a condition to exercising the rights and licenses
granted hereunder, each Recipient hereby assumes sole responsibility to
secure any other intellectual property rights needed, if any. For
example, if a third party patent license is required to allow Recipient
to distribute the Program, it is Recipient's responsibility to acquire
that license before distributing the Program.</p>
<p class="list">d) Each Contributor represents that to its knowledge it
has sufficient copyright rights in its Contribution, if any, to grant
the copyright license set forth in this Agreement.</p>
<p><b>3. REQUIREMENTS</b></p>
<p>A Contributor may choose to distribute the Program in object code
form under its own license agreement, provided that:</p>
<p class="list">a) it complies with the terms and conditions of this
Agreement; and</p>
<p class="list">b) its license agreement:</p>
<p class="list">i) effectively disclaims on behalf of all Contributors
all warranties and conditions, express and implied, including warranties
or conditions of title and non-infringement, and implied warranties or
conditions of merchantability and fitness for a particular purpose;</p>
<p class="list">ii) effectively excludes on behalf of all Contributors
all liability for damages, including direct, indirect, special,
incidental and consequential damages, such as lost profits;</p>
<p class="list">iii) states that any provisions which differ from this
Agreement are offered by that Contributor alone and not by any other
party; and</p>
<p class="list">iv) states that source code for the Program is available
from such Contributor, and informs licensees how to obtain it in a
reasonable manner on or through a medium customarily used for software
exchange.</p>
<p>When the Program is made available in source code form:</p>
<p class="list">a) it must be made available under this Agreement; and</p>
<p class="list">b) a copy of this Agreement must be included with each
copy of the Program.</p>
<p>Contributors may not remove or alter any copyright notices contained
within the Program.</p>
<p>Each Contributor must identify itself as the originator of its
Contribution, if any, in a manner that reasonably allows subsequent
Recipients to identify the originator of the Contribution.</p>
<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
<p>Commercial distributors of software may accept certain
responsibilities with respect to end users, business partners and the
like. While this license is intended to facilitate the commercial use of
the Program, the Contributor who includes the Program in a commercial
product offering should do so in a manner which does not create
potential liability for other Contributors. Therefore, if a Contributor
includes the Program in a commercial product offering, such Contributor
("Commercial Contributor") hereby agrees to defend and
indemnify every other Contributor ("Indemnified Contributor")
against any losses, damages and costs (collectively "Losses")
arising from claims, lawsuits and other legal actions brought by a third
party against the Indemnified Contributor to the extent caused by the
acts or omissions of such Commercial Contributor in connection with its
distribution of the Program in a commercial product offering. The
obligations in this section do not apply to any claims or Losses
relating to any actual or alleged intellectual property infringement. In
order to qualify, an Indemnified Contributor must: a) promptly notify
the Commercial Contributor in writing of such claim, and b) allow the
Commercial Contributor to control, and cooperate with the Commercial
Contributor in, the defense and any related settlement negotiations. The
Indemnified Contributor may participate in any such claim at its own
expense.</p>
<p>For example, a Contributor might include the Program in a commercial
product offering, Product X. That Contributor is then a Commercial
Contributor. If that Commercial Contributor then makes performance
claims, or offers warranties related to Product X, those performance
claims and warranties are such Commercial Contributor's responsibility
alone. Under this section, the Commercial Contributor would have to
defend claims against the other Contributors related to those
performance claims and warranties, and if a court requires any other
Contributor to pay any damages as a result, the Commercial Contributor
must pay those damages.</p>
<p><b>5. NO WARRANTY</b></p>
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
responsible for determining the appropriateness of using and
distributing the Program and assumes all risks associated with its
exercise of rights under this Agreement , including but not limited to
the risks and costs of program errors, compliance with applicable laws,
damage to or loss of data, programs or equipment, and unavailability or
interruption of operations.</p>
<p><b>6. DISCLAIMER OF LIABILITY</b></p>
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
<p><b>7. GENERAL</b></p>
<p>If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this Agreement, and without further action
by the parties hereto, such provision shall be reformed to the minimum
extent necessary to make such provision valid and enforceable.</p>
<p>If Recipient institutes patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that the
Program itself (excluding combinations of the Program with other
software or hardware) infringes such Recipient's patent(s), then such
Recipient's rights granted under Section 2(b) shall terminate as of the
date such litigation is filed.</p>
<p>All Recipient's rights under this Agreement shall terminate if it
fails to comply with any of the material terms or conditions of this
Agreement and does not cure such failure in a reasonable period of time
after becoming aware of such noncompliance. If all Recipient's rights
under this Agreement terminate, Recipient agrees to cease use and
distribution of the Program as soon as reasonably practicable. However,
Recipient's obligations under this Agreement and any licenses granted by
Recipient relating to the Program shall continue and survive.</p>
<p>Everyone is permitted to copy and distribute copies of this
Agreement, but in order to avoid inconsistency the Agreement is
copyrighted and may only be modified in the following manner. The
Agreement Steward reserves the right to publish new versions (including
revisions) of this Agreement from time to time. No one other than the
Agreement Steward has the right to modify this Agreement. The Eclipse
Foundation is the initial Agreement Steward. The Eclipse Foundation may
assign the responsibility to serve as the Agreement Steward to a
suitable separate entity. Each new version of the Agreement will be
given a distinguishing version number. The Program (including
Contributions) may always be distributed subject to the version of the
Agreement under which it was received. In addition, after a new version
of the Agreement is published, Contributor may elect to distribute the
Program (including its Contributions) under the new version. Except as
expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
rights or licenses to the intellectual property of any Contributor under
this Agreement, whether expressly, by implication, estoppel or
otherwise. All rights in the Program not expressly granted under this
Agreement are reserved.</p>
<p>This Agreement is governed by the laws of the State of New York and
the intellectual property laws of the United States of America. No party
to this Agreement will bring a legal action under this Agreement more
than one year after the cause of action arose. Each party waives its
rights to a jury trial in any resulting litigation.</p>
</body>
</html>
================================================
FILE: README.md
================================================
Hiccups
=======
Hiccups is a ClojureScript port of the [Hiccup](https://github.com/weavejester/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](https://github.com/emezeske/lein-cljsbuild/) and Closure's testing libs.
* Not everything has been ported yet. See ToDo.
Alternatives
------------
* [Crate](https://github.com/ibdknox/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](http://www.quirksmode.org/dom/innerhtml.html).
* Easier to use in headless environments like Node.js
* [Closure Templates](http://code.google.com/closure/templates/) is Google's Closure templating library.
Install
-------
Add the following dependency to your `project.clj` file:
```clojure
[hiccups "0.3.0"]
```
Usage
-----
Require both the core macros and the runtime functions in your namespace declaration:
```clojure
(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:
```clojure
(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:
```clojure
(html [:script])
"<script></script>"
(html [:p])
"<p />"
```
And provides a CSS-like shortcut for denoting `id` and `class`
attributes:
```clojure
(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:
```clojure
(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](https://github.com/weavejester/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.
================================================
FILE: build.boot
================================================
(def project 'hiccups)
(def version "0.3.1")
(set-env! :resource-paths #{"resources" "src/cljs" "src/clj"}
:source-paths #{"test"}
:asset-paths #{"html"}
:dependencies '[[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.8.40"]
[adzerk/boot-test "RELEASE" :scope "test"]
[adzerk/boot-cljs "1.7.228-1" :scope "test"]
[adzerk/boot-cljs-repl "0.3.0" :scope "test"]
[com.cemerick/piggieback "0.2.1" :scope "test"]
[weasel "0.7.0" :scope "test"]
[org.clojure/tools.nrepl "0.2.12" :scope "test"]
[adzerk/boot-reload "0.4.5" :scope "test"]
[pandeiro/boot-http "0.7.0" :scope "test"]
[cljsjs/boot-cljsjs "0.5.1" :scope "test"]
[provisdom/boot-tasks "0.5.1" :scope "test"]])
(task-options!
pom {:project project
:version version
:description "FIXME: write description"
:url "http://example/FIXME"
:scm {:url "https://github.com/yourname/tree-graph"}
:license {"Eclipse Public License"
"http://www.eclipse.org/legal/epl-v10.html"}})
(require
'[adzerk.boot-cljs :refer :all]
'[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
'[adzerk.boot-reload :refer :all]
'[pandeiro.boot-http :refer :all]
'[cljsjs.boot-cljsjs :refer :all]
'[provisdom.boot-tasks.core :refer :all])
(deftask web-dev
"Developer workflow for web-component UX."
[]
(comp
(serve :dir "target/")
(watch)
(cljs-repl)
(speak)
(reload)
(cljs)
(target)))
================================================
FILE: dev-resources/public/index.html
================================================
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bREPL Connection</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="test">
<h1>ClojureScript</h1>
</div>
<script src="js/hiccups.js"></script>
</body>
</html>
================================================
FILE: dev-resources/tools/http/ring/server.clj
================================================
;;; This namespace is used for development and testing purpose only.
(ns ring.server
(:require [cemerick.austin.repls :refer (browser-connected-repl-js)]
[net.cgrand.enlive-html :as enlive]
[compojure.route :refer (resources)]
[compojure.core :refer (GET defroutes)]
[ring.adapter.jetty :as jetty]
[clojure.java.io :as io]))
;;; We use enlive lib to add to the body of the index.html page the
;;; script tag containing the JS code which activates the bREPL
;;; connection.
(enlive/deftemplate page
(io/resource "public/index.html")
[]
[:body] (enlive/append
(enlive/html [:script (browser-connected-repl-js)])))
;;; defroutes macro defines a function that chains individual route
;;; functions together. The request map is passed to each function in
;;; turn, until a non-nil response is returned.
(defroutes site
(resources "/")
(GET "/*" req (page)))
;;; To run the jetty server. The server symbol is not private to
;;; allows to start and stop thejetty server from the repl.
(defn run
"Run the ring server. It defines the server symbol with defonce."
[]
(defonce server
(jetty/run-jetty #'site {:port 3000 :join? false}))
server)
================================================
FILE: dev-resources/tools/repl/brepl/connect.cljs
================================================
;;; This namespace is for creating the connection with the browser. It
;;; lives in the dev-resources/tools/brepl directory. It is used in the
;;; :dev profile only.
(ns brepl.connect
(:require [clojure.browser.repl]))
;;(repl/connect "http://localhost:9000/repl")
================================================
FILE: profiles.clj
================================================
;;; ****************************** NOTES ******************************
;;;
;;; The hiccups/profiles.clj file is used for keeping the developer
;;; view of your cljs lib separated from its user view. This way the
;;; user of your lib does not even see the complexity of the developer
;;; view of the lib. The hiccups/profiles.clj should never contain
;;; any configuration for the :user profile. The content of
;;; hiccups/profiles.clj will be merge with the content from the
;;; ~/.lein/profiles.clj and hiccups/project.clj. Keep in mind that
;;; any in case of conflicts, the hiccups/profiles.clj takes
;;; precedence over the hiccups/project.clj which, in turn, takes
;;; precedence over the ~/.lein/profiles.clj
;;;
;;; *******************************************************************
{:dev { ;; Add the out dir to the dirs to be cleaned by the lein clean
;; command. Add here any pathname containing generated files
;; to be cleaned by the lein clean command.
:clean-targets ["out"]
;; Add the test/clj and test/cljs dir to the leiningen
;; :test-paths option. It has to contain also the superset of
;; all the pathnames used for CLJS purpose. See below the
;; comment on Leiningen :source-paths.
:test-paths ["test/clj" "test/cljs"]
;; We need to add dev-resources/tools/repl, because cljsbuild
;; does not add its own source-paths to the project
;; source-paths.
:source-paths ["dev-resources/tools/http" "dev-resources/tools/repl"]
;; Add the dev-resources to the project classpath.
:resources-paths ["dev-resources"]
;; To instrument the project with the brepl facilities
;; (i.e. the ring/compojure/enlive libs) and the austin plugin
;; (cf. see below)
:dependencies [[ring "1.2.1"]
[compojure "1.1.6"]
[enlive "1.1.4"]]
;; The lib for cljs unit testing which is a maximal port of
;; clojure.test standard lib;
;; The lib for instrumenting the brepl
:plugins [[com.cemerick/clojurescript.test "0.2.1"]
[com.cemerick/austin "0.1.3"]]
;; Cljsbuild settings for development and test phases
:cljsbuild
{;; Here we configure one build for each compiler optmizations
;; options. We do not include the :none optimization.
:builds {;; The :whitespace optimizations build. This is the
;; only build included in the index.html page used
;; for the brepl connection
:whitespace
{:source-paths ["src/cljs" "test/cljs" "dev-resources/tools/repl"]
:compiler
{:output-to "dev-resources/public/js/hiccups.js"
:optimizations :whitespace
:pretty-print true}}
;; The :simple optimizations build
:simple
{:source-paths ["src/cljs" "test/cljs"]
:compiler
{:output-to "dev-resources/public/js/simple.js"
:optimizations :simple
:pretty-print false}}
;; The :advanced optimizations build
:advanced
{:source-paths ["src/cljs" "test/cljs"]
:compiler
{:output-to "dev-resources/public/js/advanced.js"
:optimizations :advanced
:pretty-print false}}}
;; Here we configure the test commands for running the
;; test. To be able to use this commands you have to install
;; phantomjs on you development machine. Phantomjs is the most
;; used webkit-based headless browser for unit testing JS code
:test-commands {;; test :whitespace build against phantomjs
"phantomjs-ws"
["phantomjs" :runner "dev-resources/public/js/hiccups.js"]
;; test :simple build against phantomjs
"phantomjs-simple"
["phantomjs" :runner "dev-resources/public/js/simple.js"]
;; test advanced build against phantomjs
"phantomjs-advanced"
["phantomjs" :runner "dev-resources/public/js/advanced.js"]}}
:injections [(require '[ring.server :as http :refer [run]]
'cemerick.austin.repls)
(defn browser-repl []
(cemerick.austin.repls/cljs-repl (reset! cemerick.austin.repls/browser-repl-env
(cemerick.austin/repl-env))))]}}
================================================
FILE: project.clj
================================================
(defproject hiccups "0.3.1"
:description "A ClojureScript port of Hiccup - a fast library for rendering HTML in ClojureScript"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo}
;; Required by cljsbuild plugin
:min-lein-version "2.2.0"
;; We need to add src/cljs too, because cljsbuild does not add its
;; source-paths to the project source-paths
:source-paths ["src/clj" "src/cljs"]
;; The libs which the project depends on.
;; Here we use the latest stable clj and cljs releases
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2069"]]
;; The plugins which the project depends on. Here we're using the
;; experimental 1.0.0-alpha2 release. Change it to the official
;; 1.0.0 as soon as it will be available
:plugins [[lein-cljsbuild "1.0.0"]]
;; Hooks the cljsbuild subtasks to the lein tasks: lein clean, lein
;; compile, lein test and lein jar
:hooks [leiningen.cljsbuild]
;; Lein-cljsbuild plugin configuration. Here we define one build
;; only: the one used for packaging any cljs sources in the jar
;; generated by lein jar command
:cljsbuild
{:builds {;; This build is only used for including any cljs source
;; in the packaged jar when you issue lein jar command and
;; any other command that depends on it
:useless
{;; The dir pathnames where cljs sources live. Do not
;; include here any cljs source which is only used during
;; development or testing
:source-paths ["src/cljs"]
;; The :jar true option is not needed to include the CLJS
;; sources in the packaged jar. This is because we added
;; the CLJS source codebase to the Leiningen
;; :source-paths
;:jar true
;; Compilation Options
:compiler
{;; The JS file pathname emitted by the compiler
:output-to "dev-resources/public/js/useless.js"
;; Compiler optimizations option set to :none to speed
;; up this useless compilation
:optimizations :none
;; No need to prettify the emitted js file
:pretty-print false}}}})
================================================
FILE: src/clj/hiccups/core.clj
================================================
(ns hiccups.core
"Library for rendering a tree of vectors into a string of HTML.
Pre-compiles where possible for performance.
Core macros and their (Clojure) helper functions."
(:require [hiccups.runtime :as rt])
(:import [clojure.lang IPersistentVector ISeq]))
(def doctype
{:html4
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "
"\"http://www.w3.org/TR/html4/strict.dtd\">\n")
:xhtml-strict
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")
:xhtml-transitional
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")
:html5
"<!DOCTYPE html>\n"})
(defn wrap-attrs
"Add an optional attribute argument to a function that returns a element vector."
[func]
(fn [& args]
(if (map? (first args))
(let [[tag & body] (apply func (rest args))]
(if (map? (first body))
(apply vector tag (merge (first body) (first args)) (rest body))
(apply vector tag (first args) body)))
(apply func args))))
(defn- update-arglists [arglists]
(for [args arglists]
(vec (cons 'attr-map? args))))
(defmacro defelem
"Defines a function that will return a element vector. If the first argument
passed to the resulting function is a map, it merges it with the attribute
map of the returned element value."
[name & fdecl]
`(do (defn ~name ~@fdecl)
(alter-meta! (var ~name) update-in [:arglists] #'update-arglists)
(alter-var-root (var ~name) wrap-attrs)))
(defelem xhtml-tag
"Create an XHTML element for the specified language."
[lang & contents]
[:html {:xmlns "http://www.w3.org/1999/xhtml"
"xml:lang" lang
:lang lang}
contents])
(defn xml-declaration
"Create a standard XML declaration for the following encoding."
[encoding]
(str "<?xml version=\"1.0\" encoding=\"" encoding "\"?>\n"))
(defmacro html4
"Create a HTML 4 document with the supplied contents. The first argument
may be an optional attribute map."
[& contents]
`(html {:mode :sgml}
~(doctype :html4)
[:html ~@contents]))
(defmacro xhtml
"Create a XHTML 1.0 strict document with the supplied contents. The first
argument may be an optional attribute may. The following attributes are
treated specially:
:lang - The language of the document
:encoding - The character encoding of the document, defaults to UTF-8."
[options & contents]
(if-not (map? options)
`(xhtml {} ~options ~@contents)
`(let [options# ~options]
(html {:mode :xml}
(xml-declaration (options# :encoding "UTF-8"))
~(doctype :xhtml-strict)
(xhtml-tag (options# :lang) ~@contents)))))
(defmacro html5
"Create a HTML5 document with the supplied contents."
[options & contents]
(if-not (map? options)
`(html5 {} ~options ~@contents)
(if (options :xml?)
`(let [options# (dissoc ~options :xml?)]
(html {:mode :xml}
(xml-declaration (options# :encoding "UTF-8"))
~(doctype :html5)
(xhtml-tag options# (options# :lang) ~@contents)))
`(let [options# (dissoc ~options :xml?)]
(html {:mode :html}
~(doctype :html5)
[:html options# ~@contents])))))
(defn- unevaluated?
"True if the expression has not been evaluated."
[expr]
(or (symbol? expr)
(and (seq? expr)
(not= (first expr) `quote))))
(defn- compile-attr-map
"Returns an unevaluated form that will render the supplied map as HTML
attributes."
[attrs]
(if (some unevaluated? (mapcat identity attrs))
`(hiccups.runtime/render-attr-map ~attrs)
(rt/render-attr-map attrs)))
(defn- form-name
"Get the name of the supplied form."
[form]
(if (and (seq? form) (symbol? (first form)))
(name (first form))))
(defmulti compile-form
"Pre-compile certain standard forms, where possible."
{:private true}
form-name)
(defmethod compile-form "for"
[[_ bindings body]]
`(cljs.core/apply cljs.core/str (cljs.core/for ~bindings (html ~body))))
(defmethod compile-form "if"
[[_ condition & body]]
`(if ~condition ~@(for [x body] `(html ~x))))
(defmethod compile-form :default
[expr]
`(hiccups.runtime/render-html ~expr))
(defn- literal?
"True if x is a literal value that can be rendered as-is."
[x]
(and (not (unevaluated? x))
(or (not (or (vector? x) (map? x)))
(every? literal? x))))
(defn- not-implicit-map?
"True if we can infer that x is not a map."
[x]
(or (= (form-name x) "for")
(not (unevaluated? x))))
(defn- element-compile-strategy
"Returns the compilation strategy to use for a given element."
[[tag attrs & content :as element]]
(cond
(every? literal? element)
::all-literal ; e.g. [:span "foo"]
(and (literal? tag) (map? attrs))
::literal-tag-and-attributes ; e.g. [:span {} x]
(and (literal? tag) (not-implicit-map? attrs))
::literal-tag-and-no-attributes ; e.g. [:span ^String x]
(literal? tag)
::literal-tag ; e.g. [:span x]
:else
::default)) ; e.g. [x]
(declare compile-html)
(defmulti compile-element
"Returns an unevaluated form that will render the supplied vector as a HTML
element."
{:private true}
element-compile-strategy)
(defmethod compile-element ::all-literal
[element]
(rt/render-element (eval element)))
(defmethod compile-element ::literal-tag-and-attributes
[[tag attrs & content]]
(let [[tag attrs _] (rt/normalize-element [tag attrs])]
(if (or content (rt/container-tags tag))
`(cljs.core/str ~(str "<" tag) ~(compile-attr-map attrs) ">"
~@(compile-html content)
~(str "</" tag ">"))
`(cljs.core/str "<" ~tag ~(compile-attr-map attrs) ~(rt/end-tag)))))
(defmethod compile-element ::literal-tag-and-no-attributes
[[tag & content]]
(compile-element (apply vector tag {} content)))
(defmethod compile-element ::literal-tag
[[tag attrs & content]]
(let [[tag tag-attrs _] (rt/normalize-element [tag])
attrs-sym (gensym "attrs")]
`(let [~attrs-sym ~attrs]
(if (map? ~attrs-sym)
~(if (or content (rt/container-tags tag))
`(cljs.core/str ~(str "<" tag)
(hiccups.runtime/render-attr-map (merge ~tag-attrs ~attrs-sym)) ">"
~@(compile-html content)
~(str "</" tag ">"))
`(cljs.core/str ~(str "<" tag)
(hiccups.runtime/render-attr-map (merge ~tag-attrs ~attrs-sym))
~(rt/end-tag)))
~(if (or attrs (rt/container-tags tag))
`(cljs.core/str ~(str "<" tag (rt/render-attr-map tag-attrs) ">")
~@(compile-html (cons attrs-sym content))
~(str "</" tag ">"))
(str "<" tag (rt/render-attr-map tag-attrs) (rt/end-tag)))))))
(defmethod compile-element :default
[element]
`(hiccups.runtime/render-element
[~(first element)
~@(for [x (rest element)]
(if (vector? x)
(compile-element x)
x))]))
(defn- compile-html
"Pre-compile data structures into HTML where possible"
[content]
(doall (for [expr content]
(cond
(vector? expr) (compile-element expr)
(literal? expr) expr
(seq? expr) (compile-form expr)
:else `(hiccups.runtime/render-html ~expr)))))
(defn- collapse-strs
"Collapse nested str expressions into one, where possible."
[expr]
(if (seq? expr)
(cons
(first expr)
(mapcat
#(if (and (seq? %) (symbol? (first %)) (= (first %) (first expr) `cljs.core/str))
(rest (collapse-strs %))
(list (collapse-strs %)))
(rest expr)))
expr))
(defmacro html
"Render Clojure data structures to a string of HTML."
[options & content]
(letfn [(make-html [content]
(collapse-strs `(cljs.core/str ~@(compile-html content))))]
(if-let [mode (and (map? options) (:mode options))]
(binding [rt/*html-mode* mode]
`(hiccups.runtime/in-mode ~mode
(fn [] ~(make-html content))))
(make-html (cons options content)))))
(defmacro defhtml
"Define a function, but wrap its output in an implicit html macro."
[name & fdecl]
(let [[fhead fbody] (split-with #(not (or (list? %) (vector? %))) fdecl)
wrap-html (fn [[args & body]] `(~args (html ~@body)))]
`(defn ~name
~@fhead
~@(if (vector? (first fbody))
(wrap-html fbody)
(map wrap-html fbody)))))
================================================
FILE: src/clj/hiccups/runtime.clj
================================================
(ns hiccups.runtime
(:require [clojure.string :as cstring]
[clojure.java.io :as io]))
(defn- read-all [rdr]
(loop [forms []]
(let [f (read rdr false :eof)]
(if (= :eof f)
forms
(recur (conj forms f))))))
; Read contents from the runtime .cljs file
; (a workaround for not being able to require a file with .cljs extensions in Clojure).
(with-open [rt (-> "hiccups/runtime.cljs" io/resource io/reader (java.io.PushbackReader.))]
(->> (rest (read-all rt))
(map eval)
dorun))
================================================
FILE: src/cljs/hiccups/runtime.cljs
================================================
(ns hiccups.runtime
(:require [clojure.string :as cstring]))
(def ^{:doc "Regular expression that parses a CSS-style id and class from a tag name." :private true}
re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
(def ^{:doc "Characters to replace when escaping HTML" :private true}
character-escapes {\& "&", \< "<", \> ">", \" """})
(def ^{:doc "A list of tags that need an explicit ending tag when rendered."}
container-tags
#{"a" "b" "body" "canvas" "dd" "div" "dl" "dt" "em" "fieldset" "form" "h1" "h2" "h3"
"h4" "h5" "h6" "head" "html" "i" "iframe" "label" "li" "ol" "option" "pre"
"script" "span" "strong" "style" "table" "textarea" "ul"})
(defn as-str [x]
(if (or (keyword? x) (symbol? x))
(name x)
(str x)))
(def ^:dynamic *html-mode* :xml)
(defn- xml-mode? []
(= *html-mode* :xml))
(defn in-mode [mode f]
(binding [*html-mode* mode]
(f)))
(defn escape-html
"Change special characters into HTML character entities."
[text]
(-> (as-str text)
(cstring/escape character-escapes)))
(def h escape-html) ; alias for escape-html
(defn end-tag []
(if (xml-mode?) " />" ">"))
(defn xml-attribute
([name value] (xml-attribute name value true))
([name value escape?]
(str " " (as-str name) "=\"" (if escape? (escape-html value) value) "\"")))
(declare render-attr-map)
(defn render-attribute [[name value]]
(cond
(true? value)
(if (xml-mode?)
(xml-attribute name name)
(str " " (as-str name)))
(not value)
""
:else
(xml-attribute name (if (map? value) (render-attr-map value) value) false)))
(defn render-attr-map [attrs]
(apply str
(sort (map render-attribute attrs))))
(defn normalize-element
"Ensure a tag vector is of the form [tag-name attrs content]."
[[tag & content]]
(when (not (or (keyword? tag) (symbol? tag) (string? tag)))
(throw (str tag " is not a valid tag name")))
(let [[_ tag id class] (re-matches re-tag (as-str tag))
tag-attrs {:id id
:class (if class (cstring/replace class "." " "))}
map-attrs (first content)]
(if (map? map-attrs)
[tag (merge tag-attrs map-attrs) (next content)]
[tag tag-attrs content])))
(declare render-html)
(defn render-element
"Render a tag vector as a HTML element."
[element]
(let [[tag attrs content] (normalize-element element)]
(if (or content (container-tags tag))
(str "<" tag (render-attr-map attrs) ">"
(render-html content)
"</" tag ">")
(str "<" tag (render-attr-map attrs) (end-tag)))))
(defn render-html
"Turn a Clojure data type into a string of HTML."
[x]
(cond
(vector? x) (render-element x)
(seq? x) (apply str (map render-html x))
:else (as-str x)))
================================================
FILE: test/cljs/hiccups/core_test.cljs
================================================
;;; This namespace is used for testing purpose. It use the
;;; clojurescript.test lib.
(ns hiccups.core-test
(:require-macros [cemerick.cljs.test :as m :refer (deftest is)]
[hiccups.core :as hiccups])
(:require [cemerick.cljs.test :as t]
[hiccups.runtime :as hiccupsrt]))
(deftest runtime-escaped-chars
(is (= (hiccupsrt/escape-html "\"") """))
(is (= (hiccupsrt/escape-html "<") "<"))
(is (= (hiccupsrt/escape-html ">") ">"))
(is (= (hiccupsrt/escape-html "&") "&"))
(is (= (hiccupsrt/escape-html "foo") "foo")))
(deftest tag-names
(is (= (hiccups/html [:div]) "<div></div>"))
(is (= (hiccups/html ["div"]) "<div></div>"))
(is (= (hiccups/html ['div]) "<div></div>"))
(is (= (hiccups/html [:div#foo]) "<div id=\"foo\"></div>"))
(is (= (hiccups/html [:form#sign-in]) "<form id=\"sign-in\"></form>"))
(is (= (hiccups/html [:input#sign-in-email]) "<input id=\"sign-in-email\" />"))
(is (= (hiccups/html [:div.foo]) "<div class=\"foo\"></div>"))
(is (= (hiccups/html [:div.foo (str "bar" "baz")])
"<div class=\"foo\">barbaz</div>"))
(is (= (hiccups/html [:div.a.b]) "<div class=\"a b\"></div>"))
(is (= (hiccups/html [:div.a.b.c]) "<div class=\"a b c\"></div>"))
(is (= (hiccups/html [:div#foo.bar.baz])
"<div class=\"bar baz\" id=\"foo\"></div>")))
(deftest tag-contents
; empty tags
(is (= (hiccups/html [:div]) "<div></div>"))
(is (= (hiccups/html [:h1]) "<h1></h1>"))
(is (= (hiccups/html [:script]) "<script></script>"))
(is (= (hiccups/html [:text]) "<text />"))
(is (= (hiccups/html [:a]) "<a></a>"))
(is (= (hiccups/html [:iframe]) "<iframe></iframe>"))
; tags containing text
(is (= (hiccups/html [:text "Lorem Ipsum"]) "<text>Lorem Ipsum</text>"))
; contents are concatenated
(is (= (hiccups/html [:body "foo" "bar"]) "<body>foobar</body>"))
(is (= (hiccups/html [:body [:p] [:br]]) "<body><p /><br /></body>"))
; seqs are expanded
(is (= (hiccups/html [:body (list "foo" "bar")]) "<body>foobar</body>"))
(is (= (hiccups/html (list [:p "a"] [:p "b"])) "<p>a</p><p>b</p>"))
; tags can contain tags
(is (= (hiccups/html [:div [:p]]) "<div><p /></div>"))
(is (= (hiccups/html [:div [:b]]) "<div><b></b></div>"))
(is (= (hiccups/html [:p [:span [:a "foo"]]])
"<p><span><a>foo</a></span></p>")))
(deftest tag-attributes
; tag with blank attribute map
(is (= (hiccups/html [:xml {}]) "<xml />"))
; tag with populated attribute map
(is (= (hiccups/html [:xml {:a "1", :b "2"}]) "<xml a=\"1\" b=\"2\" />"))
(is (= (hiccups/html [:img {"id" "foo"}]) "<img id=\"foo\" />"))
(is (= (hiccups/html [:img {'id "foo"}]) "<img id=\"foo\" />"))
(is (= (hiccups/html [:xml {:a "1", 'b "2", "c" "3"}])
"<xml a=\"1\" b=\"2\" c=\"3\" />"))
; attribute values are escaped
(is (= (hiccups/html [:div {:id "\""}]) "<div id=\""\"></div>"))
; boolean attributes
(is (= (hiccups/html [:input {:type "checkbox" :checked true}])
"<input checked=\"checked\" type=\"checkbox\" />"))
(is (= (hiccups/html [:input {:type "checkbox" :checked false}])
"<input type=\"checkbox\" />"))
; nil attributes
(is (= (hiccups/html [:span {:class nil} "foo"])
"<span>foo</span>")))
(deftest compiled-tags
; tag content can be vars
(is (= (let [x "foo"] (hiccups/html [:span x])) "<span>foo</span>"))
; tag content can be forms
(is (= (hiccups/html [:span (str (+ 1 1))]) "<span>2</span>"))
(is (= (hiccups/html [:span ({:foo "bar"} :foo)]) "<span>bar</span>"))
; attributes can contain vars
(let [x "foo"]
(is (= (hiccups/html [:xml {:x x}]) "<xml x=\"foo\" />"))
(is (= (hiccups/html [:xml {x "x"}]) "<xml foo=\"x\" />"))
(is (= (hiccups/html [:xml {:x x} "bar"]) "<xml x=\"foo\">bar</xml>")))
; attributes are evaluated
(is (= (hiccups/html [:img {:src (str "/foo" "/bar")}])
"<img src=\"/foo/bar\" />"))
(is (= (hiccups/html [:div {:id (str "a" "b")} (str "foo")])
"<div id=\"ab\">foo</div>"))
; optimized forms
(is (= (hiccups/html [:ul (for [n (range 3)]
[:li n])])
"<ul><li>0</li><li>1</li><li>2</li></ul>"))
(is (= (hiccups/html [:div (if true
[:span "foo"]
[:span "bar"])])
"<div><span>foo</span></div>"))
; values are evaluated only once
(let [times-called (atom 0)
foo #(do (swap! times-called inc) "foo")]
(hiccups/html [:div (foo)])
(is (= 1 @times-called))))
(deftest defhtml-macro
; basic html function
(hiccups/defhtml basic-fn [x] [:span x])
(is (= (basic-fn "foo") "<span>foo</span>"))
; html function with overloads
(hiccups/defhtml overloaded-fn
([x] [:span x])
([x y] [:span x [:div y]]))
(is (= (overloaded-fn "foo") "<span>foo</span>"))
(is (= (overloaded-fn "foo" "bar")
"<span>foo<div>bar</div></span>")))
(deftest render-modes
; "closed tag"
(is (= (hiccups/html [:br]) "<br />"))
(is (= (hiccups/html {:mode :xml} [:br]) "<br />"))
(is (= (hiccups/html {:mode :sgml} [:br]) "<br>"))
(is (= (hiccups/html {:mode :html} [:br]) "<br>"))
; boolean attributes
(is (= (hiccups/html {:mode :xml} [:input {:type "checkbox" :checked true}])
"<input checked=\"checked\" type=\"checkbox\" />"))
(is (= (hiccups/html {:mode :sgml} [:input {:type "checkbox" :checked true}])
"<input checked type=\"checkbox\">"))
; "laziness and binding scope"
(is (= (hiccups/html {:mode :sgml} [:html [:link] (list [:link])])
"<html><link><link></html>")))
gitextract_9f1bfi2j/
├── .gitignore
├── LICENSE.html
├── README.md
├── build.boot
├── dev-resources/
│ ├── public/
│ │ └── index.html
│ └── tools/
│ ├── http/
│ │ └── ring/
│ │ └── server.clj
│ └── repl/
│ └── brepl/
│ └── connect.cljs
├── profiles.clj
├── project.clj
├── src/
│ ├── clj/
│ │ └── hiccups/
│ │ ├── core.clj
│ │ └── runtime.clj
│ └── cljs/
│ └── hiccups/
│ └── runtime.cljs
└── test/
└── cljs/
└── hiccups/
└── core_test.cljs
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (48K chars).
[
{
"path": ".gitignore",
"chars": 173,
"preview": "*.jar\nresources/private/js/*\nclasses/\nout/\ntarget/\npom.xml\n.lein*\n.repl\n/classes\n/checkouts\npom.xml.asc\n*.class\n/.lein-*"
},
{
"path": "LICENSE.html",
"chars": 12917,
"preview": "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www"
},
{
"path": "README.md",
"chars": 3771,
"preview": "Hiccups\n=======\n\nHiccups is a ClojureScript port of the [Hiccup](https://github.com/weavejester/hiccup) HTML generation "
},
{
"path": "build.boot",
"chars": 1840,
"preview": "(def project 'hiccups)\n(def version \"0.3.1\")\n\n(set-env! :resource-paths #{\"resources\" \"src/cljs\" \"src/clj\"}\n :s"
},
{
"path": "dev-resources/public/index.html",
"chars": 357,
"preview": "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>bREPL Connection</title>\n <!--[if lt IE"
},
{
"path": "dev-resources/tools/http/ring/server.clj",
"chars": 1233,
"preview": ";;; This namespace is used for development and testing purpose only.\n(ns ring.server\n (:require [cemerick.austin.repls "
},
{
"path": "dev-resources/tools/repl/brepl/connect.cljs",
"chars": 268,
"preview": ";;; This namespace is for creating the connection with the browser. It\n;;; lives in the dev-resources/tools/brepl direct"
},
{
"path": "profiles.clj",
"chars": 4696,
"preview": ";;; ****************************** NOTES ******************************\n;;;\n;;; The hiccups/profiles.clj file is used fo"
},
{
"path": "project.clj",
"chars": 2380,
"preview": "(defproject hiccups \"0.3.1\"\n :description \"A ClojureScript port of Hiccup - a fast library for rendering HTML in Clojur"
},
{
"path": "src/clj/hiccups/core.clj",
"chars": 8802,
"preview": "(ns hiccups.core\n \"Library for rendering a tree of vectors into a string of HTML.\n Pre-compiles where possible for pe"
},
{
"path": "src/clj/hiccups/runtime.clj",
"chars": 549,
"preview": "(ns hiccups.runtime\n (:require [clojure.string :as cstring]\n [clojure.java.io :as io]))\n\n(defn- read-all [rd"
},
{
"path": "src/cljs/hiccups/runtime.cljs",
"chars": 2813,
"preview": "(ns hiccups.runtime\n (:require [clojure.string :as cstring]))\n\n(def ^{:doc \"Regular expression that parses a CSS-style "
},
{
"path": "test/cljs/hiccups/core_test.cljs",
"chars": 5642,
"preview": ";;; This namespace is used for testing purpose. It use the\n;;; clojurescript.test lib.\n(ns hiccups.core-test\n (:require"
}
]
About this extraction
This page contains the full source code of the teropa/hiccups GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (44.4 KB), approximately 12.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.