Rename write_html!
to html!
It's more concise
This commit is contained in:
parent
ab45846e1e
commit
28b1624f4c
3 changed files with 24 additions and 24 deletions
|
@ -36,6 +36,6 @@ fn expand_html_debug<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) ->
|
||||||
|
|
||||||
#[plugin_registrar]
|
#[plugin_registrar]
|
||||||
pub fn plugin_registrar(reg: &mut Registry) {
|
pub fn plugin_registrar(reg: &mut Registry) {
|
||||||
reg.register_macro("write_html", expand_html);
|
reg.register_macro("html", expand_html);
|
||||||
reg.register_macro("write_html_debug", expand_html_debug);
|
reg.register_macro("html_debug", expand_html_debug);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ fn split_comma<'a>(cx: &ExtCtxt, input: &'a [TokenTree], sp: Span) -> (&'a [Toke
|
||||||
}
|
}
|
||||||
match input.iter().position(is_comma) {
|
match input.iter().position(is_comma) {
|
||||||
Some(i) => (&input[..i], &input[1+i..]),
|
Some(i) => (&input[..i], &input[1+i..]),
|
||||||
None => cx.span_fatal(sp, "expected two arguments to write_html!()"),
|
None => cx.span_fatal(sp, "expected two arguments to `html!`"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,21 @@ extern crate maud;
|
||||||
#[test]
|
#[test]
|
||||||
fn literals() {
|
fn literals() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, "du\tcks" -23 3.14 '\n' "geese").unwrap();
|
html!(s, "du\tcks" -23 3.14 '\n' "geese").unwrap();
|
||||||
assert_eq!(s, "du\tcks-233.14\ngeese");
|
assert_eq!(s, "du\tcks-233.14\ngeese");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn escaping() {
|
fn escaping() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, "<flim&flam>").unwrap();
|
html!(s, "<flim&flam>").unwrap();
|
||||||
assert_eq!(s, "<flim&flam>");
|
assert_eq!(s, "<flim&flam>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn semicolons() {
|
fn semicolons() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
"one";
|
"one";
|
||||||
"two";
|
"two";
|
||||||
"three";
|
"three";
|
||||||
|
@ -33,7 +33,7 @@ fn semicolons() {
|
||||||
#[test]
|
#[test]
|
||||||
fn blocks() {
|
fn blocks() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
"hello"
|
"hello"
|
||||||
{
|
{
|
||||||
" ducks" " geese"
|
" ducks" " geese"
|
||||||
|
@ -47,28 +47,28 @@ mod elements {
|
||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, p { b { "pickle" } "barrel" i { "kumquat" } }).unwrap();
|
html!(s, p { b { "pickle" } "barrel" i { "kumquat" } }).unwrap();
|
||||||
assert_eq!(s, "<p><b>pickle</b>barrel<i>kumquat</i></p>");
|
assert_eq!(s, "<p><b>pickle</b>barrel<i>kumquat</i></p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nesting() {
|
fn nesting() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, html body div p sup "butts").unwrap();
|
html!(s, html body div p sup "butts").unwrap();
|
||||||
assert_eq!(s, "<html><body><div><p><sup>butts</sup></p></div></body></html>");
|
assert_eq!(s, "<html><body><div><p><sup>butts</sup></p></div></body></html>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty() {
|
fn empty() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, "pinkie" br/ "pie").unwrap();
|
html!(s, "pinkie" br/ "pie").unwrap();
|
||||||
assert_eq!(s, "pinkie<br>pie");
|
assert_eq!(s, "pinkie<br>pie");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn attributes() {
|
fn attributes() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
link rel="stylesheet" href="styles.css"/
|
link rel="stylesheet" href="styles.css"/
|
||||||
section id="midriff" {
|
section id="midriff" {
|
||||||
p class="hotpink" "Hello!"
|
p class="hotpink" "Hello!"
|
||||||
|
@ -82,7 +82,7 @@ mod elements {
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_attributes() {
|
fn empty_attributes() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, div readonly? input type="checkbox" checked? /).unwrap();
|
html!(s, div readonly? input type="checkbox" checked? /).unwrap();
|
||||||
assert_eq!(s, r#"<div readonly><input type="checkbox" checked></div>"#);
|
assert_eq!(s, r#"<div readonly><input type="checkbox" checked></div>"#);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,21 +91,21 @@ mod splices {
|
||||||
#[test]
|
#[test]
|
||||||
fn literals() {
|
fn literals() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $"<pinkie>").unwrap();
|
html!(s, $"<pinkie>").unwrap();
|
||||||
assert_eq!(s, "<pinkie>");
|
assert_eq!(s, "<pinkie>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn raw_literals() {
|
fn raw_literals() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $$"<pinkie>").unwrap();
|
html!(s, $$"<pinkie>").unwrap();
|
||||||
assert_eq!(s, "<pinkie>");
|
assert_eq!(s, "<pinkie>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn blocks() {
|
fn blocks() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
${
|
${
|
||||||
let mut result = 1i32;
|
let mut result = 1i32;
|
||||||
for i in 2..11 {
|
for i in 2..11 {
|
||||||
|
@ -121,7 +121,7 @@ mod splices {
|
||||||
fn attributes() {
|
fn attributes() {
|
||||||
let rocks = true;
|
let rocks = true;
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
input checked?=true /
|
input checked?=true /
|
||||||
input checked?=false /
|
input checked?=false /
|
||||||
input checked?=rocks /
|
input checked?=rocks /
|
||||||
|
@ -139,7 +139,7 @@ mod splices {
|
||||||
#[test]
|
#[test]
|
||||||
fn statics() {
|
fn statics() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $BEST_PONY).unwrap();
|
html!(s, $BEST_PONY).unwrap();
|
||||||
assert_eq!(s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ mod splices {
|
||||||
fn closures() {
|
fn closures() {
|
||||||
let best_pony = "Pinkie Pie";
|
let best_pony = "Pinkie Pie";
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $best_pony).unwrap();
|
html!(s, $best_pony).unwrap();
|
||||||
assert_eq!(s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ mod splices {
|
||||||
adorableness: 9,
|
adorableness: 9,
|
||||||
};
|
};
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
"Name: " $pinkie.name ". Rating: " $pinkie.repugnance()
|
"Name: " $pinkie.name ". Rating: " $pinkie.repugnance()
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
assert_eq!(s, "Name: Pinkie Pie. Rating: 1");
|
assert_eq!(s, "Name: Pinkie Pie. Rating: 1");
|
||||||
|
@ -183,7 +183,7 @@ mod splices {
|
||||||
fn nested_macro_invocation() {
|
fn nested_macro_invocation() {
|
||||||
let best_pony = "Pinkie Pie";
|
let best_pony = "Pinkie Pie";
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $(format!("{}", best_pony))).unwrap();
|
html!(s, $(format!("{}", best_pony))).unwrap();
|
||||||
assert_eq!(s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ mod splices {
|
||||||
fn issue_13() {
|
fn issue_13() {
|
||||||
let owned = String::from("yay");
|
let owned = String::from("yay");
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, $owned).unwrap();
|
html!(s, $owned).unwrap();
|
||||||
let _ = owned;
|
let _ = owned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ mod control {
|
||||||
fn if_expr() {
|
fn if_expr() {
|
||||||
for (number, &name) in (1..4).zip(["one", "two", "three"].iter()) {
|
for (number, &name) in (1..4).zip(["one", "two", "three"].iter()) {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
$if number == 1 {
|
$if number == 1 {
|
||||||
"one"
|
"one"
|
||||||
} $else if number == 2 {
|
} $else if number == 2 {
|
||||||
|
@ -220,7 +220,7 @@ mod control {
|
||||||
fn if_let() {
|
fn if_let() {
|
||||||
for &(input, output) in [(Some("yay"), "yay"), (None, "oh noes")].iter() {
|
for &(input, output) in [(Some("yay"), "yay"), (None, "oh noes")].iter() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
$if let Some(value) = input {
|
$if let Some(value) = input {
|
||||||
$value
|
$value
|
||||||
} $else {
|
} $else {
|
||||||
|
@ -235,7 +235,7 @@ mod control {
|
||||||
fn for_expr() {
|
fn for_expr() {
|
||||||
let ponies = ["Apple Bloom", "Scootaloo", "Sweetie Belle"];
|
let ponies = ["Apple Bloom", "Scootaloo", "Sweetie Belle"];
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
write_html!(s, {
|
html!(s, {
|
||||||
ul $for pony in &ponies {
|
ul $for pony in &ponies {
|
||||||
li $pony
|
li $pony
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue