Skip to content

Instantly share code, notes, and snippets.

@pandeiro pandeiro/
Last active Aug 29, 2015

What would you like to do?
Example of a simple webapp written as a single file


  1. Get Boot
  2. Copy the above file to $HOME/app.boot
  3. $ chmod a+x $HOME/app.boot
  4. $ cd && ./app.boot
#!/usr/bin/env boot
(print "Loading dependencies... ")
(set-env! :dependencies '[[pandeiro/agua "0.1.0"]])
(require '[agua.core :refer [defhtml defcss defcljs serve]])
(println "done.")
;; HTML page: expects three %s for css, prerendered html and js
(defhtml page
[:meta {:charset "utf-8"}]
[:title "My App"]
[:style "%s"]]
[:div#root "%s"]
[:footer "Copyright 2015 you"]
[:script "%s"]])
;; CSS
(defcss styles
{:box-sizing "border-box"}]
{:padding "36px"
:background "black"
:color "lightgray"
:text-align "center"}]
{:color "white"}]
{:font-size "24px"
:background "rgb(20,20,20)"
:border "solid 1px white"
:font-style "italic"
:padding "12px"
:color "rgb(150,150,150)"
:border-radius "8px"}]
{:position "fixed"
:bottom 0
:left 0
:width "100%"
:padding "8px"
:font-family "monospace"}])
;; ClojureScript
(defcljs app
(ns app.core
(:require [reagent.core :as r]))
(def state
{:person "person"}))
(defn- person-val [e]
(or (not-empty (.-value (.-target e))) "person"))
(defn main [state]
[:h1 (str "Hello, " (:person @state))]
(when js/document
{:placeholder "Name, please"
:on-change #(swap! state assoc :person (person-val %))}])])
(defn not-found []
[:h1 (str "404: '" js/location.pathname "' wasn't found.")]])
(defn router []
(condp re-find js/location.pathname
#"^/$" [main state]
(if js/document
(r/render [router] (.getElementById js/document "root"))
(r/render-to-string [router])))
(defn -main [& args]
(serve {:html page, :css styles, :app app}))

This comment has been minimized.

Copy link

ccfontes commented Feb 10, 2015

This is so sexy 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.