utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.
Apache License 2.0
363 stars 15 forks source link

Syntax Question #7

Closed AblatedSprocket closed 4 years ago

AblatedSprocket commented 4 years ago

I really like this crate and I want to use it in my projects, but I'm getting a syntax error I'm having trouble debugging. I see that this repo hasn't seen much activity lately but I'm hoping this gets seen.

My template:

const BASE_DIR: &str = "/foo/bar";
Markup::define! {
    Home {
        {markup::doctype()}
        html [lang="en"] {
            body {
                @match {fs::read_dir(BASE_DIR)} {
                    Ok(dirs) => {
                        @for dir in dirs {
                            @match {dir.ok()} {
                                Some(item) => if item.path().is_dir() {
                                    {item.file_name()}
                                }
                                None => {}
                            }
                        }
                    }
                    Err(error) => {}
                }
            }
        }
    }
}

The compiler says it's expecting an identifier at @match {dir.is_ok()} {. I googled around but couldn't find anything about this. Any help would be appreciated.

utkarshkukreti commented 4 years ago

Could you try changing @for dir in dirs to @for dir in {dirs} in the previous line?

Btw, syn now includes a function to fix this {} hack this crate requires: https://github.com/dtolnay/syn/pull/848. I'll see if I can work on using it soon.

AblatedSprocket commented 4 years ago

I tried that, but it didn't work. After playing with dereferencing different things like you do in the documentation, I eventually was able to resolve it by calling .into_iter() on dirs in the for statement. I was expecting a different compiler message for this type of error.

EDIT: I'm really enjoying this crate, thanks for putting the time into this. It's a little hard to debug, but it's so worth it for everything it lets you do.

utkarshkukreti commented 4 years ago

This was fixed in this commit: https://github.com/utkarshkukreti/markup.rs/commit/77c56b2677cab14780b231cbb70ef9db176a7c10 on Aug 7, forgot to refer to this issue. Let me know if something still doesn't work!