diff options
Diffstat (limited to 'lib/output/website/createTemplateEngine.js')
-rw-r--r-- | lib/output/website/createTemplateEngine.js | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/lib/output/website/createTemplateEngine.js b/lib/output/website/createTemplateEngine.js index daa591a..8c31ea7 100644 --- a/lib/output/website/createTemplateEngine.js +++ b/lib/output/website/createTemplateEngine.js @@ -3,6 +3,7 @@ var nunjucks = require('nunjucks'); var DoExtension = require('nunjucks-do')(nunjucks); var Api = require('../../api'); +var deprecate = require('../../api/deprecate'); var JSONUtils = require('../../json'); var LocationUtils = require('../../utils/location'); var fs = require('../../utils/fs'); @@ -51,24 +52,44 @@ function createTemplateEngine(output, currentFile) { // Create API context var context = Api.encodeGlobal(output); + + /** + Check if a file exists + + @param {String} fileName + @return {Boolean} + */ + function fileExists(fileName) { + if (!fileName) { + return false; + } + + var filePath = PathUtils.resolveInRoot(outputFolder, fileName); + return fs.existsSync(filePath); + } + + /** + Return an article by its path + + @param {String} articlePath + @return {Object|undefined} + */ + function getArticleByPath(articlePath) { + var article = summary.getByPath(articlePath); + if (!article) return undefined; + + return JSONUtils.encodeSummaryArticle(article); + } + + return TemplateEngine.create({ loader: loader, context: context, globals: { - /** - Return an article by its path - - @param {String} articlePath - @return {Object|undefined} - */ - getArticleByPath: function(articlePath) { - var article = summary.getByPath(articlePath); - if (!article) return undefined; - - return JSONUtils.encodeSummaryArticle(article); - } + getArticleByPath: getArticleByPath, + fileExists: fileExists }, filters: defaultFilters.merge({ @@ -102,13 +123,9 @@ function createTemplateEngine(output, currentFile) { return LocationUtils.normalize(filePath); }, - /** - Check if a file exists - */ - fileExists: function(fileName) { - var filePath = PathUtils.resolveInRoot(outputFolder, fileName); - return fs.existsSync(filePath); - }, + + fileExists: deprecate.method(book, 'fileExists', fileExists, 'Filter "fileExists" is deprecated, use "fileExists(filename)" '), + getArticleByPath: deprecate.method(book, 'getArticleByPath', fileExists, 'Filter "getArticleByPath" is deprecated, use "getArticleByPath(filename)" '), contentURL: function(filePath) { return fileToURL(output, filePath); |