Browse files

working on storing session state within clojure session.

  • Loading branch information...
1 parent 83dec90 commit 9862ba678937974fe9ec36fefc3a049dd8875fbc @ekoontz committed Feb 7, 2011
Showing with 22 additions and 11 deletions.
  1. +15 −6 src/index.clj
  2. +5 −5 src/quiz.clj
  3. +2 −0 src/table.clj
@@ -11,7 +11,7 @@
;; strings
- company-name* "Verbi Italiani by Eugene Koontz"
+ company-name* " presents Verbi Italiani"
app-name* "Verbi Italiani"
;; colors
@@ -60,13 +60,14 @@
(button subscribe-id* "Subscribe!" important-color*))
(slice header [text & [id]]
- (html [:h1 {:id (wo# id)} text]))
+ (title "Verbi Italiani")
+ (html [:h1 {:id (wo# id)} text]))
(defn navigation []
- [:div [:a {:href "/"} "top"]]
- [:div [:a {:href "/quiz/"} "take a quiz..."]]
- [:div [:a {:href ""} "source code"]]
+ [:div {:style "float:left;width:auto;padding:10px;"} [:a {:href "/"} "top"]]
+ [:div {:style "float:left;width:auto;padding:10px;"} [:a {:href "/quiz/"} "take a quiz..."]]
+ [:div {:style "float:left;width:auto;padding:10px;"} [:a {:href ""} "source code"]]
(slice site-header
@@ -94,10 +95,18 @@
(load-file "src/quiz.clj")
+(def sessions (hash-map))
+(def sessions (assoc sessions 'reqid 0))
+(slice update-state
+ (let [update (def sessions (assoc sessions 'reqid (+ 1 (get sessions 'reqid))))]
+ (html [:div {:style "float:left;border:1px dashed green"} (str "request_id: " (get sessions 'reqid))])))
(defroutes app
(GET "/" _ (main-page))
(GET "/subscribe" _ (slices site-header subscribe-button))
- (GET "/quiz*" _ (slices site-header quiz))
+ (GET "/quiz*" _ (slices site-header quiz update-state))
(GET "/test" r (slices jquery
(dom (alert ~(:remote-addr r)))
(html [:h1 "Hi"])
@@ -1,33 +1,33 @@
(ns italianverbs)
(defn wrapchoice [word]
+ ;; FIXME: url-encode word.
(let [href_prefix "/quiz?"]
(html [:h3 [:a {:href (str href_prefix "guess=" word)} word]])))
(defn guess ^{:impure true} [lexicon remaining answer show-true-at]
(if (= remaining show-true-at)
- (wrapchoice answer))
+ (wrapchoice (str answer "(true)")))
(if (> remaining 0)
(let [choice (rand-int (count lexicon))]
- (html (wrapchoice (get lexicon (nth (keys lexicon) choice)))
+ (html (wrapchoice (str (get lexicon (nth (keys lexicon) choice))))
(guess (dissoc lexicon (nth (keys lexicon) choice)) (- remaining 1) answer show-true-at))))))
(defn guesses ^{:impure true} [question answer lexicon true-index]
(let [multiple-choices 3]
;; 4 choices; show true answer at a random position amongst the false ones.
;; TODO: remove true answer from lexicon in (guess) call.
- (guess (dissoc lexicon question) multiple-choices answer (rand-int multiple-choices)))))
+ (guess (dissoc lexicon question) multiple-choices answer (rand-int (+ 1 multiple-choices))))))
(slice next-question [index]
- (html [:div [:h2 [:i (nth (keys lexicon) index)]]
+ (html [:div {:style "width:100%;float:left;border:0px dashed blue"} [:h2 [:i (nth (keys lexicon) index)]]
[:div {:style "padding-left:1em"}
(guesses (nth (keys lexicon) index)
(get lexicon (nth (keys lexicon) index))
lexicon index)]]))
(slice quiz ^{:impure true} []
(next-question (rand-int (count lexicon))))
@@ -17,7 +17,9 @@
(add-verb "scrivere" "to write")
(add-verb "correggere" "to correct")
(add-verb "leggere" "to read")
+(add-verb "mangiere" "to eat")
(add-verb "parlere" "to speak")
+(add-verb "pranzare" "to eat lunch")
(slice verb-table
(html [:table

0 comments on commit 9862ba6

Please sign in to comment.