fenekku / moustachu

Mustache templating for Nim
65 stars 8 forks source link

Minor tweaks including json support for render/renderFile #21

Closed JohnAD closed 4 years ago

JohnAD commented 4 years ago

The PR does three things:

  1. For the latest versions of nim (incl 1.0.4) it removes the compiler errors/warnings about kind changes.
  2. It makes two unit tests invoked by nimble test more consistent with nimble recommendations.
  3. It adds support for passing JSON directly to render and renderFile. So, instead of:
   var jc = newJObject()
   # ... stuff happens to jc
   let c = newContext(jc)
   let myResult = render(tmplate, c)

you can simply...

   var jc = newJObject()
   # ... stuff happens to jc
   let myResult = render(tmplate, jc)

Since json is part of the standard library and is heavily used by web site building (a common use-case of templating), I think this makes sense. My next Nim-website-building video will go through creating HTML views and will feature moustachu. It would be great if I could avoid the conversion step to keep things simple.

ref to video playlist: https://www.youtube.com/playlist?list=PL6RpFCvmb5SGw7aJK1E4goBxpMK3NvkON

JohnAD commented 4 years ago

I made the two changes and bumped the version to 0.14.0. To keep the doc comment consistent, I made the related render function public. Let me know if you want me to undo that.

I also found two more compiler warning messages and cleaned those up while I was at it. Not sure how I missed them earlier. Everything compiles without warnings or errors now. This includes the latest stable nim: 1.0.6.

Thanks for looking at this!