brikis98 / node-backbone-skeleton

A skeleton project for creating applications that use node.js server-side, backbone.js client-side, underscore.js templates, CoffeeScript as a JS pre-processor and Compass/SASS as a CSS pre-processor..
84 stars 16 forks source link

Template Function example #6

Closed reduxdj closed 12 years ago

reduxdj commented 12 years ago

The use case I am using this app for is just development. Can you provide me an example please, of how I would make my underscore (or any type of template for that matter) work with a callback function on my html page to render my templates. Similar to how JST's work with jammit using erb style template functions. I'm not planning on serving the page/js/css files with node.

I'm not a Ruby developer so this is a great starting ground for my bolierplate.

brikis98 commented 12 years ago

Not sure I understand your question. What do you mean "work with a callback function"? node-backbone-skeleton already has underscore support, so are you changing something?

reduxdj commented 12 years ago

I notice you are using erb style templating inside your index.html... I don't see anything that's generated that looks like this when I run the server:

window.templates['test'] = "<div>'test template'</div>";

I was thinking of using other template formatters, when I met callback function, I mean the writeTemplate function, which is already being called.

Thanks sorry for the confusion.

reduxdj commented 12 years ago

I figured out what i wanted to do, basically I generate a template that looks like this, which is just a callback function wrapper for the underscore templates:

Which renders a template that looks liket the following:

window.templates || (window.templates = {}); window.templates['test'] = function(obj){var p=[],e=_.escapeHTML,print=function(){p.push.apply(p,arguments);};with(obj||{}){p.push('

\'test template\'\n\n<%= patrick %>


\nhello\n
');}return p.join('');};

By the way, thanks for your project, I'd love to fix the watch-util, since i don't know how to change path expressions in noe yet...

So directories become utils//* when coffee writes it's scripts it acutally makes folders called */ etc...

Best,

Patrick Going to close this issue

reduxdj commented 12 years ago

https://github.com/reduxdj/node-backbone-skeleton/blob/master/util/watcher.coffee