Repository navigation
Added support for inline partials. People that are more familiar with… - #221
Conversation
… the codbase should look at some of my hackier bits. I left comments to explain the thinking
|
This is a pretty effective solution. Only 1 aspect gives me discomfort... the empty built-in helper. What problem does that solve? Otherwise, it seems fairly straightforward. In terms of the base syntax, an inline partial more or less is a block helper, so this approach makes sense. We do need some unit test coverage to call it complete, however. |
|
I don't like the empty helper either but it seemed to help side-step understanding a big chunk of code. Basically, without the empty helper, some aspect of the code would throw an error regarding not knowing what the "*inline" block was for. I also suspect the addition to the BlockHelperFunctionBinder.VisitBlockHelperExpression is a bit of a hack too. I'll admit to being new Expressions too so this was a simple way for me to get it working without hitting that learning curve. Given your more thorough knowledge of the code base, if you can provide some guidance as to how to accomplish the same things, I am happy to take another shot at it and add some tests as well. |
|
+1. This is a super awesome and super useful; any template of size is much more maintainable when broken to components, and it's nice not to have to clutter the file system with a handful of partials and the c# code with all the registering. |
|
I think if you can add some unit tests, this is good enough to go as-is. It works and after thinking about the approach more, I dig the simplicity because inline partials are syntactically a weird kind of block helper. |
|
While testing, it turned out that using Handlebars.RegisterTemplate would pollute the static space and could collide with other templates that were compiled with the same instance. This was only an issue with Handlebars.Compile. It worked fine with Handlebars.Create. That said, it seemed more appropriate that the inline partials should be scoped to the compiled template and nothing else. To do this, I added a collection of compiled inline partials to pass around with the BindingContext. I duplicated the existing Partial test into InlinePartial tests and everything is passing. |
|
On a side note... thanks for putting this project together. It is solving some problems I have in a very good way. Great code. |
|
Along the lines of the static RegisterTemplate issue, using a new instance per compile would solve the scoping issue created by the inline partials and simplify the commit quite a bit. Instead of passing around the InlinePartials in the context, I could just add them to the config. I chose to scope them is because I suspect many people (myself included) use the convenience methods listed on the readme.md without realizing the issue. I'm good either way. lmk |
… the codbase should look at some of the hackier bits. I left comments to explain the thinking in the code.
The template below can be used as a simple test. I have done some pretty complicated nesting of inline partials with parameters and different contexts and everything seems to work pretty well. I'm sure some aspects of this can and should be improved so please feel free to put things where they should be.
{{#*inline "inlineTest"}}
hello inline partial
{{/inline}}
{{> inlineTest}}