Skip to content
Browse files

adding support for partials in the store. views within partials/* fol…

…der are now consider partials, which are an special type of view. Adding support for application.json->viewEngine->preloadTemplates to preload any view in memory, and this is disabled by default for now
  • Loading branch information...
1 parent 8ffe620 commit 374826d38a353009b9859104473b00b3ea3f8726 @caridy committed
Showing with 25 additions and 7 deletions.
  1. +25 −7 lib/app/autoload/store.server.js
View
32 lib/app/autoload/store.server.js
@@ -615,9 +615,11 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
var ress,
r,
res,
+ template,
engine,
engines = {}, // view engines
posl = this.selector.getPOSLFromContext(ctx),
+ staticAppConfig = this.getStaticAppConfig(),
ctxKey,
module;
@@ -638,6 +640,9 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
if (!dest.models) {
dest.models = {};
}
+ if (!dest.partials) {
+ dest.partials = {};
+ }
if (!dest.views) {
dest.views = {};
}
@@ -679,15 +684,21 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
}
if (res.type === 'view') {
- if (!dest.views[res.name]) {
- dest.views[res.name] = {};
- }
- if (env === 'client') {
- dest.views[res.name]['content-path'] = res.url;
+ template = {
+ 'content-path': (env === 'client' ?
+ this._libs.path.join(staticAppConfig.pathToRoot || '', res.url) :
+ res.source.fs.fullPath),
+ 'content': res.content,
+ 'engine': res.view.engine
+ };
+ // we want to separate partials from actual templates
+ // in case the engine supports partials
+ if (res.name.indexOf('partials/') === 0) {
+ // removing the "partials/" prefix
+ dest.partials[libs.path.basename(res.name)] = template;
} else {
- dest.views[res.name]['content-path'] = res.source.fs.fullPath;
+ dest.views[res.name] = template;
}
- dest.views[res.name].engine = res.view.engine;
engines[res.view.engine] = true;
}
}
@@ -1410,6 +1421,13 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
}
res.name = this._libs.path.join(fs.subDirArray.join('/'), baseParts.join('.'));
res.id = [res.type, res.subtype, res.name].join('-');
+ // for performance reasons, we might want to preload all
+ // views in memory, for that, we can use:
+ // application.json->viewEngine->preloadTemplates
+ // TODO: should this be set to true by default?
+ if (this._appConfigStatic.viewEngine && this._appConfigStatic.viewEngine.preloadTemplates) {
+ res.content = this._libs.fs.readFileSync(source.fs.fullPath, 'utf8');
+ }
return res;
}

0 comments on commit 374826d

Please sign in to comment.
Something went wrong with that request. Please try again.