Permalink
Browse files

initial commit using slice's example.clj

  • Loading branch information...
1 parent 5b5ffb7 commit d91c73a19ea6dd00983f1924b4f85de5988b38c6 @ekoontz committed Feb 6, 2011
Showing with 100 additions and 2 deletions.
  1. +2 −1 README
  2. +3 −1 project.clj
  3. +95 −0 src/italianverbs/example.clj
View
3 README
@@ -1,4 +1,5 @@
-# italianverbs
+# Italianverbs flashcards by Eugene Koontz <ekoontz@hiro-tan.org>
+# using the Slice Clojure framework
FIXME: write description
View
@@ -5,4 +5,6 @@
[slice "0.4.0-SNAPSHOT"]
[org.apache.lucene/lucene-core "3.0.2"]
[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]])
+ [org.clojure/clojure-contrib "1.2.0"]
+ [compojure "0.6.0-RC3"]
+ [net.defn.ring/ring-jetty-adapter "0.2.0"]])
@@ -0,0 +1,95 @@
+(ns slice.example
+ (:use slice.core
+ slice.compojure5 ; make slices render automatically
+ uteal.core ; defs FTW
+ compojure.core ; slice isn't tied to a web "framework"
+ ring.adapter.jetty
+ hiccup.form-helpers))
+
+;; when deploying use
+;; (slice-memoize! true)
+
+(defs
+ ;; strings
+ company-name* "Cool Company"
+ app-name* "Awesome App"
+
+ ;; colors
+ site-color* "blue"
+ important-color* "red"
+
+ ;; ids
+ logo-id* "#logo"
+ download-id* "#download"
+ subscribe-id* "#subscribe"
+
+ ;; classes
+ buttons* "button"
+
+ ;; mixins
+ rounded-corners* (list :-moz-border-radius :5px
+ :-webkit-border-radius :5px)
+ big-text* (list :font-size "300%")
+ special-button* (list rounded-corners* big-text*))
+
+(slice awesome-effect
+ jquery
+ (js (fn awesomeEffect [div]
+ (.fadeOut ($ div))
+ (.fadeIn ($ div)))))
+
+(slice mouse-effect [id]
+ awesome-effect
+ (dom (.mouseover ($ ~id) (fn [] (awesomeEffect ~id)))))
+
+(slice button [id text color]
+ (html (submit-button {:id (wo# id) :class buttons*} text))
+ (css [(wdot buttons*) rounded-corners* :color color]))
+
+(slice on-click-alert [id msg]
+ (dom (.click ($ ~id) (fn [] (alert ~msg)))))
+
+(slice download-button
+ (on-click-alert download-id* "Ain't slices cool?")
+ (css [download-id* special-button*])
+ (button download-id* "Download!" important-color*))
+
+(slice subscribe-button
+ jquery
+ (on-click-alert subscribe-id* (str "Subscribed to " company-name* " newsletter."))
+ (button subscribe-id* "Subscribe!" important-color*))
+
+(slice header [text & [id]]
+ (html [:h1 {:id (wo# id)} text]))
+
+(slice site-header
+ (mouse-effect logo-id*)
+ (header company-name* logo-id*)
+ (css [logo-id*
+ big-text*
+ :color site-color*]))
+
+;;; impure slices and slices that use impure slices aren't memoized
+(slice ^{:impure true} random-number
+ (html [:p (rand-int 100)]))
+
+(slice app-section
+ (header app-name*)
+ download-button)
+
+(slice main-page
+ (title company-name*)
+ site-header
+ subscribe-button
+ app-section
+ random-number)
+
+(defroutes app
+ (GET "/" _ (main-page))
+ (GET "/subscribe" _ (slices site-header subscribe-button))
+ (GET "/test" r (slices jquery
+ (dom (alert ~(:remote-addr r)))
+ (html [:h1 "Hi"])
+ (css [:h1 :color "blue"]))))
+
+(defonce server (run-jetty #'app {:port 8888 :join? false}))

0 comments on commit d91c73a

Please sign in to comment.