about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/pronouns/pages.clj64
-rw-r--r--src/pronouns/util.clj12
-rw-r--r--src/pronouns/web.clj6
3 files changed, 44 insertions, 38 deletions
diff --git a/src/pronouns/pages.clj b/src/pronouns/pages.clj
index 7d68422..bdcd9d6 100644
--- a/src/pronouns/pages.clj
+++ b/src/pronouns/pages.clj
@@ -61,33 +61,33 @@
 
 (defn contact-block []
   (let [twitter-name (fn [handle] [:a {:href (str "https://www.twitter.com/" handle)} (str "@" handle)])]
-   [:div {:class "contact"}
-    [:p
-     "Written by "
-     (twitter-name "morganastra")
-     ", whose "
-     [:a {:href "http://pronoun.is/ze/zir"} "pronoun.is/ze/zir"]
-     ". "
-     "Visit the project on " [:a {:href "https://github.com/witch-house/pronoun.is"} "github!"]]]))
+  [:div {:class "contact"}
+   [:p
+    "Written by "
+    (twitter-name "morganastra")
+    ", whose "
+    [:a {:href "http://pronoun.is/ze/zir"} "pronoun.is/ze/zir"]
+    ". "
+   "Visit the project on " [:a {:href "https://github.com/witch-house/pronoun.is"} "github!"]]]))
 
 
 (defn format-pronoun-examples
   [subject object possessive-determiner possessive-pronoun reflexive]
   (let [title "Pronoun Island: English Language Examples"]
-   (html
-    [:html
-     [:head
-      [:title title]
-      [:meta {:name "viewport" :content "width=device-width"}]
-      [:link {:rel "stylesheet" :href "/pronouns.css"}]]
-     [:body
-      (title-block title)
-      (examples-block subject object possessive-determiner possessive-pronoun reflexive)
-      (about-block)
-      (contact-block)]])))
-
-
-(defn format-pronoun-json [pronouns]
+  (html
+   [:html
+    [:head
+     [:title title]
+     [:meta {:name "viewport" :content "width=device-width"}]
+     [:link {:rel "stylesheet" :href "/pronouns.css"}]]
+    [:body
+     (title-block title)
+     (examples-block subject object possessive-determiner possessive-pronoun reflexive)
+     (about-block)
+     (contact-block)]])))
+
+
+(defn format-pronoun-json [& pronouns]
   (json/write-str pronouns))
 
 
@@ -116,9 +116,9 @@
       [:body
        (title-block title)
        [:div {:class "table"}
-        [:p "pronoun.is is a www site for showing people how to use pronouns in English."]
-        [:p "here are some pronouns the site knows about:"]
-        [:ul links]]]
+       [:p "pronoun.is is a www site for showing people how to use pronouns in English."]
+       [:p "here are some pronouns the site knows about:"]
+       [:ul links]]]
       (contact-block)])))
 
 (defn not-found []
@@ -126,10 +126,16 @@
        "add them, or issue a pull request at "
        "https://github.com/witch-house/pronoun.is/blob/master/resources/pronouns.tab"))
 
-(defn pronouns [path pronouns-table accept]
+(defn not-found-json []
+  (json/write-str {:error "Not found"}))
+
+(defn pronouns-page [path pronouns-table format-pronouns not-found]
   (let [pronouns (parse-pronouns-with-lookup (escape-html path) pronouns-table)]
     (if pronouns
-      (if (= accept :json)
-        (format-pronoun-json pronouns)
-        (apply format-pronoun-examples pronouns))
+      (apply format-pronouns pronouns)
       (not-found))))
+
+(defn pronouns [path pronouns-table accept]
+  (if (= accept :json)
+    (pronouns-page path pronouns-table format-pronoun-json not-found-json)
+    (pronouns-page path pronouns-table format-pronoun-examples not-found)))
diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj
index 51e8403..4d4f928 100644
--- a/src/pronouns/util.clj
+++ b/src/pronouns/util.clj
@@ -18,12 +18,12 @@
 (defn minimum-unambiguous-path
   ([pronouns-table sections] (minimum-unambiguous-path pronouns-table sections 1))
   ([pronouns-table sections number-of-sections]
-   (let [sections-subset (take number-of-sections sections)
-         results (filter #(= (take number-of-sections %) sections-subset) pronouns-table)]
-     (case (count results)
-       0 nil
-       1 (clojure.string/join "/" sections-subset)
-       (recur pronouns-table sections (+ number-of-sections 1))))))
+    (let [sections-subset (take number-of-sections sections)
+          results (filter #(= (take number-of-sections %) sections-subset) pronouns-table)]
+      (case (count results)
+        0 nil
+        1 (clojure.string/join "/" sections-subset)
+        (recur pronouns-table sections (+ number-of-sections 1))))))
 
 (defn abbreviate
   "given a list of pronoun rows, return a list of minimum unabiguous paths"
diff --git a/src/pronouns/web.clj b/src/pronouns/web.clj
index 4ec1788..bf717eb 100644
--- a/src/pronouns/web.clj
+++ b/src/pronouns/web.clj
@@ -25,11 +25,11 @@
 
   (GET "/pronouns.css" {params :params}
      {:status 200
-      :headers {"Content-Type" "text/css"}
-      :body (slurp (io/resource "pronouns.css"))})
+     :headers {"Content-Type" "text/css"}
+     :body (slurp (io/resource "pronouns.css"))})
 
   (GET "/*" {params :params headers :headers}
-       (if (= "application/json" (get headers "accept"))
+       (if (= "application/json" (.toLowerCase (get headers "accept")))
          {:status 200
           :headers {"Content-Type" "application/json"}
           :body (pages/pronouns (:* params) pronouns-table :json)}