about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pronouns/config.clj5
-rw-r--r--src/pronouns/pages.clj21
-rw-r--r--src/pronouns/util.clj13
-rw-r--r--src/pronouns/web.clj19
4 files changed, 31 insertions, 27 deletions
diff --git a/src/pronouns/config.clj b/src/pronouns/config.clj
new file mode 100644
index 0000000..fdb4c97
--- /dev/null
+++ b/src/pronouns/config.clj
@@ -0,0 +1,5 @@
+(ns pronouns.config
+  (:require [pronouns.util :as u]))
+
+(def ^:dynamic *pronouns-table*
+  (u/slurp-tabfile "resources/pronouns.tab"))
diff --git a/src/pronouns/pages.clj b/src/pronouns/pages.clj
index bf67f75..708d912 100644
--- a/src/pronouns/pages.clj
+++ b/src/pronouns/pages.clj
@@ -1,5 +1,6 @@
 (ns pronouns.pages
   (:require [clojure.string :as s]
+            [pronouns.config :refer [*pronouns-table*]]
             [pronouns.util :as u]
             [hiccup.core :refer :all]
             [hiccup.util :refer [escape-html]]))
@@ -89,20 +90,22 @@
        (about-block)
        (contact-block)]])))
 
-(defn lookup-pronouns [pronouns-string pronouns-table]
+(defn lookup-pronouns [pronouns-string]
   (let [inputs (s/split pronouns-string #"/")
         n (count inputs)]
+    (println *pronouns-table*)
     (if (>= n 5)
       (take 5 inputs)
-      (u/table-lookup inputs pronouns-table))))
+      (u/table-lookup inputs *pronouns-table*))))
 
 (defn make-link [path]
   (let [link (str "/" path)
         label path]
     [:li [:a {:href link} label]]))
 
-(defn front [pronouns-table]
-  (let [abbreviations (u/abbreviate pronouns-table)
+(defn front []
+  (let [blah (println *pronouns-table*)
+        abbreviations (u/abbreviate *pronouns-table*)
         links (map make-link abbreviations)
         title "Pronoun Island"]
     (html
@@ -135,15 +138,13 @@
        (about-block)
        (contact-block)]])))
 
-(defn pronouns [params pronouns-table]
+(defn pronouns [params]
   (let [path (params :*)
         alts (or (params "or") [])
         pronouns (concat [path] (u/vec-coerce alts))
-        pronoun-declensions (filter some? (map #(lookup-pronouns (escape-html %)
-                                                                pronouns-table)
-                                              pronouns))]
-    (println path)
-    (println pronoun-declensions)
+        pronoun-declensions (filter some? (map #(lookup-pronouns
+                                                 (escape-html %))
+                                               pronouns))]
     (if (seq pronoun-declensions)
       (format-pronoun-examples pronoun-declensions)
       (not-found))))
diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj
index 3a4bf10..ef353a8 100644
--- a/src/pronouns/util.clj
+++ b/src/pronouns/util.clj
@@ -16,19 +16,20 @@
   (table-lookup query-key (slurp-tabfile tabfile)))
 
 (defn minimum-unambiguous-path
-  ([pronouns-table sections] (minimum-unambiguous-path pronouns-table sections 1))
-  ([pronouns-table sections number-of-sections]
+  ([table sections] (minimum-unambiguous-path table sections 1))
+  ([table sections number-of-sections]
     (let [sections-subset (take number-of-sections sections)
-          results (filter #(= (take number-of-sections %) sections-subset) pronouns-table)]
+          results (filter #(= (take number-of-sections %) sections-subset)
+                          table)]
       (case (count results)
         0 nil
         1 (clojure.string/join "/" sections-subset)
-        (recur pronouns-table sections (+ number-of-sections 1))))))
+        (recur table sections (+ number-of-sections 1))))))
 
 (defn abbreviate
   "given a list of pronoun rows, return a list of minimum unabiguous paths"
-  [pronouns-table]
-  (map (partial minimum-unambiguous-path pronouns-table) pronouns-table))
+  [table]
+  (map (partial minimum-unambiguous-path table) table))
 
 (defn vec-coerce [x]
   (if (vector? x) x [x]))
diff --git a/src/pronouns/web.clj b/src/pronouns/web.clj
index cb5e6c9..9219369 100644
--- a/src/pronouns/web.clj
+++ b/src/pronouns/web.clj
@@ -12,15 +12,11 @@
             [pronouns.util :as u]
             [pronouns.pages :as pages]))
 
-(def config {:default-server-port 5000
-             :pronoun-table-path "resources/pronouns.tab"})
-(def pronouns-table (u/slurp-tabfile (:pronoun-table-path config)))
-
 (defroutes app-routes
   (GET "/" []
        {:status 200
         :headers {"Content-Type" "text/html"}
-        :body (pages/front pronouns-table)})
+        :body (pages/front)})
 
   (GET "/pronouns.css" []
      {:status 200
@@ -30,7 +26,7 @@
   (GET "/*" {params :params}
        {:status 200
         :headers {"Content-Type" "text/html"}
-        :body (pages/pronouns params pronouns-table)})
+        :body (pages/pronouns params)})
 
   (ANY "*" []
        (route/not-found (slurp (io/resource "404.html")))))
@@ -39,9 +35,11 @@
   (fn [req]
     (try (handler req)
          (catch Exception e
-           {:status 500
-            :headers {"Content-Type" "text/html"}
-            :body (slurp (io/resource "500.html"))}))))
+           (binding [*out* *err*]
+             (println e)
+             {:status 500
+              :headers {"Content-Type" "text/html"}
+              :body (slurp (io/resource "500.html"))})))))
 
 (def app
   (-> app-routes
@@ -51,8 +49,7 @@
       params/wrap-params))
 
 (defn -main []
-  (let [port (Integer. (:port env
-                              (:default-server-port config)))]
+  (let [port (Integer. (:port env))]
     (jetty/run-jetty app {:port port})))
 
 ;; For interactive development: