leonidas / transparency

Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
http://leonidas.github.com/transparency/
MIT License
969 stars 112 forks source link

Expose elementMatcher function as render() option #61

Closed miohtama closed 12 years ago

miohtama commented 12 years ago

So that people can use any black magic they wish to bind templates.

Useful e.g. in projects where several people are working on the same HTML code.

pyykkis commented 12 years ago

Thanks for the feedback. I totally understand the need, based on the IRC discussion.

I think about the API over night, request for comments tomorrow and go for the implementation on Sunday.

pyykkis commented 12 years ago

Here's the API proposal.

I ended up proposing that the matcher can be given just for one call or for all the calls. The latter is probably the more common scenario.


# Match only by data-bind. Return true, if the element matches to the key.
matcher = (element, key) ->
  element.getAttribute('data-bind') == key

# Use the custom matcher only for this call
$('#template').render data, {}, matcher: matcher

# Use the custom matcher for all the calls in the future
Transparency.config.matcher = matcher

# Matches only by data-bind
$('#template').render data
pyykkis commented 12 years ago

https://github.com/leonidas/transparency#configuration