Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

working on storing session state within clojure session.

  • Loading branch information...
commit 9862ba678937974fe9ec36fefc3a049dd8875fbc 1 parent 83dec90
@ekoontz authored
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
View
21 src/index.clj
@@ -11,7 +11,7 @@
(defs
;; strings
- company-name* "Verbi Italiani by Eugene Koontz"
+ company-name* "foofers.org 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 []
(html
- [:div [:a {:href "/"} "top"]]
- [:div [:a {:href "/quiz/"} "take a quiz..."]]
- [:div [:a {:href "http://github.com/ekoontz/italianverbs"} "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 "http://github.com/ekoontz/italianverbs"} "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"])
View
10 src/quiz.clj
@@ -1,16 +1,17 @@
(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]
(html
(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]
@@ -18,16 +19,15 @@
(html
;; 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))))
View
2  src/table.clj
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.