Use the Escaper struct directly

It's internal anyway, so meh
This commit is contained in:
Chris Wong 2015-01-17 20:52:09 +13:00
parent 4da9272494
commit 40424e283c
2 changed files with 7 additions and 11 deletions
maud/src
maud_macros/src

View file

@ -7,8 +7,9 @@ use std::io::{IoError, IoErrorKind, IoResult};
/// Escape an HTML value. /// Escape an HTML value.
pub fn escape(s: &str) -> String { pub fn escape(s: &str) -> String {
use std::fmt::Writer;
let mut buf = String::new(); let mut buf = String::new();
rt::escape(&mut buf, |w| w.write_str(s)).unwrap(); rt::Escaper { inner: &mut buf }.write_str(s).unwrap();
buf buf
} }
@ -71,8 +72,8 @@ pub mod rt {
write!(w, "{}", value) write!(w, "{}", value)
} }
struct Escaper<'a, 'b: 'a> { pub struct Escaper<'a, 'b: 'a> {
inner: &'a mut (fmt::Writer + 'b), pub inner: &'a mut (fmt::Writer + 'b),
} }
impl<'a, 'b> fmt::Writer for Escaper<'a, 'b> { impl<'a, 'b> fmt::Writer for Escaper<'a, 'b> {
@ -90,11 +91,4 @@ pub mod rt {
Ok(()) Ok(())
} }
} }
#[inline]
pub fn escape<F>(w: &mut fmt::Writer, f: F) -> fmt::Result where
F: FnOnce(&mut fmt::Writer) -> fmt::Result
{
f(&mut Escaper { inner: w })
}
} }

View file

@ -71,7 +71,9 @@ impl<'cx, 's, 'o> Renderer<'cx, 's, 'o> {
quote_expr!(self.cx, ::maud::rt::write_fmt($w, $expr)), quote_expr!(self.cx, ::maud::rt::write_fmt($w, $expr)),
Escape::Escape => Escape::Escape =>
quote_expr!(self.cx, quote_expr!(self.cx,
::maud::rt::escape($w, |w| ::maud::rt::write_fmt(w, $expr))), ::maud::rt::write_fmt(
&mut ::maud::rt::Escaper { inner: $w },
$expr)),
}; };
self.push(expr); self.push(expr);
} }