Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update template resolver to read a default template and also to have …

…a failsafe template
  • Loading branch information...
commit bcc38a69d2bf702a18e21ae151c2ae79c5969b8b 1 parent 3a55318
@dmachi authored
Showing with 16 additions and 17 deletions.
  1. +16 −17 lib/resolver.js
View
33 lib/resolver.js
@@ -12,39 +12,38 @@ var when = require("promised-io/promise").when;
// for example, searching /foo/bar/baz,/foo/bar,/foo and returning the first one found.
**/
-exports.Resolver = function(store) {
+exports.Resolver = function(store,options) {
//print("Setup Resolver: " + store);
+ var defaultTemplate = require("commonjs-utils/settings").defaultTemplate || "default"
return function(id,exact){
print("Resolve Template for ID: " + id);
- var parts=id.split("/");
+ var template,
+ parts=id.split("/");
while(parts.length>0){
var tid = parts.join("/");
var templateString="";
//print("getFrom Store");
- var template = store.get(tid);
+ template = store.get(tid);
if (template){
print("Found Template: " + tid);
template.forEach(function(c){templateString+=c.decodeToString()});
return templateString;
-
- /*
- for (var i in engine){
- print("i: " + i);
- }
- var render = new Function("$data", engine.compile(templateString));
-
- return {
- id: tid,
- render: render,
- template: template
- }
- */
}
if (exact){return}
+
parts.pop();
}
- return;
+
+ //attempt to load the default template
+ template = store.get(defaultTemplate);
+ if (template){
+ template.forEach(function(c){templateString+=c.decodeToString()});
+ return templateString;
+ }
+
+ //no default template give a really basic default
+ return "<html><body>{{$data}}<body></html>";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.