
Dug.js – A JSONP to HTML Script - ekpyrotic
http://rog.ie/blog/dugjs-a-jsonp-to-html-script
======
drtse4
Clean, concise, no dependencies, straightforward to use, what's not to like.

~~~
pedalpete
On top of that, a simple solution to a task people do again and again.

------
Sir_Cmpwn
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/](http://www.w3.org/TR/cors/)

------
hbi99
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 structures with XSL
(additionally, it's possible to search JSON structures with XPath queries
using this lib;
[http://defiantjs.com/#xpath_evaluator](http://defiantjs.com/#xpath_evaluator)).

~~~
philbo
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?

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

I created [http://apidocjs.com](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.

------
dpweb
Nice although I think I prefer the style to separate the htm from the js

    
    
        <template id='mytemplate'>
          my data is {{data}}
        </template>
    
        <script>
          doit('mytemplate', 'http://api.dribbble.com/.../shots')    
          
          // or jq plugin
          $('#mytemplate').render('http://...');   
        </script>

------
_zen
[https://github.com/rogie/Dug.js](https://github.com/rogie/Dug.js)

------
jpdlla
Previous discussion on Designer News
[https://news.layervault.com/stories/14856-dugjs-a-jsonp-
to-h...](https://news.layervault.com/stories/14856-dugjs-a-jsonp-to-html-
script)

------
va949
Anybody knows how to use this on instagram photos?

------
NKCSS
Fun little project :)

