epeli/piler — pull request #47 by tandrewnichols (2014-01-31 05:16:43+00:00)
Title: Work-in-progress: Add the ability to manage templates

So this started because I'm using piler and angular.js and wanted to cache my angular templates on the client side. Adding

```html

will tell angular to add them to $templateCache. So I wanted a TemplatePile that would just let me add a series of angular templates and render them automatically.

So there's a new TemplatePile and a TemplateManager, but I wrote them to work with other templating engines too (interesting side effect is that you could write your angular templates in jade and compile them on the server side and let piler render them on the client side).

I added a couple helpers too: an addFiles method that let's you pass an array of files to a pile manager, and an addDir method that let's you read all the files (recursively) from a directory (optionally filtered with globstar patterns). I thought about trying to use the asynchronous fs methods for this, but you probably don't want to have to do

```javascript
clientjs.addDir('some/dir', function(err) {
// Now we know we can safely call res.end
// but it feels wrong to do it here . . .
});
```

So I went with sync, figuring that most people who are going to pull in a whole directory, will probably do so on app initialization and not per request.

This is still sort of a work in progress (untested and no tests), but I wanted to get some feedback to see if this is worth continuing to pursue (or to see if you have any additional thoughts/comments).

Thanks.