Compare commits
5 commits
5ad04f1427
...
0fa50fad47
Author | SHA1 | Date | |
---|---|---|---|
0fa50fad47 | |||
b6182eb317 | |||
63e4f2b8fc | |||
680bbd5b2d | |||
5aa00e052e |
|
@ -78,7 +78,7 @@ pub trait Preference {
|
||||||
/// This is the primary method of creating a `Preference` object from a prefstring. The
|
/// This is the primary method of creating a `Preference` object from a prefstring. The
|
||||||
/// default implementation calls the underlying [`Preference::from_prefstring_bytes()`] method.
|
/// default implementation calls the underlying [`Preference::from_prefstring_bytes()`] method.
|
||||||
fn from_prefstring(prefstring: &str) -> Result<Self, ParseError> where Self: Sized {
|
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)
|
.map_err(ParseError::Base32Error)
|
||||||
.and_then(|ps| Self::from_prefstring_bytes(&ps))
|
.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
|
/// This is the primary method of creating a prefstring from a `Preference` object. The
|
||||||
/// default implementation calls the underlying [`Preference::into_prefstring_bytes()`] method.
|
/// default implementation calls the underlying [`Preference::into_prefstring_bytes()`] method.
|
||||||
fn as_prefstring(&self) -> String {
|
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.
|
/// Select a pronoun for today using this Preference's WeightedTable.
|
||||||
|
|
|
@ -14,14 +14,14 @@ use pronouns_today::{InstanceSettings, Pronoun};
|
||||||
#[template(path = "index.html")]
|
#[template(path = "index.html")]
|
||||||
struct IndexTemplate<'a> {
|
struct IndexTemplate<'a> {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
short: String,
|
pronoun: &'a Pronoun,
|
||||||
pronouns: Vec<(usize, &'a Pronoun)>,
|
pronouns: Vec<(usize, &'a Pronoun)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_page(pronoun: &Pronoun, settings: &InstanceSettings, name: Option<String>) -> String {
|
fn render_page(pronoun: &Pronoun, settings: &InstanceSettings, name: Option<String>) -> String {
|
||||||
IndexTemplate {
|
IndexTemplate {
|
||||||
name,
|
name,
|
||||||
short: pronoun.render_threeform(),
|
pronoun,
|
||||||
pronouns: settings.pronoun_list.iter().enumerate().collect(),
|
pronouns: settings.pronoun_list.iter().enumerate().collect(),
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
|
@ -33,7 +33,6 @@ async fn create_link(
|
||||||
settings: web::Data<InstanceSettings>,
|
settings: web::Data<InstanceSettings>,
|
||||||
form: web::Form<HashMap<String, String>>,
|
form: web::Form<HashMap<String, String>>,
|
||||||
) -> Result<impl Responder> {
|
) -> Result<impl Responder> {
|
||||||
eprintln!("create {:?}", form);
|
|
||||||
let mut weights = vec![0; settings.pronoun_list.len()];
|
let mut weights = vec![0; settings.pronoun_list.len()];
|
||||||
for (k, v) in form.iter() {
|
for (k, v) in form.iter() {
|
||||||
if let Ok(i) = k.parse::<usize>() {
|
if let Ok(i) = k.parse::<usize>() {
|
||||||
|
@ -44,9 +43,7 @@ async fn create_link(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let prefs = InstanceSettings::create_preferences(&weights);
|
let prefs = InstanceSettings::create_preferences(&weights);
|
||||||
eprintln!("prefs: {:?}", prefs);
|
|
||||||
let pref_string = prefs.as_prefstring();
|
let pref_string = prefs.as_prefstring();
|
||||||
eprintln!("prefstring: {}", pref_string);
|
|
||||||
let url = match form.get("name") {
|
let url = match form.get("name") {
|
||||||
Some(name) if !name.is_empty() => format!("/{}/{}", name, pref_string),
|
Some(name) if !name.is_empty() => format!("/{}/{}", name, pref_string),
|
||||||
_ => format!("/{}", pref_string),
|
_ => format!("/{}", pref_string),
|
||||||
|
@ -58,7 +55,6 @@ async fn create_link(
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn default(settings: web::Data<InstanceSettings>) -> Result<impl Responder> {
|
async fn default(settings: web::Data<InstanceSettings>) -> Result<impl Responder> {
|
||||||
eprintln!("default");
|
|
||||||
let pronoun = settings
|
let pronoun = settings
|
||||||
.select_pronouns(None, None)
|
.select_pronouns(None, None)
|
||||||
.map_err(|_| Error::InvlaidPrefString)?;
|
.map_err(|_| Error::InvlaidPrefString)?;
|
||||||
|
@ -72,7 +68,6 @@ async fn only_prefs(
|
||||||
web::Path(prefs): web::Path<String>,
|
web::Path(prefs): web::Path<String>,
|
||||||
settings: web::Data<InstanceSettings>,
|
settings: web::Data<InstanceSettings>,
|
||||||
) -> Result<impl Responder> {
|
) -> Result<impl Responder> {
|
||||||
eprintln!("prefs {}", prefs);
|
|
||||||
let pronoun = settings
|
let pronoun = settings
|
||||||
.select_pronouns(None, Some(&prefs))
|
.select_pronouns(None, Some(&prefs))
|
||||||
.map_err(|_| Error::InvlaidPrefString)?;
|
.map_err(|_| Error::InvlaidPrefString)?;
|
||||||
|
@ -86,7 +81,6 @@ async fn prefs_and_name(
|
||||||
web::Path((name, prefs)): web::Path<(String, String)>,
|
web::Path((name, prefs)): web::Path<(String, String)>,
|
||||||
settings: web::Data<InstanceSettings>,
|
settings: web::Data<InstanceSettings>,
|
||||||
) -> Result<impl Responder> {
|
) -> Result<impl Responder> {
|
||||||
eprintln!("prefs+name");
|
|
||||||
let pronoun = settings
|
let pronoun = settings
|
||||||
.select_pronouns(Some(&name), Some(&prefs))
|
.select_pronouns(Some(&name), Some(&prefs))
|
||||||
.map_err(|_| Error::InvlaidPrefString)?;
|
.map_err(|_| Error::InvlaidPrefString)?;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>My Pronouns Today</title>
|
<title>{% if name.is_some() %} {{ name.as_ref().unwrap() }}'s {% else %}
|
||||||
|
My{% endif %} Pronouns Today</title>
|
||||||
<style>
|
<style>
|
||||||
#form {
|
#form {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -11,13 +12,28 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>
|
<h1>{% if name.is_some() %} {{ name.as_ref().unwrap() }}'s {% else %}
|
||||||
{% if name.is_some() %}
|
My{% endif %} pronouns today are: {{ pronoun.render_threeform() }}</h1>
|
||||||
{{ name.as_ref().unwrap() }}
|
|
||||||
{% else %}
|
<p>This page picks a random pronoun from a list of preferred pronouns every
|
||||||
My
|
day.
|
||||||
{% endif %}
|
{% if name.is_some() %} {{ name.as_ref().unwrap() }}{% else %}
|
||||||
pronouns today are: {{ short }}</h1>
|
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>
|
<label for="form-toggle">Create your own custom link!</label>
|
||||||
<input type="checkbox" id="form-toggle" style="display: none;"/>
|
<input type="checkbox" id="form-toggle" style="display: none;"/>
|
||||||
|
|
Loading…
Reference in a new issue