blakeembrey / dombars

*DEPRECATED* DOM-based templating library with data-binding and built on Handlebars
MIT License
51 stars 5 forks source link

Output of compile a DOM element vs. a template function? #33

Closed rvangundy closed 10 years ago

rvangundy commented 10 years ago

Wondering why this is the case? Original Handlebars works like:

var template = Handlebars.compile('<div>{{firstname}} {{lastname}}</div>');
var str = template({ firstname:'John', lastname:'Doe' });

Replacing the string output with an element in DOMbars, this pattern would allow reuse of the template function, but also would pave the way for a DOMbars pre compiler.

blakeembrey commented 10 years ago

That's the way DOMBars is already working, unless I'm missing something else?

var template = DOMBars.compile('<div>{{firstname}} {{lastname}}</div>');
var dom = template({ firstname:'John', lastname:'Doe' });
blakeembrey commented 10 years ago

Also, I've already written a precompiler for DOMBars.

rvangundy commented 10 years ago

Doh, yeah you're right. Just doing some upfront investigating and misread the lingo in the readme:

// Generate a template.
var template = DOMBars.compile(
  '<input type="checkbox" checked="{{{test}}}">'
)({
  test: false
});

// Append the template directly to the body element and watch the magic happen.
document.body.appendChild(template);

Coming off the Handlebars docs you'd expect something more like:

// Generate a template.
var template = DOMBars.compile('<input type="checkbox" checked="{{{test}}}">');
var context = {test: false};

document.body.appendChild(template(context));

So just a semantics issue. Cool library, time to dive in deeper than the docs :)

blakeembrey commented 10 years ago

Haha, yeah. Thank you! I'll look at updating the docs and doing some maintenance tonight or tomorrow.