STRd6 / jadelet

Pure and simple clientside templates
https://jadelet.com
MIT License
378 stars 11 forks source link

Automatically add missing root element #22

Open zdenko opened 6 years ago

zdenko commented 6 years ago

Would it be wrong if the missing root element is automatically added:

So

.one               
.two

becomes

div
  .one               
  .two

I did a test with a small change in the compiler.coffee, and it works.

compile = (parseTree, {compiler, runtime, exports}={}) ->
  if parseTree.length > 1
    parseTree = [{tag: "div", children: parseTree}]

The only caveat here is that the HTML output might not be what the user expects.

STRd6 commented 5 years ago

It may be possible to wrap the items in a documentFragment. This should be fine for the external uses as document.body.appendChild will work fine with that, but we may need to add a check for when a template adds a subtemplate to get the reference counts right in the Jadelet runtime.

It is better form to have each template have a designated root element, semantically it just makes more sense to me. Personally I've never needed sibling elements returned in practice.