parent
d8b76db92f
commit
46fab1372b
3 changed files with 6 additions and 18 deletions
|
@ -79,16 +79,6 @@ pub mod rt {
|
||||||
Markup { callback: f }
|
Markup { callback: f }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// rustc is a butt and doesn't let us quote macro invocations
|
|
||||||
/// directly. So we factor the `write!` call into a separate
|
|
||||||
/// function and use that instead.
|
|
||||||
///
|
|
||||||
/// See <https://github.com/rust-lang/rust/issues/16617>
|
|
||||||
#[inline]
|
|
||||||
pub fn write_fmt<T: fmt::Display>(w: &mut fmt::Write, value: &T) -> fmt::Result {
|
|
||||||
write!(w, "{}", *value)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Escaper<'a, 'b: 'a> {
|
pub struct Escaper<'a, 'b: 'a> {
|
||||||
pub inner: &'a mut (fmt::Write + 'b),
|
pub inner: &'a mut (fmt::Write + 'b),
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ impl<'cx> Renderer<'cx> {
|
||||||
let Renderer { cx, w, stmts, .. } = { self.flush(); self };
|
let Renderer { cx, w, stmts, .. } = { self.flush(); self };
|
||||||
quote_expr!(cx,
|
quote_expr!(cx,
|
||||||
::maud::rt::make_markup(|$w: &mut ::std::fmt::Write| -> Result<(), ::std::fmt::Error> {
|
::maud::rt::make_markup(|$w: &mut ::std::fmt::Write| -> Result<(), ::std::fmt::Error> {
|
||||||
|
use ::std::fmt::Write;
|
||||||
$stmts
|
$stmts
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
@ -96,12 +97,13 @@ impl<'cx> Renderer<'cx> {
|
||||||
let w = self.w;
|
let w = self.w;
|
||||||
let expr = match escape {
|
let expr = match escape {
|
||||||
Escape::PassThru =>
|
Escape::PassThru =>
|
||||||
quote_expr!(self.cx, ::maud::rt::write_fmt($w, &$expr)),
|
quote_expr!(self.cx, write!($w, "{}", $expr)),
|
||||||
Escape::Escape =>
|
Escape::Escape =>
|
||||||
quote_expr!(self.cx,
|
quote_expr!(self.cx,
|
||||||
::maud::rt::write_fmt(
|
write!(
|
||||||
&mut ::maud::rt::Escaper { inner: $w },
|
::maud::rt::Escaper { inner: $w },
|
||||||
&$expr)),
|
"{}",
|
||||||
|
$expr)),
|
||||||
};
|
};
|
||||||
let stmt = self.cx.stmt_expr(self.cx.expr_try(expr.span, expr));
|
let stmt = self.cx.stmt_expr(self.cx.expr_try(expr.span, expr));
|
||||||
self.push(stmt);
|
self.push(stmt);
|
||||||
|
|
|
@ -165,16 +165,12 @@ mod splices {
|
||||||
assert_eq!(s, "Name: Pinkie Pie. Rating: 1");
|
assert_eq!(s, "Name: Pinkie Pie. Rating: 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: See <https://github.com/rust-lang/rust/issues/16617>
|
|
||||||
// for why this is commented out
|
|
||||||
/*
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nested_macro_invocation() {
|
fn nested_macro_invocation() {
|
||||||
let best_pony = "Pinkie Pie";
|
let best_pony = "Pinkie Pie";
|
||||||
let s = html! { $(format!("{}", best_pony)) }.to_string();
|
let s = html! { $(format!("{}", best_pony)) }.to_string();
|
||||||
assert_eq!(s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Reference in a new issue