Live data from Hacker News

Dug.js – A JSONP to HTML Script

rog.ie

11–20 of 20 posts

Re: Dug.js – A JSONP to HTML Script

#12
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

The idea behind Mustache is that your template shouldn't have intelligence. The data passed to the template should be such that it isn't necessary (beyond simple ifs).

Re: Dug.js – A JSONP to HTML Script

#13
post #10
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

A typical reason to avoid intelligence in view templates is that it is more difficult to test that logic when it is stored inside the template. Separation of the two improves testability. What are the testing options like for XSLT, are you able to run good automated tests against your templates?

On the other side that make the creation of templates (somethings) unduly complex.

I created http://apidocjs.com and had the problem that i needed some "simple" logic in the templates (handlebars). For such things i must implement a separate view with configuration/data modelling/... and Helper function, but that makes the project-output complex, because i want that the people can change the template as easy as possible. Quick & dirty developed i create many duplicate code in the template to avoid a separate view. It was a silly idea, it makes the template more complex ;-) And only because of some missing logic.

Re: Dug.js – A JSONP to HTML Script

#14
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

A middle ground would be underscore templating system. It's simple to use and there's all the freedom you want regarding to what you do in the templates.

Re: Dug.js – A JSONP to HTML Script

#15
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

The idea behind Mustache is that your template shouldn't have intelligence. The data passed to the template should be such that it isn't necessary (beyond simple ifs).

Great input from all commentators and clearly this is an area that many have opinions on like

Regarding Mustache and Handlebars; the basic idea is that templates should be logic-free - despite this, there are many question at Stackoverflow, on how to add intelligence when using these templating engines. The basic idea and real-life implementation doesn't add up...

Re: Dug.js – A JSONP to HTML Script

#16
This is a great solution for existing APIs, but I want to mention that if you're designing a new API, you should opt for CORS instead of JSONP. This allows people to do straight-up XHR requests on your domain, with a whitelist of methods, headers, whatever.

http://www.w3.org/TR/cors/

Re: Dug.js – A JSONP to HTML Script

#17
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

XSLT is about the worst possible piece of technology - it's over engineered and practically unusable for all but simple transforms. functions, conditionals etc are just typical enterprise antiquated over designed unable crap.

Re: Dug.js – A JSONP to HTML Script

#19
post #5

Templating solutions such as Mustache and Handlebars falls short when the need to add intelligence to the template. In such cases, the template needs to extended with helper functions, which leads to scattered templating. Another way to implement smart templates is to use XSLT, which is both standardized as well as longtime proven. XSLT is used commonly used with XML but with DefiantJS, it's trivial to transform JSON…

why not use liquid?: https://github.com/tonyheupel/liquid.js

Re: Dug.js – A JSONP to HTML Script

#20
Nice although I think I prefer the style to separate the htm from the js

    
      my data is {{data}}
    

    
      doit('mytemplate', 'http://api.dribbble.com/.../shots')    
      
      // or jq plugin
      $('#mytemplate').render('http://...');   
    
Post reply on HN