nickel-org / nickel.rs

An expressjs inspired web framework for Rust

Home Page:http://nickel-org.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Templating with mustache in nickel

freiguy1 opened this issue · comments

I'm attempting to use templating with nickel and mustache, which seems sort of built in. In this example it strongly suggests using nickel_mustache. However, the last commit to that repo was over a year ago. It doesn't seem to compile for me, so I'm not really sure what is going on. Nickel itself still looks active, but perhaps no one needs templating? Which seems very strange. Why is this the first issue on it? I'm sort of lost.

I thought it'd be best to paste my build issue with nickel_mustache:

   Compiling nickel v0.7.3
error: `$t:expr` is followed by `{`, which is not allowed for `expr` fragments
 --> C:\Users\freie\.cargo\registry\src\github.com-1ecc6299db9ec823\nickel-0.7.
\src\mimes.rs:5:16
  |
5 |     ($($t:expr { $($name:ident, $as_s:pat, $subt:expr,)+ })+) => (
  |                ^

error: aborting due to previous error

error: Could not compile `nickel`.

This is using rust 1.13.0

The build error shows nickel_mustache is using an old version of nickel... like over a year old.

Are you adding a dependency to nickel_mustache in your Cargo.toml? That shouldn't be necessary. I am using templates with just a dependency on nickel. Mustache is brought in by nickel itself.

Yeah, I was, because the comment in that example lead me to believe using templates this way was deprecated, and I should instead use nickel_mustache the way it's used in it's main example in its readme.

Is this comment just wrong?

// * NOTE *
// This example is deprecated, you should use nickel_mustache from crates.io

I think that nickel_mustache hasn't been maintained because it is not needed any more. As long as you use closures and the router!() macro, rather than functions, for the handlers, you can compile a template using any templating engine in your main function and use it from the handler. See https://github.com/nickel-org/nickel.rs/blob/master/examples/route_data.rs for how to use shared data in the handlers.

When the inbuilt templating was added, mustache was the only alternative, and sharing data between the handlers was a pain, so it made sense to add a built in convenience function. Today it's rather unnecessary, and might be removed one day.

Thanks all!

Edit: It might be helpful to us new people to update that particular example.