Compare commits

...

5 commits

Author SHA1 Message Date
Ben Aaron Goldberg 0fa50fad47 web: Remove debug comments
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
2021-10-24 05:43:06 -04:00
Ben Aaron Goldberg b6182eb317 web: Push name in title
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
2021-10-24 05:42:18 -04:00
Ben Aaron Goldberg 63e4f2b8fc lib: Make pref_strings lowercase
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
2021-10-24 05:41:35 -04:00
Ben Aaron Goldberg 680bbd5b2d web: Added example sentences
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
2021-10-24 05:34:02 -04:00
Ben Aaron Goldberg 5aa00e052e web: Add web page explantation message
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
2021-10-24 05:19:45 -04:00
3 changed files with 28 additions and 18 deletions

View file

@ -78,7 +78,7 @@ pub trait Preference {
/// This is the primary method of creating a `Preference` object from a prefstring. The
/// default implementation calls the underlying [`Preference::from_prefstring_bytes()`] method.
fn from_prefstring(prefstring: &str) -> Result<Self, ParseError> where Self: Sized {
BASE32_NOPAD.decode(prefstring.as_ref())
BASE32_NOPAD.decode(prefstring.to_uppercase().as_bytes())
.map_err(ParseError::Base32Error)
.and_then(|ps| Self::from_prefstring_bytes(&ps))
}
@ -88,7 +88,7 @@ pub trait Preference {
/// This is the primary method of creating a prefstring from a `Preference` object. The
/// default implementation calls the underlying [`Preference::into_prefstring_bytes()`] method.
fn as_prefstring(&self) -> String {
BASE32_NOPAD.encode(&self.as_prefstring_bytes())
BASE32_NOPAD.encode(&self.as_prefstring_bytes()).to_lowercase()
}
/// Select a pronoun for today using this Preference's WeightedTable.

View file

@ -14,14 +14,14 @@ use pronouns_today::{InstanceSettings, Pronoun};
#[template(path = "index.html")]
struct IndexTemplate<'a> {
name: Option<String>,
short: String,
pronoun: &'a Pronoun,
pronouns: Vec<(usize, &'a Pronoun)>,
}
fn render_page(pronoun: &Pronoun, settings: &InstanceSettings, name: Option<String>) -> String {
IndexTemplate {
name,
short: pronoun.render_threeform(),
pronoun,
pronouns: settings.pronoun_list.iter().enumerate().collect(),
}
.render()
@ -33,7 +33,6 @@ async fn create_link(
settings: web::Data<InstanceSettings>,
form: web::Form<HashMap<String, String>>,
) -> Result<impl Responder> {
eprintln!("create {:?}", form);
let mut weights = vec![0; settings.pronoun_list.len()];
for (k, v) in form.iter() {
if let Ok(i) = k.parse::<usize>() {
@ -44,9 +43,7 @@ async fn create_link(
}
}
let prefs = InstanceSettings::create_preferences(&weights);
eprintln!("prefs: {:?}", prefs);
let pref_string = prefs.as_prefstring();
eprintln!("prefstring: {}", pref_string);
let url = match form.get("name") {
Some(name) if !name.is_empty() => format!("/{}/{}", name, pref_string),
_ => format!("/{}", pref_string),
@ -58,7 +55,6 @@ async fn create_link(
#[get("/")]
async fn default(settings: web::Data<InstanceSettings>) -> Result<impl Responder> {
eprintln!("default");
let pronoun = settings
.select_pronouns(None, None)
.map_err(|_| Error::InvlaidPrefString)?;
@ -72,7 +68,6 @@ async fn only_prefs(
web::Path(prefs): web::Path<String>,
settings: web::Data<InstanceSettings>,
) -> Result<impl Responder> {
eprintln!("prefs {}", prefs);
let pronoun = settings
.select_pronouns(None, Some(&prefs))
.map_err(|_| Error::InvlaidPrefString)?;
@ -86,7 +81,6 @@ async fn prefs_and_name(
web::Path((name, prefs)): web::Path<(String, String)>,
settings: web::Data<InstanceSettings>,
) -> Result<impl Responder> {
eprintln!("prefs+name");
let pronoun = settings
.select_pronouns(Some(&name), Some(&prefs))
.map_err(|_| Error::InvlaidPrefString)?;

View file

@ -1,6 +1,7 @@
<html>
<head>
<title>My Pronouns Today</title>
<title>{% if name.is_some() %} {{ name.as_ref().unwrap() }}'s {% else %}
My{% endif %} Pronouns Today</title>
<style>
#form {
display: none;
@ -11,13 +12,28 @@
</style>
</head>
<body>
<h1>
{% if name.is_some() %}
{{ name.as_ref().unwrap() }}
{% else %}
My
{% endif %}
pronouns today are: {{ short }}</h1>
<h1>{% if name.is_some() %} {{ name.as_ref().unwrap() }}'s {% else %}
My{% endif %} pronouns today are: {{ pronoun.render_threeform() }}</h1>
<p>This page picks a random pronoun from a list of preferred pronouns every
day.
{% if name.is_some() %} {{ name.as_ref().unwrap() }}{% else %}
Whoever linked you to this page{% endif %} would like you to try {{ pronoun.render_threeform() }} pronouns for
{{ pronoun.object_pronoun }} today.</p>
<h3>Here are some example sentences using my she/her pronouns:</h3>
<p>{{ pronoun.subject_pronoun | capitalize }} walked the dog.</p>
<p>I went with {{ pronoun.object_pronoun }}.</p>
<p>{{ pronoun.subject_pronoun | capitalize }} rode {{ pronoun.possesive_determiner }} bike.</p>
<p>At least I think it is {{ pronoun.possesive_pronoun }}.</p>
<p>{{ pronoun.subject_pronoun | capitalize }} bought the stuffed animal for {{ pronoun.reflexive_pronoun }}.</p>
<hr/>
<label for="form-toggle">Create your own custom link!</label>
<input type="checkbox" id="form-toggle" style="display: none;"/>