BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

Consider namespaced tag/template/converter/helper registration #313

Closed BorisMoore closed 7 years ago

BorisMoore commented 7 years ago

Make it possible to register a new {{tabs}} control without deleting existing {{tabs}} by specifying a namespace. E.g. make all jQueryUI tags have namespace ui. Now if I register my.tabs - using 'my' namespace, I can then use {{tabs}} - which will use my.tabs (since it was the last to be registered) as will {{my.tabs}}. But I can still use the jQueryUI {{tabs}} by specifying the namespace: {{ui.tabs}}.

Note that I considered an alternative - of automatically copying an existing registered resource to a different name. Existin {{tabs}} for example would get copied over to {{tabs2}} - using the following code

if (name) {
  oldItem = thisStore[name];
  thisStore[name] = item;
  if (oldItem) { // Consider this - reregistering existing item under different name
    cnt = 2; // There is already an item with that name.
    while (itemName = name + cnt++, thisStore[itemName]) {}
    thisStore[itemName] = oldItem; // Copy it to name2 (or name3... if name2 already used)
    if (onStore) {
      onStore(itemName, oldItem, parentTmpl, compile);
    }
  }
}

But that approach seems to be undiscoverable. and can lead to unnecessary creation of new resources.

BorisMoore commented 7 years ago

Closing all post V1 issues for now.