enhancement: decrease dist size

This commit is contained in:
harttle
2016-10-04 22:31:28 +08:00
parent 1e1b6e8cc3
commit 77930e2d20
30 changed files with 2724 additions and 3934 deletions
+19 -6
View File
@@ -1,10 +1,8 @@
const Scope = require('./src/scope');
const assert = require('assert');
const tokenizer = require('./src/tokenizer.js');
const fs = require('fs');
const Render = require('./src/render.js');
const lexical = require('./src/lexical.js');
const path = require("path");
const fs = require('fs');
const Tag = require('./src/tag.js');
const Filter = require('./src/filter.js');
const Template = require('./src/parser');
@@ -75,9 +73,11 @@ var _engine = {
return this.tag.register(name, tag);
},
handleCache: function(filepath) {
assert(filepath, 'filepath cannot be null');
filepath = path.resolve(this.options.root, filepath);
if (path.extname(filepath) === '') {
if (!filepath) throw new Error('filepath cannot be null');
filepath = resolvePath(this.options.root, filepath);
if (!filepath.match(/\.\w+$/)) {
filepath += this.options.extname;
}
@@ -114,6 +114,19 @@ function factory(options) {
return engine;
}
function resolvePath(root, path) {
if (path[0] == '/') return path;
var arr = root.split('/').concat(path.split('/'));
var result = [];
arr.forEach(function(slug) {
if (slug == '..') result.pop();
else if (!slug || slug == '.');
else result.push(slug);
});
return '/' + result.join('/');
}
factory.lexical = lexical;
factory.isTruthy = Expression.isTruthy;
factory.isFalsy = Expression.isFalsy;