| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
use makeover_layout as layout; |
| 62 |
use quasi_declare::declare; |
| 63 |
use quasi_router::{Document, Request, Response, RouteError}; |
| 64 |
use quasi_webview::Webview; |
| 65 |
|
| 66 |
|
| 67 |
pub const PATH: &str = "/policy"; |
| 68 |
|
| 69 |
|
| 70 |
pub const PAGE_REGION: &str = "policy"; |
| 71 |
|
| 72 |
const MEASURE: layout::Measure = layout::Measure::Wide; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
pub fn screen(_viewer: &super::Viewer, _request: Request) -> Result<Response, RouteError> { |
| 82 |
Ok(page_screen().into()) |
| 83 |
} |
| 84 |
|
| 85 |
declare! { |
| 86 |
|
| 87 |
pub(crate) shape page_screen() -> Screen; |
| 88 |
|
| 89 |
screen single "Content Policy - Makenotwork" { |
| 90 |
measured MEASURE; |
| 91 |
documented Document::default().classed(crate::shell::body_class(MEASURE, &["policy-page"])); |
| 92 |
summarised "What belongs on Makenotwork, what doesn't, and how problems are handled."; |
| 93 |
|
| 94 |
include page_region(); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
declare! { |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
#[staged] |
| 107 |
pub(crate) shape page_region() -> Slot; |
| 108 |
|
| 109 |
region PAGE_REGION as Pane { |
| 110 |
page "Content Policy"; |
| 111 |
text "Makenotwork exists so creators can sell their work on fair terms. This policy \ |
| 112 |
describes what belongs here, what doesn't, and how we handle problems."; |
| 113 |
|
| 114 |
for part in copy "content/policy.toml" as sections { |
| 115 |
section part.heading; |
| 116 |
include super::own_prose(part.body); |
| 117 |
} |
| 118 |
|
| 119 |
section "Other Policies"; |
| 120 |
list { |
| 121 |
for other in copy "content/policy.toml" as others { |
| 122 |
row other.title { |
| 123 |
secondary other.covers; |
| 124 |
act "Read" to get other.route navigating; |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
section "Questions"; |
| 130 |
for closing in copy "content/policy.toml" as closing { |
| 131 |
include super::own_prose(closing.body); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
#[must_use] |
| 139 |
pub fn renderer(viewer: &super::Viewer) -> Webview { |
| 140 |
Webview::new().with_shell(viewer.document_shell().with_body_first(format!( |
| 141 |
"{}{}", |
| 142 |
crate::shell::skip_link(PAGE_REGION), |
| 143 |
crate::shell::site_header(viewer.user.as_ref()), |
| 144 |
))) |
| 145 |
} |
| 146 |
|
| 147 |
#[cfg(test)] |
| 148 |
mod tests { |
| 149 |
use super::*; |
| 150 |
|
| 151 |
fn html() -> String { |
| 152 |
use quasi_axum::Serves as _; |
| 153 |
|
| 154 |
Webview::new().screen(&page_screen()) |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
#[test] |
| 160 |
fn the_document_carries_the_classes_the_template_carried() { |
| 161 |
let screen = page_screen(); |
| 162 |
|
| 163 |
assert_eq!( |
| 164 |
screen.document.body_class.as_deref(), |
| 165 |
Some("padded-page policy-page") |
| 166 |
); |
| 167 |
assert!( |
| 168 |
html().contains("class=\"padded-page policy-page\""), |
| 169 |
"{}", |
| 170 |
html() |
| 171 |
); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
#[test] |
| 178 |
fn the_prose_keeps_its_inline_link_and_its_emphasis() { |
| 179 |
let html = html(); |
| 180 |
|
| 181 |
assert!( |
| 182 |
html.contains(r#"href="/docs/guarantees""#), |
| 183 |
"the creator-guarantees link did not survive: {html}" |
| 184 |
); |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
assert!( |
| 189 |
!html.contains("nofollow"), |
| 190 |
"the policy page nofollowed its own documents: {html}" |
| 191 |
); |
| 192 |
assert!( |
| 193 |
html.contains("<strong>reports@makenot.work</strong>") |
| 194 |
|| html.contains("<b>reports@makenot.work</b>"), |
| 195 |
"the reports address lost its emphasis: {html}" |
| 196 |
); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
fn copy() -> toml::Table { |
| 206 |
include_str!("../../content/policy.toml") |
| 207 |
.parse() |
| 208 |
.expect("the policy copy is TOML") |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
#[test] |
| 217 |
fn every_other_policy_keeps_its_row_and_its_route() { |
| 218 |
let html = html(); |
| 219 |
|
| 220 |
let copy = copy(); |
| 221 |
let others = copy["others"].as_array().expect("a list of documents"); |
| 222 |
assert_eq!(others.len(), 7, "the page pointed at seven documents"); |
| 223 |
for other in others { |
| 224 |
let title = other["title"].as_str().expect("a title"); |
| 225 |
let route = other["route"].as_str().expect("a route"); |
| 226 |
let escaped = crate::helpers::escape_html(title); |
| 227 |
assert!(html.contains(&escaped), "{title} missing"); |
| 228 |
assert!(html.contains(route), "{route} missing"); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
#[test] |
| 238 |
fn every_section_keeps_its_heading() { |
| 239 |
let html = html(); |
| 240 |
|
| 241 |
let copy = copy(); |
| 242 |
let sections = copy["sections"].as_array().expect("a list of sections"); |
| 243 |
assert_eq!(sections.len(), 5, "the page had five prose sections"); |
| 244 |
for section in sections { |
| 245 |
let heading = section["heading"].as_str().expect("a heading"); |
| 246 |
let escaped = crate::helpers::escape_html(heading); |
| 247 |
assert!(html.contains(&escaped), "{heading} missing"); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
#[test] |
| 255 |
fn both_contact_addresses_survive_and_stay_distinct() { |
| 256 |
let html = html(); |
| 257 |
|
| 258 |
assert!(html.contains("reports@makenot.work"), "{html}"); |
| 259 |
assert!(html.contains("policy@makenot.work"), "{html}"); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
#[test] |
| 264 |
fn the_page_spells_no_spinner() { |
| 265 |
let html = html(); |
| 266 |
|
| 267 |
for spelling in ["htmx-indicator", "spinner", "loading-text", "loading-state"] { |
| 268 |
assert!(!html.contains(spelling), "{spelling} survives in {html}"); |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
|