From f0f6c207daea6efff6422e0a79fa388198fc9d4d Mon Sep 17 00:00:00 2001 From: Morgan Astra Date: Sun, 7 Aug 2016 03:04:39 -0700 Subject: add experimental support for multiple pronoun sets --- src/pronouns/pages.clj | 46 +++++++++++++++++++++++++++++----------------- src/pronouns/util.clj | 3 +++ src/pronouns/web.clj | 10 +++++----- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/pronouns/pages.clj b/src/pronouns/pages.clj index 3e63437..2a0c732 100644 --- a/src/pronouns/pages.clj +++ b/src/pronouns/pages.clj @@ -71,20 +71,22 @@ (defn format-pronoun-examples - [subject object possessive-determiner possessive-pronoun reflexive] + [pronoun-declension alternates] + (println pronoun-declension) + (println alternates) (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 - (title-block title) - (examples-block subject object possessive-determiner possessive-pronoun reflexive) - (about-block) - (contact-block)]]))) - + (html + [:html + [:head + [:title title] + [:meta {:name "viewport" :content "width=device-width"}] + [:link {:rel "stylesheet" :href "/pronouns.css"}]] + [:body + (title-block title) + (apply examples-block pronoun-declension) + (map #(apply examples-block %) alternates) + (about-block) + (contact-block)]]))) (defn parse-pronouns-with-lookup [pronouns-string pronouns-table] (let [inputs (s/split pronouns-string #"/") @@ -121,8 +123,18 @@ "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 (escape-html path) pronouns-table)] - (if pronouns - (apply format-pronoun-examples pronouns) +(defn pronouns [params pronouns-table] + (println params) + (let [path (params :*) + ors (u/vec-coerce (params "or")) + a (println path) + pronoun-declension (parse-pronouns-with-lookup (escape-html path) + pronouns-table) + alternates (map #(parse-pronouns-with-lookup (escape-html %) + pronouns-table) + ors) + ] + (println pronoun-declension) + (if pronoun-declension + (format-pronoun-examples pronoun-declension alternates) (not-found)))) diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj index 4d4f928..3a4bf10 100644 --- a/src/pronouns/util.clj +++ b/src/pronouns/util.clj @@ -29,3 +29,6 @@ "given a list of pronoun rows, return a list of minimum unabiguous paths" [pronouns-table] (map (partial minimum-unambiguous-path pronouns-table) pronouns-table)) + +(defn vec-coerce [x] + (if (vector? x) x [x])) diff --git a/src/pronouns/web.clj b/src/pronouns/web.clj index 23ac603..cb5e6c9 100644 --- a/src/pronouns/web.clj +++ b/src/pronouns/web.clj @@ -6,8 +6,7 @@ [clojure.string :as s] [ring.middleware.logger :as logger] [ring.middleware.stacktrace :as trace] - [ring.middleware.session :as session] - [ring.middleware.session.cookie :as cookie] + [ring.middleware.params :as params] [ring.adapter.jetty :as jetty] [environ.core :refer [env]] [pronouns.util :as u] @@ -23,7 +22,7 @@ :headers {"Content-Type" "text/html"} :body (pages/front pronouns-table)}) - (GET "/pronouns.css" {params :params} + (GET "/pronouns.css" [] {:status 200 :headers {"Content-Type" "text/css"} :body (slurp (io/resource "pronouns.css"))}) @@ -31,7 +30,7 @@ (GET "/*" {params :params} {:status 200 :headers {"Content-Type" "text/html"} - :body (pages/pronouns (:* params) pronouns-table)}) + :body (pages/pronouns params pronouns-table)}) (ANY "*" [] (route/not-found (slurp (io/resource "404.html"))))) @@ -48,7 +47,8 @@ (-> app-routes logger/wrap-with-logger wrap-error-page - trace/wrap-stacktrace)) + trace/wrap-stacktrace + params/wrap-params)) (defn -main [] (let [port (Integer. (:port env -- cgit From f7e3f082cebec1c7f601bb3d3ed021c7acf6d841 Mon Sep 17 00:00:00 2001 From: Morgan Astra Date: Sun, 7 Aug 2016 03:18:47 -0700 Subject: add descriptive headers for multiple pronoun sets #38 --- src/pronouns/pages.clj | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/pronouns/pages.clj b/src/pronouns/pages.clj index 2a0c732..dcade59 100644 --- a/src/pronouns/pages.clj +++ b/src/pronouns/pages.clj @@ -43,13 +43,17 @@ (defn examples-block [subject object possessive-determiner possessive-pronoun reflexive] - [:div {:class "examples"} - [:p [:h2 "Here are some usage examples for my pronouns:"]] - (subject-example subject) - (object-example object) - (posessive-determiner-example subject possessive-determiner) - (possessive-pronoun-example possessive-pronoun) - (reflexive-example subject reflexive)]) + (let [sub-obj (str subject "/" object) + header-str (str "Here are some usage examples for my " + sub-obj + " pronouns")] + [:div {:class "examples"} + [:p [:h2 header-str]] + (subject-example subject) + (object-example object) + (posessive-determiner-example subject possessive-determiner) + (possessive-pronoun-example possessive-pronoun) + (reflexive-example subject reflexive)])) (defn about-block [] [:div {:class "about"} @@ -72,8 +76,6 @@ (defn format-pronoun-examples [pronoun-declension alternates] - (println pronoun-declension) - (println alternates) (let [title "Pronoun Island: English Language Examples"] (html [:html @@ -88,7 +90,7 @@ (about-block) (contact-block)]]))) -(defn parse-pronouns-with-lookup [pronouns-string pronouns-table] +(defn lookup-pronouns [pronouns-string pronouns-table] (let [inputs (s/split pronouns-string #"/") n (count inputs)] (if (>= n 5) @@ -124,16 +126,13 @@ "https://github.com/witch-house/pronoun.is/blob/master/resources/pronouns.tab")) (defn pronouns [params pronouns-table] - (println params) (let [path (params :*) ors (u/vec-coerce (params "or")) - a (println path) - pronoun-declension (parse-pronouns-with-lookup (escape-html path) - pronouns-table) - alternates (map #(parse-pronouns-with-lookup (escape-html %) - pronouns-table) - ors) - ] + pronoun-declension (lookup-pronouns (escape-html path) + pronouns-table) + alternates (map #(lookup-pronouns (escape-html %) + pronouns-table) + ors)] (println pronoun-declension) (if pronoun-declension (format-pronoun-examples pronoun-declension alternates) -- cgit From a4369bf8498a8fd314ef6f7a5bd45cb212bec161 Mon Sep 17 00:00:00 2001 From: Morgan Astra Date: Sun, 7 Aug 2016 03:20:31 -0700 Subject: remove errant println! --- src/pronouns/pages.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pronouns/pages.clj b/src/pronouns/pages.clj index dcade59..2aaf964 100644 --- a/src/pronouns/pages.clj +++ b/src/pronouns/pages.clj @@ -133,7 +133,6 @@ alternates (map #(lookup-pronouns (escape-html %) pronouns-table) ors)] - (println pronoun-declension) (if pronoun-declension (format-pronoun-examples pronoun-declension alternates) (not-found)))) -- cgit