diff --git a/src/index.clj b/src/index.clj index ec15f01..1f6e2c6 100644 --- a/src/index.clj +++ b/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"]) diff --git a/src/quiz.clj b/src/quiz.clj index d50235c..3ee8642 100644 --- a/src/quiz.clj +++ b/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)))) diff --git a/src/table.clj b/src/table.clj index 6c0da24..0948404 100644 --- a/src/table.clj +++ b/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