2015-03-10 09:29:58 +00:00
|
|
|
(ns pronouns.pages
|
|
|
|
(:require [clojure.string :as s]
|
2015-03-14 02:34:43 +00:00
|
|
|
[pronouns.util :as u]
|
2016-01-23 23:55:21 +00:00
|
|
|
[hiccup.core :refer :all]
|
|
|
|
[hiccup.util :refer [escape-html]]))
|
2015-03-14 02:34:43 +00:00
|
|
|
|
2015-03-14 03:39:54 +00:00
|
|
|
(defn wrap-pronoun
|
|
|
|
[pronoun]
|
|
|
|
[:b pronoun])
|
|
|
|
|
2015-03-14 06:25:39 +00:00
|
|
|
(defn render-sentence [& content]
|
2015-07-04 01:20:49 +00:00
|
|
|
[:p [:span.sentence content]])
|
2015-03-14 03:39:54 +00:00
|
|
|
|
2015-03-14 02:34:43 +00:00
|
|
|
(defn subject-example
|
|
|
|
[subject]
|
2015-03-14 06:25:39 +00:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject)) " went to the park."))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
(defn object-example
|
|
|
|
[object]
|
2015-03-14 06:25:39 +00:00
|
|
|
(render-sentence "I went with " (wrap-pronoun object) "."))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
(defn posessive-determiner-example
|
|
|
|
[subject possessive-determiner]
|
2015-07-04 01:20:49 +00:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject))
|
|
|
|
" brought "
|
|
|
|
(wrap-pronoun possessive-determiner)
|
|
|
|
" frisbee."))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
(defn possessive-pronoun-example
|
|
|
|
[possessive-pronoun]
|
2015-03-14 06:25:39 +00:00
|
|
|
(render-sentence "At least I think it was " (wrap-pronoun possessive-pronoun) "."))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
(defn reflexive-example
|
|
|
|
[subject reflexive]
|
2015-07-04 01:20:49 +00:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject))
|
|
|
|
" threw the frisbee to "
|
|
|
|
(wrap-pronoun reflexive)
|
|
|
|
"."))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
2015-03-14 07:57:03 +00:00
|
|
|
(defn title-block [title]
|
|
|
|
[:div {:class "title"}
|
|
|
|
[:h1 title]])
|
|
|
|
|
2015-03-14 06:41:38 +00:00
|
|
|
(defn examples-block
|
|
|
|
[subject object possessive-determiner possessive-pronoun reflexive]
|
|
|
|
[:div {:class "examples"}
|
2015-03-14 07:57:03 +00:00
|
|
|
[:p [:h2 "Here are some usage examples for my pronouns:"]]
|
2015-03-14 06:41:38 +00:00
|
|
|
(subject-example subject)
|
|
|
|
(object-example object)
|
|
|
|
(posessive-determiner-example subject possessive-determiner)
|
|
|
|
(possessive-pronoun-example possessive-pronoun)
|
|
|
|
(reflexive-example subject reflexive)])
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
(defn about-block []
|
|
|
|
[:div {:class "about"}
|
2015-03-14 08:06:59 +00:00
|
|
|
[:p "Full usage: "
|
2015-03-14 03:39:54 +00:00
|
|
|
[:tt "http://pronoun.is/subject-pronoun/object-pronoun/possessive-determiner/possessive-pronoun/reflexive"]
|
2015-03-14 08:06:59 +00:00
|
|
|
" displays examples of your pronouns."]
|
|
|
|
[:p "This is a bit unwieldy. If we have a good guess we'll let you use just the first one or two."]])
|
2015-03-14 03:39:54 +00:00
|
|
|
|
2015-03-14 06:41:38 +00:00
|
|
|
(defn contact-block []
|
|
|
|
(let [twitter-name (fn [handle] [:a {:href (str "https://www.twitter.com/" handle)} (str "@" handle)])]
|
|
|
|
[:div {:class "contact"}
|
2015-03-14 08:06:59 +00:00
|
|
|
[:p
|
|
|
|
"Written by "
|
|
|
|
(twitter-name "morganastra")
|
|
|
|
", whose "
|
|
|
|
[:a {:href "http://pronoun.is/ze/zir"} "pronoun.is/ze/zir"]
|
|
|
|
". "
|
2015-03-14 06:41:38 +00:00
|
|
|
"Visit the project on " [:a {:href "https://github.com/witch-house/pronoun.is"} "github!"]]]))
|
2015-03-14 03:39:54 +00:00
|
|
|
|
|
|
|
|
2015-03-10 09:29:58 +00:00
|
|
|
(defn format-pronoun-examples
|
|
|
|
[subject object possessive-determiner possessive-pronoun reflexive]
|
2015-03-14 08:25:45 +00:00
|
|
|
(let [title "Pronoun Island: English Language Examples"]
|
2015-03-14 03:39:54 +00:00
|
|
|
(html
|
|
|
|
[:html
|
2015-03-14 04:14:23 +00:00
|
|
|
[:head
|
2015-03-14 07:57:03 +00:00
|
|
|
[:title title]
|
2015-06-16 08:26:53 +00:00
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2015-03-14 04:14:23 +00:00
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
2015-03-14 03:53:33 +00:00
|
|
|
[:body
|
2015-03-14 07:57:03 +00:00
|
|
|
(title-block title)
|
2015-03-14 03:53:33 +00:00
|
|
|
(examples-block subject object possessive-determiner possessive-pronoun reflexive)
|
|
|
|
(about-block)
|
2015-03-14 07:57:03 +00:00
|
|
|
(contact-block)]])))
|
2015-03-10 09:29:58 +00:00
|
|
|
|
2015-03-14 02:34:43 +00:00
|
|
|
|
2015-03-10 09:29:58 +00:00
|
|
|
(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))))
|
|
|
|
|
2015-07-04 01:46:21 +00:00
|
|
|
(defn make-link [path]
|
|
|
|
(let [link (str "/" path)
|
|
|
|
label path]
|
2015-03-14 06:30:19 +00:00
|
|
|
[:li [:a {:href link} label]]))
|
|
|
|
|
|
|
|
(defn front [pronouns-table]
|
2015-07-04 01:46:21 +00:00
|
|
|
(let [abbreviations (u/abbreviate pronouns-table)
|
|
|
|
links (map make-link abbreviations)
|
2015-03-14 07:57:03 +00:00
|
|
|
title "Pronoun Island"]
|
2015-03-14 06:30:19 +00:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
2015-03-14 07:57:03 +00:00
|
|
|
[:title title]
|
2015-06-16 08:26:53 +00:00
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2015-03-14 06:30:19 +00:00
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
|
|
|
[:body
|
2015-03-14 07:57:03 +00:00
|
|
|
(title-block title)
|
2015-03-14 07:47:26 +00:00
|
|
|
[:div {:class "table"}
|
2015-03-14 08:25:45 +00:00
|
|
|
[:p "pronoun.is is a www site for showing people how to use pronouns in English."]
|
2015-03-14 06:30:19 +00:00
|
|
|
[:p "here are some pronouns the site knows about:"]
|
2015-03-14 07:47:26 +00:00
|
|
|
[:ul links]]]
|
|
|
|
(contact-block)])))
|
2015-03-10 09:29:58 +00:00
|
|
|
|
|
|
|
(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]
|
2016-01-23 23:55:21 +00:00
|
|
|
(let [pronouns (parse-pronouns-with-lookup (escape-html path) pronouns-table)]
|
2015-03-10 09:29:58 +00:00
|
|
|
(if pronouns
|
|
|
|
(apply format-pronoun-examples pronouns)
|
|
|
|
(not-found))))
|