Comparing version
@@ -30,4 +30,3 @@ "use strict"; | ||
aliasRegex: Type.REGEX, | ||
defaultThemeRegex: Type.REGEX, | ||
themeRegex: Type.REGEX | ||
defaultThemeRegex: Type.REGEX | ||
}, | ||
@@ -53,7 +52,6 @@ { | ||
defaultTheme: 'default', | ||
theme: false | ||
themes: [] | ||
}, config); | ||
this.defaultThemeRegex = new RegExp('^' + this.config.defaultTheme + '/'); | ||
this.themeRegex = new RegExp('^' + this.config.theme + '/'); | ||
@@ -243,19 +241,2 @@ di.setAlias('viewsPath', this.config.views); | ||
* @author Igor Ivanovic | ||
* @method View#setThemesPath | ||
* | ||
* @description | ||
* Set theme path | ||
*/ | ||
setTheme: function View_setTheme(name) { | ||
if (Type.assert(Type.STRING, name)) { | ||
this.config.theme = name; | ||
} else if (Type.isNull(name)) { | ||
this.config.theme = null; | ||
} else { | ||
throw new error.HttpError(500, {name: name}, "ViewLoader.setTheme: name must be string type"); | ||
} | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method View#getPath | ||
@@ -278,5 +259,49 @@ * | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method View#lookUpFile | ||
* | ||
* @description | ||
* Look up file | ||
* @return {string} | ||
*/ | ||
lookUpFile: function View_lookUpFile(path, file, to, from) { | ||
var themes = this.config.themes.slice(), | ||
theme, | ||
re, | ||
filePath, | ||
trace = []; | ||
while (themes.length) { | ||
theme = themes.shift(); | ||
re = new RegExp('^' + theme + '/'); | ||
file = file.replace(re, ''); | ||
filePath = di.normalizePath(path + theme + '/' + file + this.config.suffix); | ||
if (this.isFile(filePath)) { | ||
return filePath; | ||
} | ||
trace.push({ | ||
theme: theme, | ||
path: path, | ||
filePath: filePath | ||
}); | ||
} | ||
filePath = di.normalizePath(path + this.config.defaultTheme + '/' + file + this.config.suffix); | ||
if (this.isFile(filePath)) { | ||
return filePath; | ||
} | ||
throw new error.HttpError(500, { | ||
from: from, | ||
load: to, | ||
trace: trace | ||
}, "View.resolve: template don't exists"); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method View#resolve | ||
@@ -289,3 +314,3 @@ * | ||
resolve: function View_resolve(to, from) { | ||
var path, file, dPath, themePath; | ||
var path, file; | ||
@@ -315,33 +340,3 @@ to = di.normalizePath(to); | ||
if (!!this.config.theme) { | ||
file = file.replace(this.themeRegex, ''); | ||
themePath = di.normalizePath(path + this.config.theme + '/' + file + this.config.suffix); | ||
if (this.isFile(themePath)) { | ||
return themePath; | ||
} | ||
} | ||
dPath = di.normalizePath(path + this.config.defaultTheme + '/' + file + this.config.suffix); | ||
if (this.isFile(dPath)) { | ||
return dPath; | ||
} | ||
if (this.config.theme) { | ||
throw new error.HttpError(500, { | ||
from: from, | ||
load: to, | ||
themeFile: themePath, | ||
defaultFile: dPath | ||
}, "View.resolve: template don't exists"); | ||
} else { | ||
throw new error.HttpError(500, { | ||
from: from, | ||
load: to, | ||
defaultFile: dPath | ||
}, "View.resolve: template don't exists"); | ||
} | ||
return this.lookUpFile(path, file, to, from); | ||
}, | ||
@@ -348,0 +343,0 @@ /** |
@@ -25,3 +25,3 @@ "use strict"; | ||
"setLoader", "setFilter", "setTag", "setExtension", | ||
"render", "renderFile", "setTheme", | ||
"render", "renderFile", | ||
"resolve", "load", "getPath" | ||
@@ -28,0 +28,0 @@ ].forEach( |
@@ -5,3 +5,3 @@ { | ||
"description": "Powerful lightweight mvc framework for nodejs", | ||
"version": "0.1.0-beta-50", | ||
"version": "0.1.0-beta-51", | ||
"dependencies" : { | ||
@@ -8,0 +8,0 @@ "mongoose": "3.8.x", |
129864
-0.26%4153
-0.1%