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

Export Transparency to various popular frameworks #15

Closed miohtama closed 12 years ago

miohtama commented 12 years ago

To continue with issue #10

Please use UGLY full caps for globals: TRANSPARENCY (only if you are going to make it a forced global)

http://yuiblog.com/blog/2006/06/01/global-domination/

E.g. Three.js, Yahoo YUI does this and it is generally accepted best practice:

https://github.com/mrdoob/three.js/blob/master/src/Three.js

However, since globals are not that popular, I suggest you add minimal boilerplate to export Transparency in different ways

Through jQuery: $.transparency

Plain: window.TRANSPARENCY

require.js (asynchronous loading): var transparency = require("libs/transparency")

and so on...

I found an example: Mustache for Javascript does this

https://github.com/janl/mustache.js/tree/master/wrappers

Is Transparency a class or a namespace?

pyykkis commented 12 years ago

We'll, e.g., Spine.js, jQuery, Handlebars.js and YUI export a global object containing constructors and functions. Only Yahoo has adopted usage of all caps, which is indeed, ugly :)

Transparency now exports one global object, Transparency, working as a namespace.

At the moment, it contains just one function, Transparency.render(). In the future, at least it contains additionally at least Transparency.SafeHtml() to construct unescaped strings.

jQuery plugin code is executed only if jQuery is available, so it can be included all the time. Other frameworks could be easily supported in a similar fashion. Would you like to contribute? =)

miohtama commented 12 years ago

Please use lowercase for namespace and CamelCase for classes. If Transparency is indeed a module then it should be all lower.

Also I think it would be more future proof to have safeHTML() as function, not constructor, as in the future the internal implementatino may change (to something more efficient),

miohtama commented 12 years ago

Clarification: in Javascript use CamelCase for constructor.

So either new Transparency() or transparency

miohtama commented 12 years ago

Unfortunately I don't personally use other major frameworks besides jQuery :)

pyykkis commented 12 years ago

Closing as there hasn't been requests for any specific framework. I'll add the boilerplate, if someone requests something specific in the future.