Permalink
Browse files

readme and example

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent b6289b3 commit aa76706e0bd4ef40d94ff81ee23b2f508183f39c @ibdknox committed Aug 7, 2011
Showing with 75 additions and 1 deletion.
  1. +34 −0 README.md
  2. +41 −1 src/todo/core.cljs
View
@@ -0,0 +1,34 @@
+### Pinot is still very alpha symbol names and are still likely to change
+
+##Pinot
+Pinot is a ClojureScript client-side framework designed to make it easy to write your websites completely in Clojure.
+
+Currently Pinot provides a wrapper over several DOM interaction points in the goog.\* libraries. It also provides an implementation of [Hiccup](https://github.com/weavejester/hiccup) that translates directly into DOM objects instead of a string of HTML.
+
+For an example look at the src/todos/core.cljs
+
+##Usage
+From any leiningen project file:
+
+```clojure
+[pinot "0.1.0-SNAPSHOT"]
+```
+Then make sure you have your lib folder on your classpath.
+
+## Docs
+* Coming soon...
+
+Checkout src/todos/core.cljs as an example.
+
+## Roadmap
+
+* more DOM manipulation
+* finish events
+* MVC replacement (something like the Clojure version of backbone).
+
+## License
+
+Copyright (C) 2011 Chris Granger
+
+Distributed under the Eclipse Public License, the same as Clojure.
+
View
@@ -1,8 +1,48 @@
-(ns todos.core
+(ns todo.core
(:require [pinot.html :as ph]
[pinot.html.tags :as tags]
[pinot.validation :as vali]
[pinot.events :as pe])
(:require-macros [pinot.macros :as pm]))
+(def todos (atom {1 "Get milk"
+ 2 "Pay bills"
+ 3 "Do stuff"}))
+(defn add-todo [text]
+ (let [neue-key (inc (apply max (keys @todos)))]
+ (swap! todos assoc neue-key text)
+ [neue-key text]))
+
+(defn remove-todo [id]
+ (swap! todos dissoc id))
+
+(pm/defpartial todo-item [[id item]]
+ [:li (tags/link-to {:class "remove" :id id} "#" item)])
+
+(pm/defpartial todo-form []
+ (tags/form-to {:id "todoForm"} [:post "/todos"]
+ (tags/label "todoText" "Todo: ")
+ (tags/text-field "todoText")
+ (tags/submit-button {:class "submit"} "add todo")))
+
+(ph/append-to (ph/dom-find "body")
+ (ph/html
+ [:div
+ (todo-form)
+ [:ul
+ (map todo-item @todos)]]))
+
+(pe/on (ph/dom-find "#todoForm") :submit
+ (fn [me e]
+ (let [text (ph/val (ph/dom-find "#todoText"))
+ neue (add-todo text)]
+ (ph/append-to (ph/dom-find "ul") (todo-item neue))
+ (pe/prevent e))))
+
+(pe/on (ph/dom-find "a.remove") :click
+ (fn [me e]
+ (let [id (ph/attr me :id)]
+ (remove-todo id)
+ (ph/unappend me)
+ (pe/prevent e))))

0 comments on commit aa76706

Please sign in to comment.