@itrocks/template 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/cjs/template.d.ts +1 -0
- package/cjs/template.js +8 -3
- package/esm/template.d.ts +1 -0
- package/esm/template.js +8 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -410,6 +410,11 @@ Any expression starting with `/`, `./` or `../` is considered a template include
|
|
|
410
410
|
</div>
|
|
411
411
|
```
|
|
412
412
|
|
|
413
|
+
The path prefix defines how the file location is resolved:
|
|
414
|
+
- `./` refers to the directory of the current template file
|
|
415
|
+
- `../` refers to the parent directory of the current template file
|
|
416
|
+
- `/` refers to the root of the current project (not the filesystem root)
|
|
417
|
+
|
|
413
418
|
The default contextual data is the one in the current scope.
|
|
414
419
|
|
|
415
420
|
You can pass parent or sub-data to your included template as an alternative context:
|
package/cjs/template.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export declare class Template {
|
|
|
108
108
|
targetStack: string[];
|
|
109
109
|
};
|
|
110
110
|
include(path: string, data: any): Promise<string>;
|
|
111
|
+
includePath(filePath: string): string;
|
|
111
112
|
isContextClean(): boolean;
|
|
112
113
|
literalTarget(index: number, isTitle?: boolean): void;
|
|
113
114
|
parseBuffer(buffer: string): Promise<string>;
|
package/cjs/template.js
CHANGED
|
@@ -226,6 +226,11 @@ class Template {
|
|
|
226
226
|
? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
|
|
227
227
|
: parsed;
|
|
228
228
|
}
|
|
229
|
+
includePath(filePath) {
|
|
230
|
+
return (filePath[0] === '/')
|
|
231
|
+
? (app_dir_1.appDir + ((filePath[1] === '@') ? '/node_modules' : '') + filePath)
|
|
232
|
+
: filePath;
|
|
233
|
+
}
|
|
229
234
|
isContextClean() {
|
|
230
235
|
const clean = this.getCleanContext();
|
|
231
236
|
const context = this.getContext();
|
|
@@ -401,13 +406,13 @@ class Template {
|
|
|
401
406
|
expressionEnd--;
|
|
402
407
|
}
|
|
403
408
|
const blockStack = this.blockStack;
|
|
404
|
-
return this.include(expression.slice(0, expressionEnd), blockStack[blockStack.length - blockBack].data);
|
|
409
|
+
return this.include(this.includePath(expression.slice(0, expressionEnd)), blockStack[blockStack.length - blockBack].data);
|
|
405
410
|
}
|
|
406
411
|
if (expression[expressionEnd] === ')') {
|
|
407
412
|
const openPosition = expression.lastIndexOf('(');
|
|
408
|
-
return this.include(expression.slice(0, openPosition), await this.parsePath(expression.slice(openPosition + 1, expression.length - 1), data));
|
|
413
|
+
return this.include(this.includePath(expression.slice(0, openPosition)), await this.parsePath(expression.slice(openPosition + 1, expression.length - 1), data));
|
|
409
414
|
}
|
|
410
|
-
return this.include(expression, data);
|
|
415
|
+
return this.include(this.includePath(expression), data);
|
|
411
416
|
}
|
|
412
417
|
let onlyDots = true;
|
|
413
418
|
for (const c of expression) {
|
package/esm/template.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export declare class Template {
|
|
|
108
108
|
targetStack: string[];
|
|
109
109
|
};
|
|
110
110
|
include(path: string, data: any): Promise<string>;
|
|
111
|
+
includePath(filePath: string): string;
|
|
111
112
|
isContextClean(): boolean;
|
|
112
113
|
literalTarget(index: number, isTitle?: boolean): void;
|
|
113
114
|
parseBuffer(buffer: string): Promise<string>;
|
package/esm/template.js
CHANGED
|
@@ -221,6 +221,11 @@ export class Template {
|
|
|
221
221
|
? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
|
|
222
222
|
: parsed;
|
|
223
223
|
}
|
|
224
|
+
includePath(filePath) {
|
|
225
|
+
return (filePath[0] === '/')
|
|
226
|
+
? (appDir + ((filePath[1] === '@') ? '/node_modules' : '') + filePath)
|
|
227
|
+
: filePath;
|
|
228
|
+
}
|
|
224
229
|
isContextClean() {
|
|
225
230
|
const clean = this.getCleanContext();
|
|
226
231
|
const context = this.getContext();
|
|
@@ -396,13 +401,13 @@ export class Template {
|
|
|
396
401
|
expressionEnd--;
|
|
397
402
|
}
|
|
398
403
|
const blockStack = this.blockStack;
|
|
399
|
-
return this.include(expression.slice(0, expressionEnd), blockStack[blockStack.length - blockBack].data);
|
|
404
|
+
return this.include(this.includePath(expression.slice(0, expressionEnd)), blockStack[blockStack.length - blockBack].data);
|
|
400
405
|
}
|
|
401
406
|
if (expression[expressionEnd] === ')') {
|
|
402
407
|
const openPosition = expression.lastIndexOf('(');
|
|
403
|
-
return this.include(expression.slice(0, openPosition), await this.parsePath(expression.slice(openPosition + 1, expression.length - 1), data));
|
|
408
|
+
return this.include(this.includePath(expression.slice(0, openPosition)), await this.parsePath(expression.slice(openPosition + 1, expression.length - 1), data));
|
|
404
409
|
}
|
|
405
|
-
return this.include(expression, data);
|
|
410
|
+
return this.include(this.includePath(expression), data);
|
|
406
411
|
}
|
|
407
412
|
let onlyDots = true;
|
|
408
413
|
for (const c of expression) {
|
package/package.json
CHANGED