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

Plain String list rendering is broken #14

Closed raimohanska closed 12 years ago

raimohanska commented 12 years ago

The "comments" example is broken in real browsers even though the jasmine tests pass just fine. I think this is since the removal of jQuery. Example below fails with message "Uncaught Error: SYNTAX_ERR: DOM Exception 12" in Chrome and with different message in other browsers.

This error occurs when the "key" parameters of matchingElements is a string representation of a number, like "0" or "1". This happens when the object to be rendered is a string. I think the renderValues method should be changed so that the internals of the object are not scanned for strings. Like below. That would fix it.

renderValues = (template, object) ->
  if typeof object == "object"
    (setValue(e, v) for e in matchingElements(template, k)) for k, v of object when typeof v != 'object'
  else
    setValue(template.querySelector(".listElement") || template.querySelector("*"), object)

Failing example page: https://gist.github.com/1868486

pyykkis commented 12 years ago

Fixed as proposed. Thanks for the fix and the test page!