Use the Escaper struct directly
It's internal anyway, so meh
This commit is contained in:
parent
4da9272494
commit
40424e283c
2 changed files with 7 additions and 11 deletions
|
@ -7,8 +7,9 @@ use std::io::{IoError, IoErrorKind, IoResult};
|
|||
|
||||
/// Escape an HTML value.
|
||||
pub fn escape(s: &str) -> String {
|
||||
use std::fmt::Writer;
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -71,8 +72,8 @@ pub mod rt {
|
|||
write!(w, "{}", value)
|
||||
}
|
||||
|
||||
struct Escaper<'a, 'b: 'a> {
|
||||
inner: &'a mut (fmt::Writer + 'b),
|
||||
pub struct Escaper<'a, 'b: 'a> {
|
||||
pub inner: &'a mut (fmt::Writer + 'b),
|
||||
}
|
||||
|
||||
impl<'a, 'b> fmt::Writer for Escaper<'a, 'b> {
|
||||
|
@ -90,11 +91,4 @@ pub mod rt {
|
|||
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 })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@ impl<'cx, 's, 'o> Renderer<'cx, 's, 'o> {
|
|||
quote_expr!(self.cx, ::maud::rt::write_fmt($w, $expr)),
|
||||
Escape::Escape =>
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue