Merge pull request #94 from witch-house/slash-or
Support `:or` in path, in addition to parameter
This commit is contained in:
commit
26148e3c23
@ -136,13 +136,20 @@
|
|||||||
examples
|
examples
|
||||||
(footer-block)]])))
|
(footer-block)]])))
|
||||||
|
|
||||||
(defn lookup-pronouns [pronouns-string]
|
(defn table-lookup* [pronouns-string]
|
||||||
(let [inputs (s/split pronouns-string #"/")
|
(let [inputs (s/split pronouns-string #"/")
|
||||||
n (count inputs)]
|
n (count inputs)]
|
||||||
(if (>= n 5)
|
(if (>= n 5)
|
||||||
(take 5 inputs)
|
(take 5 inputs)
|
||||||
(u/table-lookup inputs @pronouns-table))))
|
(u/table-lookup inputs @pronouns-table))))
|
||||||
|
|
||||||
|
(defn lookup-pronouns
|
||||||
|
"Given a seq of pronoun sets, look up each set in the pronouns table"
|
||||||
|
[pronoun-sets]
|
||||||
|
(->> pronoun-sets
|
||||||
|
(map (comp table-lookup* escape-html))
|
||||||
|
(filter some?)))
|
||||||
|
|
||||||
(defn make-link [path]
|
(defn make-link [path]
|
||||||
(let [link (str "/" path)
|
(let [link (str "/" path)
|
||||||
label path]
|
label path]
|
||||||
@ -184,8 +191,9 @@
|
|||||||
[:ul links]]]
|
[:ul links]]]
|
||||||
(footer-block)])))
|
(footer-block)])))
|
||||||
|
|
||||||
(defn not-found []
|
(defn not-found [path]
|
||||||
(let [title "Pronoun Island: English Language Examples"]
|
(let [title "Pronoun Island: English Language Examples"
|
||||||
|
or-re #"/[oO][rR]/"]
|
||||||
(html
|
(html
|
||||||
[:html
|
[:html
|
||||||
[:head
|
[:head
|
||||||
@ -195,17 +203,23 @@
|
|||||||
[:body
|
[:body
|
||||||
(header-block title)
|
(header-block title)
|
||||||
[:div {:class "section examples"}
|
[:div {:class "section examples"}
|
||||||
[:p [:h2 (str "We couldn't find those pronouns in our database. "
|
[:p [:h2 "We couldn't find those pronouns in our database :("]
|
||||||
"If you think we should have them, please reach out!")]]]
|
"If you think we should have them, please reach out!"]
|
||||||
|
(when (re-find or-re path)
|
||||||
|
(let [alts (s/split path or-re)
|
||||||
|
new-path (str "/" (s/join "/:OR/" alts))]
|
||||||
|
[:div
|
||||||
|
"Did you mean: "
|
||||||
|
(href new-path
|
||||||
|
(str "pronoun.is"
|
||||||
|
new-path))]))]
|
||||||
(footer-block)]])))
|
(footer-block)]])))
|
||||||
|
|
||||||
(defn pronouns [params]
|
(defn pronouns [params]
|
||||||
(let [path (params :*)
|
(let [path (params :*)
|
||||||
alts (or (params "or") [])
|
param-alts (u/vec-coerce (or (params "or") []))
|
||||||
pronouns (concat [path] (u/vec-coerce alts))
|
path-alts (s/split path #"/:[oO][rR]/")
|
||||||
pronoun-declensions (filter some? (map #(lookup-pronouns
|
pronouns (lookup-pronouns (concat path-alts param-alts))]
|
||||||
(escape-html %))
|
(if (seq pronouns)
|
||||||
pronouns))]
|
(format-pronoun-examples pronouns)
|
||||||
(if (seq pronoun-declensions)
|
(not-found path))))
|
||||||
(format-pronoun-examples pronoun-declensions)
|
|
||||||
(not-found))))
|
|
||||||
|
@ -3,10 +3,21 @@
|
|||||||
[clojure.test :refer [deftest testing is are]]))
|
[clojure.test :refer [deftest testing is are]]))
|
||||||
|
|
||||||
(deftest prose-comma-list
|
(deftest prose-comma-list
|
||||||
(testing "prose-comma-list turns a list of strings into a prose list"
|
(testing "`prose-comma-list` turns a list of strings into a prose list"
|
||||||
(are [call result] (= call result)
|
(are [v s] (= (pages/prose-comma-list v) s)
|
||||||
(pages/prose-comma-list ["foo"]) "foo"
|
["foo" "bar" "baz" "bobble"] "foo, bar, baz, and bobble"
|
||||||
(pages/prose-comma-list ["foo" "bar"]) "foo and bar"
|
["foo" "bar" "baz"] "foo, bar, and baz"
|
||||||
(pages/prose-comma-list ["foo" "bar" "baz"]) "foo, bar, and baz"
|
["foo" "bar"] "foo and bar"
|
||||||
(pages/prose-comma-list ["foo" "bar" "baz" "bobble"]) "foo, bar, baz, and bobble"
|
["foo"] "foo"
|
||||||
(pages/prose-comma-list []) "")))
|
[] "")))
|
||||||
|
|
||||||
|
(deftest lookup-pronouns
|
||||||
|
(are [pronoun-strs pronouns]
|
||||||
|
(= (pages/lookup-pronouns pronoun-strs)
|
||||||
|
pronouns)
|
||||||
|
["she/her"] '(["she" "her" "her" "hers" "herself"])
|
||||||
|
["she" "they"] '(["she" "her" "her" "hers" "herself"]
|
||||||
|
["they" "them" "their" "theirs" "themselves"])
|
||||||
|
["she/her" "foo/bar"] '(["she" "her" "her" "hers" "herself"])
|
||||||
|
["foo/bar"] '()
|
||||||
|
["a/b/c/d/e"] '(("a" "b" "c" "d" "e"))))
|
||||||
|
Loading…
Reference in New Issue
Block a user