-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- #58 {% import %} ignored after {% extends %}
- #5 Improve error reporting
- Loading branch information
Showing
15 changed files
with
1,084 additions
and
1,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,122 @@ | ||
var TemplateParser = require('./parser/TemplateParser') | ||
var TemplateProvider = require('./TemplateProvider') | ||
var LanguageContext = require('./LanguageContext') | ||
var Default = require('./lang/Default') | ||
var fs = require('fs') | ||
var FileSystemTemplateProvider = TemplateProvider.FileSystemTemplateProvider; | ||
var registryTemplateParser = { | ||
}; | ||
var languageContext = new LanguageContext.LanguageContext(); | ||
Default.register(languageContext); | ||
function internalCompile(options, absolutePath) { | ||
if (typeof absolutePath === "undefined") { absolutePath = false; } | ||
if(options.root === undefined) { | ||
options.root = ''; | ||
} | ||
if(registryTemplateParser[options.root] === undefined) { | ||
var templateParser = new TemplateParser.TemplateParser(new FileSystemTemplateProvider(options.root), languageContext); | ||
registryTemplateParser[options.root] = templateParser; | ||
} | ||
return function (params) { | ||
var cache = options.cache; | ||
if(params && params.settings) { | ||
if(options.cache === undefined) { | ||
cache = params.settings['view cache']; | ||
} | ||
} | ||
return languageContext.templateConfig.setCacheTemporal(cache, function () { | ||
var templateParser = registryTemplateParser[options.root]; | ||
if(options.path === undefined) { | ||
if(options.content === undefined) { | ||
throw (new Error("No content or path")); | ||
} | ||
return templateParser.compileAndRenderStringToString(options.content, params); | ||
} else { | ||
if(absolutePath) { | ||
return templateParser.compileAndRenderToString(options.path, params); | ||
} else { | ||
if(options.path.indexOf(options.root) !== 0) { | ||
throw (new Error("Path '" + options.path + "' not inside root '" + options.root + "'")); | ||
} | ||
return templateParser.compileAndRenderToString(options.path.substr(options.root.length), params); | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
var rootPathCache = { | ||
}; | ||
function internalRender(filename, options, absolutePath) { | ||
if (typeof absolutePath === "undefined") { absolutePath = false; } | ||
options = options || { | ||
}; | ||
if(options.settings === undefined) { | ||
options.settings = { | ||
}; | ||
} | ||
var rootPath = options.settings['views'] || '.'; | ||
if(rootPathCache[rootPath] === undefined) { | ||
rootPathCache[rootPath] = fs.realpathSync(rootPath); | ||
} | ||
var params = { | ||
path: filename, | ||
root: rootPathCache[rootPath], | ||
cache: options.cache, | ||
content: options.content | ||
}; | ||
return internalCompile(params, absolutePath)(options); | ||
} | ||
function internalCompileString(content, options) { | ||
return function (params) { | ||
params.content = content; | ||
params.path = params.filename; | ||
return internalRender(params.filename, params, true); | ||
}; | ||
} | ||
exports.internalCompileString = internalCompileString; | ||
function express2Compile(templateString, options) { | ||
options = options || { | ||
}; | ||
if(options.settings === undefined) { | ||
options.settings = { | ||
}; | ||
} | ||
return internalCompileString(templateString, options.settings['atpl options']); | ||
} | ||
exports.express2Compile = express2Compile; | ||
function express3RenderFile(filename, options, callback) { | ||
if('function' == typeof options) { | ||
callback = options; | ||
options = { | ||
}; | ||
} | ||
var err = null; | ||
var result = null; | ||
try { | ||
result = internalRender(filename, options); | ||
} catch (err) { | ||
} | ||
return callback(null, result); | ||
} | ||
function registerExtension(items) { | ||
return languageContext.registerExtension(items); | ||
} | ||
exports.registerExtension = registerExtension; | ||
function registerTags(items) { | ||
return languageContext.registerTags(items); | ||
} | ||
exports.registerTags = registerTags; | ||
function registerFunctions(items) { | ||
return languageContext.registerFunctions(items); | ||
} | ||
exports.registerFunctions = registerFunctions; | ||
function registerFilters(items) { | ||
return languageContext.registerFilters(items); | ||
} | ||
exports.registerFilters = registerFilters; | ||
function registerTests(items) { | ||
return languageContext.registerTests(items); | ||
} | ||
exports.registerTests = registerTests; | ||
exports.compile = express2Compile; | ||
exports.__express = express3RenderFile; | ||
var TemplateParser = require('./parser/TemplateParser') | ||
var TemplateProvider = require('./TemplateProvider') | ||
var LanguageContext = require('./LanguageContext') | ||
var Default = require('./lang/Default') | ||
var fs = require('fs') | ||
var FileSystemTemplateProvider = TemplateProvider.FileSystemTemplateProvider; | ||
var registryTemplateParser = { | ||
}; | ||
var languageContext = new LanguageContext.LanguageContext(); | ||
Default.register(languageContext); | ||
function internalCompile(options, absolutePath) { | ||
if (typeof absolutePath === "undefined") { absolutePath = false; } | ||
if(options.root === undefined) { | ||
options.root = ''; | ||
} | ||
if(registryTemplateParser[options.root] === undefined) { | ||
var templateParser = new TemplateParser.TemplateParser(new FileSystemTemplateProvider(options.root), languageContext); | ||
registryTemplateParser[options.root] = templateParser; | ||
} | ||
return function (params) { | ||
var cache = options.cache; | ||
if(params && params.settings) { | ||
if(options.cache === undefined) { | ||
cache = params.settings['view cache']; | ||
} | ||
} | ||
return languageContext.templateConfig.setCacheTemporal(cache, function () { | ||
var templateParser = registryTemplateParser[options.root]; | ||
if(options.path === undefined) { | ||
if(options.content === undefined) { | ||
throw (new Error("No content or path")); | ||
} | ||
return templateParser.compileAndRenderStringToString(options.content, params); | ||
} else { | ||
if(absolutePath) { | ||
return templateParser.compileAndRenderToString(options.path, params); | ||
} else { | ||
if(options.path.indexOf(options.root) !== 0) { | ||
throw (new Error("Path '" + options.path + "' not inside root '" + options.root + "'")); | ||
} | ||
return templateParser.compileAndRenderToString(options.path.substr(options.root.length), params); | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
var rootPathCache = { | ||
}; | ||
function internalRender(filename, options, absolutePath) { | ||
if (typeof absolutePath === "undefined") { absolutePath = false; } | ||
options = options || { | ||
}; | ||
if(options.settings === undefined) { | ||
options.settings = { | ||
}; | ||
} | ||
var rootPath = options.settings['views'] || '.'; | ||
if(rootPathCache[rootPath] === undefined) { | ||
rootPathCache[rootPath] = fs.realpathSync(rootPath); | ||
} | ||
var params = { | ||
path: filename, | ||
root: rootPathCache[rootPath], | ||
cache: options.cache, | ||
content: options.content | ||
}; | ||
return internalCompile(params, absolutePath)(options); | ||
} | ||
function internalCompileString(content, options) { | ||
return function (params) { | ||
params.content = content; | ||
params.path = params.filename; | ||
return internalRender(params.filename, params, true); | ||
}; | ||
} | ||
exports.internalCompileString = internalCompileString; | ||
function express2Compile(templateString, options) { | ||
options = options || { | ||
}; | ||
if(options.settings === undefined) { | ||
options.settings = { | ||
}; | ||
} | ||
return internalCompileString(templateString, options.settings['atpl options']); | ||
} | ||
exports.express2Compile = express2Compile; | ||
function express3RenderFile(filename, options, callback) { | ||
if('function' == typeof options) { | ||
callback = options; | ||
options = { | ||
}; | ||
} | ||
var err = null; | ||
var result = null; | ||
try { | ||
result = internalRender(filename, options); | ||
} catch (err) { | ||
} | ||
return callback(null, result); | ||
} | ||
function registerExtension(items) { | ||
return languageContext.registerExtension(items); | ||
} | ||
exports.registerExtension = registerExtension; | ||
function registerTags(items) { | ||
return languageContext.registerTags(items); | ||
} | ||
exports.registerTags = registerTags; | ||
function registerFunctions(items) { | ||
return languageContext.registerFunctions(items); | ||
} | ||
exports.registerFunctions = registerFunctions; | ||
function registerFilters(items) { | ||
return languageContext.registerFilters(items); | ||
} | ||
exports.registerFilters = registerFilters; | ||
function registerTests(items) { | ||
return languageContext.registerTests(items); | ||
} | ||
exports.registerTests = registerTests; | ||
exports.compile = express2Compile; | ||
exports.__express = express3RenderFile; |
Oops, something went wrong.