Skip to content

Conversation

@tobias-loew
Copy link

Hi Michael,

I finally found the time to work on the boostache code.
I could fix several deficits of the engine and think it is now a moustache-compliant template engine. The main problem was the missing context-stack (as we already discussed in Aspen): in contrast to the original implementation of the engine, which generates a data-driven call-hierarchy, moustache is not entirely data-driven (it can have nested contexts). For instance the original boostach couldn't handle correctly moustache code like in my example2.cpp (same data as original example2.cpp but with input
std::string input(
"Invoice"
"\n"
"{{#lines}}"
"inner start\n"
"{{#lines}}"
" {{item_code}} {{description}} {{amount}}\n"
"{{/lines}}"
"inner end\n"
"{{/lines}}"
);

the correct output is:
"Invoice
inner start
1234 teddy bear $23
1235 computer $9
inner end
inner start
1234 teddy bear $23
1235 computer $9
inner end"
)
I solved this by using a simple linked list of visited contexts, where the references to the contexts are stored in a variant over all types in the data-structure (computed by tmp-code in unificator.hpp). Thus, the stack is a fixed type and there is no infinite template recursion when the engine is compiled (which was the main problem of my first attempt). Furthermore, I changed the default rendering to a haskell-like dumping. In example3 I added overloads for render and test for a user-defined type (user_rendered_t) and it also works fine. Now, having moustache running we can then try and tackle django. (Which has some interesting features like "cycle" or "regroup" that will need further extensions of the engine.)
Any comment is appreciated!
Tobias

@mjcaisse
Copy link
Member

Thank you for this PR @tobias-loew . I suspect the project and other VS specific files are useful. Is there a way to move them to a subdirectory without causing problems?

@tobias-loew
Copy link
Author

Sorry for that. I'll remove the VS stuff and some other junk and update the PR with my latest changes from this week. Just be patience for some days...

@tobias-loew
Copy link
Author

Hi Michael,

I made a PR for my latest changes (including those made to django). The msvc files should hopefully have gone.
For the django-part there is still a lot work to do: e.g. django returns iteration sets from expressions in the for-loop which go beyond the plain container-iteration in moustache.

cheers

Tobias

@mjcaisse
Copy link
Member

mjcaisse commented Jul 6, 2018

Thank you Tobias. I'm cleaning a few things up and then will get this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants