Debugging

For debugging purposes, Maud provides an alternative macro named html_debug!. This macro expands to the same expression as html!, but prints extra diagnostics during compilation.

For example, if we build this code:

#![feature(proc_macro)]

extern crate maud;

use maud::html_debug;

fn main() {
    let name = "Lyra";
    let markup = html_debug! {
        p { "Hi, " (name) "!" }
    };
    println!("{}", markup.into_string());
}

We then get:

$ cargo build
   Compiling lyra v0.1.0 (file:///home/chris/dev/maud/lyra)
expansion:
{
extern crate maud ; let mut __maud_output = String :: with_capacity (
25u64 as usize ) ; __maud_output . push_str ( "\u{3c}\u{70}\u{3e}" ) ; {
__maud_output . push_str ( "\u{48}\u{69}\u{2c}\u{20}" ) ; {
extern crate maud ; trait Render : maud :: Render {
fn render_to ( & self , output : & mut String ) {
maud :: Render :: render_to ( self , output ) ; } } impl < T : maud :: Render
> Render for T {  } name . render_to ( & mut __maud_output ) ; } __maud_output
. push_str ( "\u{21}" ) ; } __maud_output . push_str (
"\u{3c}\u{2f}\u{70}\u{3e}" ) ; maud :: PreEscaped ( __maud_output ) }
    Finished dev [unoptimized + debuginfo] target(s) in 0.48 secs

After piping through rustfmt, we get the following code:

{
    extern crate maud ;
    let mut __maud_output = String::with_capacity(25u64 as usize);
    __maud_output.push_str("\u{3c}\u{70}\u{3e}");
    {
        __maud_output.push_str("\u{48}\u{69}\u{2c}\u{20}");
        {
            extern crate maud ;
            trait Render: maud::Render {
                fn render_to(&self, output: &mut String) {
                    maud::Render::render_to(self, output);
                }
            }
            impl<T: maud::Render> Render for T {}
            name.render_to(&mut __maud_output);
        }
        __maud_output.push_str("\u{21}");
    }
    __maud_output.push_str("\u{3c}\u{2f}\u{70}\u{3e}");
    maud::PreEscaped(__maud_output)
}

Wunderbar!

results matching ""

    No results matching ""