parent
d8b76db92f
commit
46fab1372b
3 changed files with 6 additions and 18 deletions
|
@ -79,16 +79,6 @@ pub mod rt {
|
|||
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 inner: &'a mut (fmt::Write + 'b),
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ impl<'cx> Renderer<'cx> {
|
|||
let Renderer { cx, w, stmts, .. } = { self.flush(); self };
|
||||
quote_expr!(cx,
|
||||
::maud::rt::make_markup(|$w: &mut ::std::fmt::Write| -> Result<(), ::std::fmt::Error> {
|
||||
use ::std::fmt::Write;
|
||||
$stmts
|
||||
Ok(())
|
||||
}))
|
||||
|
@ -96,12 +97,13 @@ impl<'cx> Renderer<'cx> {
|
|||
let w = self.w;
|
||||
let expr = match escape {
|
||||
Escape::PassThru =>
|
||||
quote_expr!(self.cx, ::maud::rt::write_fmt($w, &$expr)),
|
||||
quote_expr!(self.cx, write!($w, "{}", $expr)),
|
||||
Escape::Escape =>
|
||||
quote_expr!(self.cx,
|
||||
::maud::rt::write_fmt(
|
||||
&mut ::maud::rt::Escaper { inner: $w },
|
||||
&$expr)),
|
||||
write!(
|
||||
::maud::rt::Escaper { inner: $w },
|
||||
"{}",
|
||||
$expr)),
|
||||
};
|
||||
let stmt = self.cx.stmt_expr(self.cx.expr_try(expr.span, expr));
|
||||
self.push(stmt);
|
||||
|
|
|
@ -165,16 +165,12 @@ mod splices {
|
|||
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]
|
||||
fn nested_macro_invocation() {
|
||||
let best_pony = "Pinkie Pie";
|
||||
let s = html! { $(format!("{}", best_pony)) }.to_string();
|
||||
assert_eq!(s, "Pinkie Pie");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Reference in a new issue