solidusjs/solidus — pull request #107 by joanniclaborde (2014-06-06 15:52:26+00:00)
Title: View reusability

Fixes #106.

A new site config file is introduced: `/preprocessors.js`. Instead of specifying the resources and preprocessors to use in each template directly, all that information is moved to this new config file. Also, resources are now part of preprocessors.

This file is basically a map between a view an a preprocessor. A preprocessor is an object with two (optional) properties: `resources` (object of resources) and `process` (function that receives and returns the current context).

**/preprocessors.js**
```
module.exports = {
'page.hbs': function() {
return {
resources: {
stuff: "http://stuff.com/stuff"
},
process: function(context) {
context.stuff = true;
return context;
}
};
},

'partial.hbs': function() {
return require('./preprocessors/partial.js');
}
}
```

Each preprocessor can also be moved to a separate file in the `/preprocessors` directory. Each preprocessor file will later be accessible by the client application, so it can request its resources and run its `process` function dynamically.

**/preprocessors/partial.js**
```
module.exports.resources = {
tweets: "http://twitter.com/tweets"
}

module.exports.process = function(context) {
context.first_tweets = resources.tweets[0];
return context;
}
```