about summary refs log tree commit diff
path: root/src/pronouns/pages.clj
blob: f1f8b67ba8cf4862ec7dca621856708f43a19d60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns pronouns.pages
  (:require [clojure.string :as s]
            [pronouns.util :as u]))

(defn format-pronoun-examples
  [subject object possessive-determiner possessive-pronoun reflexive]
  (s/join "\n"
          [(str subject " went to the park")
           (str "I went with " object)
           (str subject " brought " possessive-determiner " frisbee")
           (str "at least I think it was " possessive-pronoun)
           (str subject " threw it to " reflexive)]))

(defn parse-pronouns-with-lookup [pronouns-string pronouns-table]
  (let [inputs (s/split pronouns-string #"/")
        n (count inputs)]
    (if (>= n 5)
      (take 5 inputs)
      (u/table-lookup inputs pronouns-table))))

(defn front []
  (str "pronoun.is is a www site for showing people how to use pronouns"))

(defn not-found []
  (str "We couldn't find those pronouns in our database, please ask us to "
       "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]
  (let [pronouns (parse-pronouns-with-lookup path pronouns-table)]
    (if pronouns
      (apply format-pronoun-examples pronouns)
      (not-found))))