mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 22:10:41 -07:00
refactor: filepath resolving into getTemplate
This commit is contained in:
Vendored
+5
-6
@@ -273,18 +273,17 @@ var _engine = {
|
|||||||
|
|
||||||
if (!filepath) throw new Error('filepath cannot be null');
|
if (!filepath) throw new Error('filepath cannot be null');
|
||||||
|
|
||||||
filepath = resolvePath(this.options.root, filepath);
|
|
||||||
|
|
||||||
if (!filepath.match(/\.\w+$/)) {
|
|
||||||
filepath += this.options.extname;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getTemplate(filepath).then(function (html) {
|
return this.getTemplate(filepath).then(function (html) {
|
||||||
var tpl = _this2.options.cache && _this2.cache[filepath] || _this2.parse(html);
|
var tpl = _this2.options.cache && _this2.cache[filepath] || _this2.parse(html);
|
||||||
return _this2.options.cache ? _this2.cache[filepath] = tpl : tpl;
|
return _this2.options.cache ? _this2.cache[filepath] = tpl : tpl;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getTemplate: function getTemplate(filepath) {
|
getTemplate: function getTemplate(filepath) {
|
||||||
|
filepath = resolvePath(this.options.root, filepath);
|
||||||
|
|
||||||
|
if (!filepath.match(/\.\w+$/)) {
|
||||||
|
filepath += this.options.extname;
|
||||||
|
}
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
fs.readFile(filepath, 'utf8', function (err, html) {
|
fs.readFile(filepath, 'utf8', function (err, html) {
|
||||||
err ? reject(err) : resolve(html);
|
err ? reject(err) : resolve(html);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -75,12 +75,6 @@ var _engine = {
|
|||||||
handleCache: function(filepath) {
|
handleCache: function(filepath) {
|
||||||
if (!filepath) throw new Error('filepath cannot be null');
|
if (!filepath) throw new Error('filepath cannot be null');
|
||||||
|
|
||||||
filepath = resolvePath(this.options.root, filepath);
|
|
||||||
|
|
||||||
if (!filepath.match(/\.\w+$/)) {
|
|
||||||
filepath += this.options.extname;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getTemplate(filepath)
|
return this.getTemplate(filepath)
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
var tpl = this.options.cache && this.cache[filepath] || this.parse(html);
|
var tpl = this.options.cache && this.cache[filepath] || this.parse(html);
|
||||||
@@ -88,6 +82,11 @@ var _engine = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
getTemplate: function(filepath) {
|
getTemplate: function(filepath) {
|
||||||
|
filepath = resolvePath(this.options.root, filepath);
|
||||||
|
|
||||||
|
if (!filepath.match(/\.\w+$/)) {
|
||||||
|
filepath += this.options.extname;
|
||||||
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
fs.readFile(filepath, 'utf8', function(err, html) {
|
fs.readFile(filepath, 'utf8', function(err, html) {
|
||||||
err ? reject(err) : resolve(html);
|
err ? reject(err) : resolve(html);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shopify-liquid",
|
"name": "shopify-liquid",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"description": "Liquid template engine in Node.js (Shopify compliant)",
|
"description": "Liquid template engine in Node.js (Shopify compliant)",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user