pronoun.lol/src/pronouns/pages.clj

104 lines
3.2 KiB
Clojure
Raw Normal View History

(ns pronouns.pages
(:require [clojure.string :as s]
[pronouns.util :as u]
[hiccup.core :refer :all]))
2015-03-14 04:39:54 +01:00
(defn wrap-pronoun
[pronoun]
[:b pronoun])
(defn wrap-para
[whatever]
2015-03-14 04:53:33 +01:00
[:p whatever])
2015-03-14 04:39:54 +01:00
(defn subject-example
[subject]
2015-03-14 04:39:54 +01:00
(wrap-para
2015-03-14 04:53:33 +01:00
[:span#sentence (wrap-pronoun subject) " went to the park."]))
2015-03-14 04:39:54 +01:00
(defn object-example
[object]
(wrap-para
2015-03-14 04:53:33 +01:00
[:span#sentence "I went with " (wrap-pronoun object) "."]))
2015-03-14 04:39:54 +01:00
(defn posessive-determiner-example
[subject possessive-determiner]
(wrap-para
2015-03-14 04:53:33 +01:00
[:span#sentence (wrap-pronoun subject) " brought " (wrap-pronoun possessive-determiner) " frisbee."]))
2015-03-14 04:39:54 +01:00
(defn possessive-pronoun-example
[possessive-pronoun]
(wrap-para
2015-03-14 04:53:33 +01:00
[:span#sentence "At least I think it was " (wrap-pronoun possessive-pronoun) "."]))
2015-03-14 04:39:54 +01:00
(defn reflexive-example
[subject reflexive]
(wrap-para
[:span#sentence (wrap-pronoun subject) " threw the frisbee to " (wrap-pronoun reflexive)]))
2015-03-14 04:39:54 +01:00
(defn twitter-name [name]
2015-03-14 04:53:33 +01:00
[:a {:href (str "https://www.twitter.com/" name)} (str "@" name)])
2015-03-14 04:39:54 +01:00
(defn contact-block []
[:div {:class "contact"}
2015-03-14 05:37:38 +01:00
[:p "Written by " (twitter-name "morganastra") " and " (twitter-name "thelseraphim") ". "
"Visit the project on " [:a {:href "https://github.com/witch-house/pronoun.is"} "github!"]]])
2015-03-14 04:39:54 +01:00
(defn about-block []
[:div {:class "about"}
[:p "Full usage:"]
[:p
[:tt "http://pronoun.is/subject-pronoun/object-pronoun/possessive-determiner/possessive-pronoun/reflexive"]
" displays examples of your pronouns. If we have a good guess we'll let you use just the first one or two."]
[:p "Quick examples:"]
2015-03-14 04:53:33 +01:00
[:p "My name is Thel Seraphim, my " [:a {:href "http://pronoun.is/she"} "pronoun.is/she"] "."]
[:p "My name is Morgan, my " [:a {:href "http://pronoun.is/ze/zir"} "pronoun.is/ze/zir"] "."]])
2015-03-14 04:39:54 +01:00
(defn examples-block
[subject object possessive-determiner possessive-pronoun reflexive]
[:div {:class "examples"}
2015-03-14 04:55:45 +01:00
[:p [:h1 "Here are some usage examples for my pronouns:"]]
2015-03-14 04:39:54 +01:00
(subject-example subject)
(object-example object)
(posessive-determiner-example subject possessive-determiner)
(possessive-pronoun-example possessive-pronoun)
(reflexive-example subject reflexive)])
(defn format-pronoun-examples
[subject object possessive-determiner possessive-pronoun reflexive]
2015-03-14 04:39:54 +01:00
(html
[:html
[:head
[:title "Pronoun examples"]
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
2015-03-14 04:53:33 +01:00
[:body
(examples-block subject object possessive-determiner possessive-pronoun reflexive)
(about-block)
(contact-block)]]))
(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))))