Enfocus is a dom manipulation library for ClojureScript. Originally inspired by Christophe Grand's clojure based Enlive, it has evolved into a cross browser tool for building rich UIs.
It supports all of the Enlive-based transformations along with many more transformations geared towards managing live dom features, such as events and effects. The best way to understand what this library can do is to look at code. The Quick Start page of this site is controlled by the following code.
(ns enfocus.demo.site (:require [enfocus.core :as ef] [enfocus.effects :as effects] [enfocus.events :as ev]) (:require-macros [enfocus.macros :as em])) (em/deftemplate gstarted "templates/getting-started.html" []) (defn clone-for-demo [] (let [fruit-data {"apple" 5, "pear" 6}] (ef/at "#clone-for-demo tbody > tr:first-child" (em/clone-for [fr (vec fruit-data)] "*:first-child" (ef/content (first fr)) "*:last-child" (ef/content (str (second fr))))))) (defn read-form-demo [] (let [values (ef/from "#read-form-test" (ef/read-form))] (ef/at "#read-form-demo" (ef/content (pr-str values))))) (em/defaction gstarted-page [] "#content-pane" (ef/do-> (ef/content (gstarted)) (reset-scroll)) "#button1" (ev/listen :click #(ef/at (.-currentTarget %) (ef/content "I have been clicked"))) "#button2" (ev/listen :click #(ef/at "#rz-demo" (effects/chain (effects/resize 200 :curheight 500) (effects/resize 5 :curheight 500)))) "#button3" (ev/listen :click clone-for-demo) "#button4" (ev/listen :click read-form-demo))
In this small piece of code we can see many of key features of enfocus: content manipulation, style manipulation, remote resources, complex effects, event handling and management of timed or synchronized events. All this, and we have only seen 35 lines of code!
You will find instructions for contributing to either the Enfocus main project or the Enfocus demo site project at the following links:
Copyright (C) 2013 Creighton Kirkendall
Distributed under the Eclipse Public License, the same as Clojure.