2024-05-03 11:38:27 +02:00
|
|
|
;; pronoun.lol - a website for pronoun usage examples
|
2018-11-14 22:00:58 +01:00
|
|
|
;; Copyright (C) 2014 - 2018 Morgan Astra
|
2024-05-03 11:38:27 +02:00
|
|
|
;; Copyright (C) 2024 Kim Endisch
|
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]
|
2018-11-16 04:07:12 +01: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
|
2024-05-03 11:38:27 +02:00
|
|
|
[:tt "https://pronoun.lol/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 "
|
2024-05-03 11:38:27 +02:00
|
|
|
(href "https://pronoun.lol/she" "pronoun.lol/she")]
|
|
|
|
[:p "pronoun.lol is free software under the "
|
2016-09-22 01:25:33 +02:00
|
|
|
(href "https://www.gnu.org/licenses/agpl.html" "AGPLv3")
|
|
|
|
"! visit the project on "
|
2024-05-03 11:38:27 +02:00
|
|
|
(href "https://github.com/witch-house/pronoun.lol" "github")]
|
2018-12-29 20:14:28 +01:00
|
|
|
[: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)
|
2024-05-03 11:40:30 +02:00
|
|
|
title (str "Pronoun LOL: " (prose-comma-list sub-objs) " examples")
|
2017-03-08 21:30:45 +01:00
|
|
|
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"}]
|
2018-12-29 20:14:28 +01:00
|
|
|
[:meta {:charset "utf-8"}]
|
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
|
|
|
|
2018-11-16 07:16:19 +01:00
|
|
|
(defn table-lookup* [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)
|
2018-11-16 04:07:12 +01:00
|
|
|
(u/table-lookup inputs @pronouns-table))))
|
2015-03-10 10:29:58 +01:00
|
|
|
|
2018-11-16 07:16:19 +01:00
|
|
|
(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?)))
|
|
|
|
|
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-16 04:07:12 +01:00
|
|
|
(let [abbreviations (take 6 (u/abbreviate @pronouns-table))
|
2015-07-04 03:46:21 +02:00
|
|
|
links (map make-link abbreviations)
|
2024-05-03 11:40:30 +02:00
|
|
|
title "Pronoun LOL"
|
2024-05-03 11:38:27 +02:00
|
|
|
description "Pronoun.lol is a website for personal pronoun usage examples."]
|
2015-03-14 07:30:19 +01:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
2015-03-14 08:57:03 +01:00
|
|
|
[:title title]
|
2019-01-24 08:25:52 +01:00
|
|
|
[:meta {:name "description" :content description}]
|
|
|
|
[:meta {:name "twitter:card" :content "summary"}]
|
|
|
|
[:meta {:name "twitter:title" :content title}]
|
|
|
|
[:meta {:name "twitter:description" :content description}]
|
2015-06-16 10:26:53 +02:00
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2018-12-29 20:14:28 +01:00
|
|
|
[:meta {:charset "utf-8"}]
|
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"}
|
2024-05-03 11:38:27 +02:00
|
|
|
[:p "pronoun.lol is a website for personal pronoun usage examples"]
|
2018-11-15 07:22:15 +01:00
|
|
|
[: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 []
|
2018-11-16 04:07:12 +01:00
|
|
|
(let [abbreviations (u/abbreviate @pronouns-table)
|
2018-11-15 07:22:15 +01:00
|
|
|
links (map make-link abbreviations)
|
2024-05-03 11:40:30 +02:00
|
|
|
title "Pronoun LOL"]
|
2018-11-15 07:22:15 +01:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
|
|
|
[:title title]
|
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2018-12-29 20:14:28 +01:00
|
|
|
[:meta {:charset "utf-8"}]
|
2018-11-15 07:22:15 +01:00
|
|
|
[: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
|
|
|
|
2018-11-16 07:16:19 +01:00
|
|
|
(defn not-found [path]
|
2024-05-03 11:40:30 +02:00
|
|
|
(let [title "Pronoun LOL: English Language Examples"
|
2018-11-16 07:16:19 +01:00
|
|
|
or-re #"/[oO][rR]/"]
|
2016-08-07 14:47:00 +02:00
|
|
|
(html
|
|
|
|
[:html
|
|
|
|
[:head
|
|
|
|
[:title title]
|
|
|
|
[:meta {:name "viewport" :content "width=device-width"}]
|
2018-12-29 20:14:28 +01:00
|
|
|
[:meta {:charset "utf-8"}]
|
2016-08-07 14:47:00 +02:00
|
|
|
[:link {:rel "stylesheet" :href "/pronouns.css"}]]
|
|
|
|
[:body
|
2016-09-24 10:28:13 +02:00
|
|
|
(header-block title)
|
2018-11-16 07:16:19 +01:00
|
|
|
[:div {:class "section examples"}
|
|
|
|
[:p [:h2 "We couldn't find those pronouns in our database :("]
|
|
|
|
"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
|
2024-05-03 11:38:27 +02:00
|
|
|
(str "pronoun.lol"
|
2018-11-16 07:16:19 +01:00
|
|
|
new-path))]))]
|
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 :*)
|
2018-11-16 07:16:19 +01:00
|
|
|
param-alts (u/vec-coerce (or (params "or") []))
|
|
|
|
path-alts (s/split path #"/:[oO][rR]/")
|
|
|
|
pronouns (lookup-pronouns (concat path-alts param-alts))]
|
|
|
|
(if (seq pronouns)
|
|
|
|
(format-pronoun-examples pronouns)
|
|
|
|
(not-found path))))
|