mancha 0.9.0 → 0.9.4

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.
@@ -1,68 +0,0 @@
1
- import * as path from "path";
2
- import * as stream from "stream";
3
- import * as through from "through2";
4
- import { Renderer } from "./index.js";
5
- /**
6
- * Main entrypoint to be used in Gulp. Usage:
7
- *
8
- * var mancha = require('mancha/dist/gulp')
9
- * gulp.src(...).pipe(mancha({myvar: myval})).pipe(...)
10
- *
11
- * @param context <key, value> pairs of literal string replacements. `key` will become `{{ key }}`
12
- * before replacing it with `value` in the processed files.
13
- */
14
- function mancha(context = {}) {
15
- const renderer = new Renderer(context);
16
- return through.obj(function (file, encoding, callback) {
17
- const catcher = (err) => {
18
- console.log(err);
19
- callback(err, file);
20
- };
21
- const dirpath = path.dirname(file.path);
22
- if (file.isNull()) {
23
- callback(null, file);
24
- }
25
- else {
26
- if (file.isBuffer()) {
27
- const chunk = file.contents.toString(encoding);
28
- renderer
29
- .preprocessString(chunk, { dirpath, rootDocument: !file.path.endsWith(".tpl.html") })
30
- .then(async (fragment) => {
31
- await renderer.renderNode(fragment);
32
- const content = renderer.serializeHTML(fragment);
33
- file.contents = Buffer.from(content, encoding);
34
- callback(null, file);
35
- })
36
- .catch(catcher);
37
- }
38
- else if (file.isStream()) {
39
- let docstr = "";
40
- file.contents
41
- .on("data", (chunk) => {
42
- if (Buffer.isBuffer(chunk)) {
43
- docstr += chunk.toString(encoding);
44
- }
45
- else {
46
- docstr += chunk.toString();
47
- }
48
- })
49
- .on("end", () => {
50
- renderer
51
- .preprocessString(docstr, { dirpath, rootDocument: !file.path.endsWith(".tpl.html") })
52
- .then(async (document) => {
53
- await renderer.renderNode(document);
54
- const content = renderer.serializeHTML(document);
55
- const readable = new stream.Readable();
56
- readable._read = function () { };
57
- readable.push(content);
58
- readable.push(null);
59
- file.contents = readable;
60
- callback(null, file);
61
- })
62
- .catch(catcher);
63
- });
64
- }
65
- }
66
- });
67
- }
68
- export default mancha;