feat: extracts {{prompt}} out from {{form}} as a separate element
This commit is contained in:
parent
2e0002a810
commit
4807104eb1
5 changed files with 29 additions and 13 deletions
|
|
@ -84,7 +84,7 @@
|
|||
# Message textarea height in pixels.
|
||||
# BOOK_TEXTAREA_HEIGHT=150
|
||||
|
||||
# Custom HTML template file with {{title}}, {{form}}, {{entries}}, and {{style}} placeholders.
|
||||
# Custom HTML template file with {{title}}, {{prompt}}, {{form}}, {{entries}}, and {{style}} placeholders.
|
||||
# Uses built-in default if unset.
|
||||
# BOOK_TEMPLATE=./templates/default.html
|
||||
|
||||
|
|
|
|||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -458,7 +458,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "guestbook"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -175,7 +175,7 @@ Running `guestbook` with no env vars will give you a working guestbook on `local
|
|||
# Message textarea height in pixels.
|
||||
# BOOK_TEXTAREA_HEIGHT=150
|
||||
|
||||
# Custom HTML template file with {{title}}, {{form}}, {{entries}}, and {{style}} placeholders.
|
||||
# Custom HTML template file with {{title}}, {{prompt}}, {{form}}, {{entries}}, and {{style}} placeholders.
|
||||
# Uses built-in default if unset.
|
||||
# BOOK_TEMPLATE=./templates/default.html
|
||||
|
||||
|
|
@ -344,10 +344,13 @@ The `status` field can be `pending`, `approved`, or `denied`. Only approved entr
|
|||
Available placeholders:
|
||||
|
||||
title - Site title (BOOK_SITE_TITLE). Useful in <title> and headings.
|
||||
prompt - The form prompt text (BOOK_FORM_PROMPT), wrapped in a
|
||||
<span class="guestbook-prompt">. Empty when submissions
|
||||
are disabled. Place anywhere relative to the form.
|
||||
form - The submission form (labels, inputs, button). Controlled by
|
||||
BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE,
|
||||
BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_WIDTH,
|
||||
BOOK_TEXTAREA_HEIGHT. Empty when BOOK_ENABLE_SUBMISSIONS=false.
|
||||
BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE, BOOK_LABEL_MESSAGE,
|
||||
BOOK_BUTTON_TEXT, BOOK_TEXTAREA_WIDTH, BOOK_TEXTAREA_HEIGHT.
|
||||
Empty when BOOK_ENABLE_SUBMISSIONS=false.
|
||||
entries - Approved guestbook entries, newest first. Entry separator
|
||||
controlled by BOOK_SEPARATOR.
|
||||
style - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in
|
||||
|
|
@ -370,6 +373,7 @@ The `status` field can be `pending`, `approved`, or `denied`. Only approved entr
|
|||
guestbook
|
||||
=========
|
||||
|
||||
{{prompt}}
|
||||
{{form}}
|
||||
|
||||
entries
|
||||
|
|
|
|||
|
|
@ -13,8 +13,17 @@ pub fn render_page(template: &str, config: &Config, entries: &[Entry], form_html
|
|||
&config.style
|
||||
};
|
||||
let style = format!("<style>\n{css}\n </style>");
|
||||
let prompt = if config.enable_submissions {
|
||||
format!(
|
||||
"<span class=\"guestbook-prompt\">{}</span>",
|
||||
config.form_prompt
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
template
|
||||
.replace("{{title}}", &config.site_title)
|
||||
.replace("{{prompt}}", &prompt)
|
||||
.replace("{{form}}", form_html)
|
||||
.replace("{{entries}}", &entries_html)
|
||||
.replace("{{style}}", &style)
|
||||
|
|
@ -174,8 +183,7 @@ pub fn render_form(config: &Config) -> String {
|
|||
};
|
||||
|
||||
format!(
|
||||
r#"<span class="guestbook-prompt">{prompt}</span>
|
||||
<form class="guestbook-form" method="post" action="/submit" accept-charset="UTF-8">
|
||||
r#"<form class="guestbook-form" method="post" action="/submit" accept-charset="UTF-8">
|
||||
<label class="guestbook-label" for="name">{label_name}</label>
|
||||
<input class="guestbook-input" id="name" name="name" required>
|
||||
{website_section}
|
||||
|
|
@ -184,7 +192,6 @@ pub fn render_form(config: &Config) -> String {
|
|||
{captcha_section}
|
||||
{drawing_section}{voice_note_section}<input name="url" aria-hidden="true" style="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)" tabindex="-1" autocomplete="off"><button class="guestbook-button" type="submit">{button}</button>
|
||||
</form>"#,
|
||||
prompt = config.form_prompt,
|
||||
label_name = config.label_name,
|
||||
website_section = website_section,
|
||||
label_message = config.label_message,
|
||||
|
|
@ -437,7 +444,8 @@ mod tests {
|
|||
config.button_text = "submit".into();
|
||||
config.label_name = "Name:".into();
|
||||
let form = render_form(&config);
|
||||
assert!(form.contains("Leave a note!"));
|
||||
let html = render_page(DEFAULT_TEMPLATE, &config, &[], &form);
|
||||
assert!(html.contains("Leave a note!"));
|
||||
assert!(form.contains("submit"));
|
||||
assert!(form.contains("Name:"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,13 @@
|
|||
Available placeholders:
|
||||
|
||||
title - Site title (BOOK_SITE_TITLE). Useful in <title> and headings.
|
||||
prompt - The form prompt text (BOOK_FORM_PROMPT), wrapped in a
|
||||
<span class="guestbook-prompt">. Empty when submissions
|
||||
are disabled. Place anywhere relative to the form.
|
||||
form - The submission form (labels, inputs, button). Controlled by
|
||||
BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE,
|
||||
BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_WIDTH,
|
||||
BOOK_TEXTAREA_HEIGHT. Empty when BOOK_ENABLE_SUBMISSIONS=false.
|
||||
BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE, BOOK_LABEL_MESSAGE,
|
||||
BOOK_BUTTON_TEXT, BOOK_TEXTAREA_WIDTH, BOOK_TEXTAREA_HEIGHT.
|
||||
Empty when BOOK_ENABLE_SUBMISSIONS=false.
|
||||
entries - Approved guestbook entries, newest first. Entry separator
|
||||
controlled by BOOK_SEPARATOR.
|
||||
style - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in
|
||||
|
|
@ -33,6 +36,7 @@
|
|||
guestbook
|
||||
=========
|
||||
|
||||
{{prompt}}
|
||||
{{form}}
|
||||
|
||||
entries
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue