var engines = {}
/**
* Cache partial store
* View cache.
*/
var partials = {}
var cache = { views: {}, partials: {}}
/**
* Cache view files where _type_ is
* "partials" or "views".
*
* @param {string} type
* @api public
*/
function cacheFiles(type) {
var dir = set(type)
fs.readdirSync(dir).each(function(file){
file = dir + '/' + file
cache[type][file] = fs.readFileSync(file)
})
}
// --- View
exports.View = Plugin.extend({
extend: {
set('views', function(){ return set('root') + '/views' })
if (!set('partials'))
set('partials', function(){ return set('views') + '/partials' })
// Cache views in memory
// Cache partials in memory
if (set('cache view contents'))
cacheFiles('views')
if (set('cache view partials'))
cacheFiles('partials')
if (set('cache view partials')) {
var dir = set('partials')
fs.readdirSync(dir).each(function(file){
file = dir + '/' + file
partials[file] = fs.readFileSync(file)
})
}
// Request
Request.include({
self.halt(200, content)
}
function renderFromDisc() {
if (partial)
return render(partials[path] || fs.readFileSync(path))
return render(cache.partials[path] || fs.readFileSync(path))
fs.readFile(path, function(err, content){
if (err) throw err
set('cache view contents')
? self.cache.set('view:' + path, content, function(cache){