2016-09-21 00:40:01 +02:00
|
|
|
;; pronoun.is - a website for pronoun usage examples
|
2018-11-14 22:00:58 +01:00
|
|
|
;; Copyright (C) 2014 - 2018 Morgan Astra
|
2016-09-21 00:40:01 +02:00
|
|
|
|
|
|
|
;; This program is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU Affero General Public License as
|
|
|
|
;; published by the Free Software Foundation, either version 3 of the
|
|
|
|
;; License, or (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU Affero General Public License
|
2018-11-14 23:17:47 +01:00
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>
|
2016-09-21 00:40:01 +02:00
|
|
|
|
2015-03-10 10:29:58 +01:00
|
|
|
(ns pronouns.pages
|
|
|
|
(:require [clojure.string :as s]
|
2016-08-10 06:05:50 +02:00
|
|
|
[pronouns.config :refer [*pronouns-table*]]
|
2015-03-14 03:34:43 +01:00
|
|
|
[pronouns.util :as u]
|
2016-01-24 00:55:21 +01:00
|
|
|
[hiccup.core :refer :all]
|
2017-03-09 07:48:40 +01:00
|
|
|
[hiccup.element :as e]
|
2016-01-24 00:55:21 +01:00
|
|
|
[hiccup.util :refer [escape-html]]))
|
2015-03-14 03:34:43 +01:00
|
|
|
|
2016-09-24 09:32:23 +02:00
|
|
|
(defn prose-comma-list
|
|
|
|
[items]
|
|
|
|
(let [c (count items)]
|
|
|
|
(cond
|
2016-09-24 10:28:13 +02:00
|
|
|
(<= c 1) (or (first items) "")
|
2016-09-24 09:32:23 +02:00
|
|
|
(= c 2) (s/join " and " items)
|
|
|
|
:else (str (s/join ", " (butlast items)) ", and " (last items)))))
|
|
|
|
|
2016-09-21 00:40:01 +02:00
|
|
|
(defn href
|
|
|
|
[url text]
|
|
|
|
[:a {:href url} text])
|
|
|
|
|
2018-11-14 23:28:15 +01:00
|
|
|
;; FIXME morgan.astra <2018-11-14 Wed>
|
|
|
|
;; use a div for this instead of a plain bold tag
|
2015-03-14 04:39:54 +01:00
|
|
|
(defn wrap-pronoun
|
|
|
|
[pronoun]
|
|
|
|
[:b pronoun])
|
|
|
|
|
2015-03-14 07:25:39 +01:00
|
|
|
(defn render-sentence [& content]
|
2015-07-04 03:20:49 +02:00
|
|
|
[:p [:span.sentence content]])
|
2015-03-14 04:39:54 +01:00
|
|
|
|
2015-03-14 03:34:43 +01:00
|
|
|
(defn subject-example
|
|
|
|
[subject]
|
2015-03-14 07:25:39 +01:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject)) " went to the park."))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
|
|
|
(defn object-example
|
|
|
|
[object]
|
2015-03-14 07:25:39 +01:00
|
|
|
(render-sentence "I went with " (wrap-pronoun object) "."))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
|
|
|
(defn posessive-determiner-example
|
|
|
|
[subject possessive-determiner]
|
2015-07-04 03:20:49 +02:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject))
|
|
|
|
" brought "
|
|
|
|
(wrap-pronoun possessive-determiner)
|
|
|
|
" frisbee."))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
|
|
|
(defn possessive-pronoun-example
|
|
|
|
[possessive-pronoun]
|
2016-09-24 09:32:23 +02:00
|
|
|
(render-sentence "At least I think it was "
|
|
|
|
(wrap-pronoun possessive-pronoun)
|
|
|
|
"."))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
|
|
|
(defn reflexive-example
|
|
|
|
[subject reflexive]
|
2015-07-04 03:20:49 +02:00
|
|
|
(render-sentence (wrap-pronoun (s/capitalize subject))
|
|
|
|
" threw the frisbee to "
|
|
|
|
(wrap-pronoun reflexive)
|
|
|
|
"."))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
2016-09-24 09:32:23 +02:00
|
|
|
(defn header-block [header]
|
2016-09-21 01:17:58 +02:00
|
|
|
[:div {:class "section title"}
|
2018-11-14 22:00:58 +01:00
|
|
|
(href "/" [:h1 header])])
|
2015-03-14 08:57:03 +01:00
|
|
|
|
2015-03-14 07:41:38 +01:00
|
|
|
(defn examples-block
|
|
|
|
[subject object possessive-determiner possessive-pronoun reflexive]
|
2016-09-24 09:32:23 +02:00
|
|
|
(let [sub-obj (s/join "/" [subject object])
|
|
|
|
header-str (str "Here are some example sentences using my "
|
2016-08-07 12:18:47 +02:00
|
|
|
sub-obj
|
2016-09-24 09:32:23 +02:00
|
|
|
" pronouns:")]
|
2016-09-21 01:17:58 +02:00
|
|
|
[:div {:class "section examples"}
|
2016-09-22 01:25:33 +02:00
|
|
|
[:h2 header-str]
|
|
|
|
[:p (subject-example subject)
|
|
|
|
(object-example object)
|
|
|
|
(posessive-determiner-example subject possessive-determiner)
|
|
|
|
(possessive-pronoun-example possessive-pronoun)
|
|
|
|
(reflexive-example subject reflexive)]]))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
2016-09-23 02:44:16 +02:00
|
|
|
(defn usage-block []
|
|
|
|
[:div {:class "section usage"}
|
2015-03-14 09:06:59 +01:00
|
|
|
[:p "Full usage: "
|
2018-11-14 23:28:15 +01:00
|
|
|
;; FIXME morgan.astra <2018-11-14 Wed>
|
|
|
|
;; This looks really ugly in the browser
|
2018-11-14 23:16:18 +01:00
|
|
|
[:tt "https://pronoun.is/subject-pronoun/object-pronoun/possessive-determiner/possessive-pronoun/reflexive"]
|
2016-09-22 01:25:33 +02:00
|
|
|
" displays examples of your pronouns."]
|
2016-09-24 09:32:23 +02:00
|
|
|
[: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 04:39:54 +01:00
|
|
|
|
2015-03-14 07:41:38 +01:00
|
|
|
(defn contact-block []
|
2016-09-21 00:40:01 +02:00
|
|
|
(let [twitter-name (fn [handle] (href (str "https://www.twitter.com/" handle)
|
|
|
|
(str "@" handle)))]
|
2016-09-22 08:58:16 +02:00
|
|
|
[:div {:class "section contact"}
|
2016-09-22 01:25:33 +02:00
|
|
|
[:p "Written by "
|
|
|
|
(twitter-name "morganastra")
|
|
|
|
", whose "
|
2018-11-14 23:16:18 +01:00
|
|
|
(href "https://pronoun.is/she" "pronoun.is/she")]
|
2016-09-22 01:25:33 +02:00
|
|
|
[:p "pronoun.is is free software under the "
|
|
|
|
(href "https://www.gnu.org/licenses/agpl.html" "AGPLv3")
|
|
|
|
"! visit the project on "
|
|
|
|
(href "https://github.com/witch-house/pronoun.is" "github")]
|
|
|
|
[:p "<3"]]))
|
2015-03-14 04:39:54 +01:00
|
|
|
|
2016-09-22 08:58:16 +02:00
|
|
|
(defn footer-block []
|
2016-09-23 02:44:16 +02:00
|
|
|
[:footer (usage-block) (contact-block)])
|
2015-03-14 04:39:54 +01:00
|
|
|
|
2015-03-10 10:29:58 +01:00
|
|
|
(defn format-pronoun-examples
|
2016-08-07 12:55:53 +02:00
|
|
|
[pronoun-declensions]
|
2016-09-24 09:32:23 +02:00
|
|
|
(let [sub-objs (map #(s/join "/" (take 2 %)) pronoun-declensions)
|
2017-03-08 21:30:45 +01:00
|
|
|
title (str "Pronoun Island: " (prose-comma-list sub-objs) " examples")
|
|
|
|
examples (map #(apply examples-block %) pronoun-declensions)]
|
2016-08-07 12:04:39 +02:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
|
|
|
[:title title]
|
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2017-03-08 21:30:45 +01:00
|
|
|
[:meta {:name "description" :content (u/strip-markup examples)}]
|
2017-03-10 03:10:38 +01:00
|
|
|
[:meta {:name "twitter:card" :content "summary"}]
|
2017-03-09 09:27:51 +01:00
|
|
|
[:meta {:name "twitter:title" :content title}]
|
|
|
|
[:meta {:name "twitter:description" :content (u/strip-markup examples)}]
|
2016-08-07 12:04:39 +02:00
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
|
|
|
[:body
|
2016-09-24 10:28:13 +02:00
|
|
|
(header-block title)
|
2017-03-08 21:30:45 +01:00
|
|
|
examples
|
2016-09-22 08:58:16 +02:00
|
|
|
(footer-block)]])))
|
2015-03-14 03:34:43 +01:00
|
|
|
|
2016-08-10 06:05:50 +02:00
|
|
|
(defn lookup-pronouns [pronouns-string]
|
2015-03-10 10:29:58 +01:00
|
|
|
(let [inputs (s/split pronouns-string #"/")
|
|
|
|
n (count inputs)]
|
|
|
|
(if (>= n 5)
|
|
|
|
(take 5 inputs)
|
2016-08-10 06:05:50 +02:00
|
|
|
(u/table-lookup inputs *pronouns-table*))))
|
2015-03-10 10:29:58 +01:00
|
|
|
|
2015-07-04 03:46:21 +02:00
|
|
|
(defn make-link [path]
|
|
|
|
(let [link (str "/" path)
|
|
|
|
label path]
|
2016-09-21 00:40:01 +02:00
|
|
|
[:li (href link label)]))
|
2015-03-14 07:30:19 +01:00
|
|
|
|
2016-08-10 06:05:50 +02:00
|
|
|
(defn front []
|
2018-11-15 08:09:06 +01:00
|
|
|
(let [abbreviations (take 6 (u/abbreviate *pronouns-table*))
|
2015-07-04 03:46:21 +02:00
|
|
|
links (map make-link abbreviations)
|
2015-03-14 08:57:03 +01:00
|
|
|
title "Pronoun Island"]
|
2015-03-14 07:30:19 +01:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
2015-03-14 08:57:03 +01:00
|
|
|
[:title title]
|
2015-06-16 10:26:53 +02:00
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2015-03-14 07:30:19 +01:00
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
|
|
|
[:body
|
2016-09-24 10:28:13 +02:00
|
|
|
(header-block title)
|
2016-09-21 01:17:58 +02:00
|
|
|
[:div {:class "section table"}
|
2018-11-15 07:22:15 +01:00
|
|
|
[:p "pronoun.is is a website for personal pronoun usage examples"]
|
|
|
|
[:p "here are some pronouns the site knows about:"]
|
|
|
|
[:ul links]
|
|
|
|
[:p [:small (href "all-pronouns" "see all pronouns in the database")]]]]
|
|
|
|
(footer-block)])))
|
|
|
|
|
|
|
|
(defn all-pronouns []
|
|
|
|
(let [abbreviations (u/abbreviate *pronouns-table*)
|
|
|
|
links (map make-link abbreviations)
|
|
|
|
title "Pronoun Island"]
|
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
|
|
|
[:title title]
|
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
|
|
|
[:body
|
|
|
|
(header-block title)
|
|
|
|
[:div {:class "section table"}
|
|
|
|
[:p "All pronouns the site knows about:"]
|
|
|
|
[:ul links]]]
|
2016-09-22 08:58:16 +02:00
|
|
|
(footer-block)])))
|
2015-03-10 10:29:58 +01:00
|
|
|
|
|
|
|
(defn not-found []
|
2016-08-07 14:47:00 +02:00
|
|
|
(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
|
2016-09-24 10:28:13 +02:00
|
|
|
(header-block title)
|
2016-09-21 01:17:58 +02:00
|
|
|
[:div {:class "section examples"}
|
2018-08-11 15:18:15 +02:00
|
|
|
[:p [:h2 (str "We couldn't find those pronouns in our database. "
|
2016-08-07 14:47:00 +02:00
|
|
|
"If you think we should have them, please reach out!")]]]
|
2016-09-22 08:58:16 +02:00
|
|
|
(footer-block)]])))
|
2015-03-10 10:29:58 +01:00
|
|
|
|
2016-08-10 06:05:50 +02:00
|
|
|
(defn pronouns [params]
|
2016-08-07 12:04:39 +02:00
|
|
|
(let [path (params :*)
|
2016-08-07 12:55:53 +02:00
|
|
|
alts (or (params "or") [])
|
|
|
|
pronouns (concat [path] (u/vec-coerce alts))
|
2016-08-10 06:05:50 +02:00
|
|
|
pronoun-declensions (filter some? (map #(lookup-pronouns
|
|
|
|
(escape-html %))
|
|
|
|
pronouns))]
|
2016-08-07 14:47:00 +02:00
|
|
|
(if (seq pronoun-declensions)
|
2016-08-07 12:55:53 +02:00
|
|
|
(format-pronoun-examples pronoun-declensions)
|
2015-03-10 10:29:58 +01:00
|
|
|
(not-found))))
|