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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
pub struct Fortune {
pub id: i32,
pub message: &'static str,
}
markup::define! {
Define<'a>(fortunes: &'a [Fortune]) {
@let fortunes = *fortunes;
{markup::doctype()}
html {
head {
title { "Fortunes" }
}
body {
table {
tr { th { "id" } th { "message" } }
@for item in fortunes {
tr {
td { @item.id }
td { @item.message }
}
}
}
}
}
}
}
pub fn new(fortunes: &[Fortune]) -> impl std::fmt::Display + '_ {
markup::new! {
{markup::doctype()}
html {
head {
title { "Fortunes" }
}
body {
table {
tr { th { "id" } th { "message" } }
@for item in fortunes {
tr {
td { @item.id }
td { @item.message }
}
}
}
}
}
}
}
pub static FORTUNES: &[Fortune] = &[
Fortune {
id: 1,
message: "fortune: No such file or directory",
},
Fortune {
id: 2,
message: "A computer scientist is someone who fixes things that aren\'t broken.",
},
Fortune {
id: 3,
message: "After enough decimal places, nobody gives a damn.",
},
Fortune {
id: 4,
message: "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1",
},
Fortune {
id: 5,
message: "A computer program does what you tell it to do, not what you want it to do.",
},
Fortune {
id: 6,
message: "Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen",
},
Fortune {
id: 7,
message: "Any program that runs right is obsolete.",
},
Fortune {
id: 8,
message: "A list is only as strong as its weakest link. — Donald Knuth",
},
Fortune {
id: 9,
message: "Feature: A bug with seniority.",
},
Fortune {
id: 10,
message: "Computers make very fast, very accurate mistakes.",
},
Fortune {
id: 11,
message:
"<script>alert(\"This should not be displayed in a browser alert box.\");</script>",
},
Fortune {
id: 12,
message: "フレームワークのベンチマーク",
},
];
#[allow(dead_code)]
pub fn main() {
println!("{}", Define { fortunes: FORTUNES });
}
#[test]
fn t() {
let define = Define { fortunes: FORTUNES }.to_string();
let new = new(FORTUNES).to_string();
assert_eq!(define.len(), 1153);
assert_eq!(define, new);
}
|