fenekku / moustachu

Mustache templating for Nim
65 stars 8 forks source link

Implemented support for partials. #7

Closed h3rald closed 6 years ago

h3rald commented 7 years ago

This should fix #1.

watzon commented 6 years ago

Anything holding this up @fenekku ?

fenekku commented 6 years ago

Anything holding this up @fenekku ?

Vacation mostly :), but also I think I never quite understood the "disk partials" use and use case which was why I didn't implement it if I recall. I implemented the "in-memory" partials however which made sense to me.

I did it by not having an additional partials parameter because I didn't quite see the need for it - the API to make work in other implementations have always seemed clunky to me. Sure it would help to differentiate between a filename and a string but the computer can probably do it for you. The questions "is that a filename's path?" and "What is the relative location of that path?" just added more complexity. I wanted something simpler, but again it is probably because I never understood the full picture.

Could you provide an example of file structure, templates, contexts and calls to illustrate the usage of disk partials? Once it makes sense I would be happy to merge!

h3rald commented 6 years ago

Hi!

Sure. I am currently building a small, self-contained static site generator (hastysite) in nim, and I am currently using mustache as templating engine.

I implemented partials support because I needed a way to reuse things like header, footer etc. in (potentially) several page-level templates. Here you can find some example templates -- in particular the page.mustache template references the others. This is a pointless example because I only have one top-level template, but I could create others and reuse the same partials.

The actual render call within hastysite is here. In this case, I am assuming that all templates will be within the same folder (let's say it's "good enough" for me).

fenekku commented 6 years ago

Cool!

Let me look into this/try this out because I also used partials for my personal static site generator (but clearly I didn't have 'disk partials'). I had the generator program read specific templates from disk and assign them to context variables which were then injected as partials. I had complete control this way.

fenekku commented 6 years ago

Also don't forget to bump the version!

h3rald commented 6 years ago

@fenekku Sorry for the delay -- I think I implemented the changes you requested, please take a look :) I bumped the version to 0.11.0... not sure if you follow semantic versioning, but I thought that this could be considered a new feature rather than a bugfix after all, but again up to you!