honkit 6.0.4 → 6.1.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.
- package/lib/__tests__/__fixtures__/honkit/book.d.ts +7 -0
- package/lib/__tests__/__fixtures__/honkit/book.d.ts.map +1 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/e2e.test.d.ts +2 -0
- package/lib/__tests__/e2e.test.d.ts.map +1 -0
- package/lib/__tests__/e2e.test.js +81 -0
- package/lib/__tests__/init.d.ts +2 -0
- package/lib/__tests__/init.d.ts.map +1 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/satisfies.d.ts +2 -0
- package/lib/__tests__/satisfies.d.ts.map +1 -0
- package/lib/__tests__/satisfies.js +11 -0
- package/lib/__tests__/snapshot-asciidoc.d.ts +2 -0
- package/lib/__tests__/snapshot-asciidoc.d.ts.map +1 -0
- package/lib/__tests__/snapshot-asciidoc.js +48 -0
- package/lib/__tests__/snapshot-honkit.d.ts +2 -0
- package/lib/__tests__/snapshot-honkit.d.ts.map +1 -0
- package/lib/__tests__/snapshot-honkit.js +48 -0
- package/lib/constants/__tests__/configSchema.d.ts +2 -0
- package/lib/constants/__tests__/configSchema.d.ts.map +1 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/fs/__tests__/mock.d.ts +2 -0
- package/lib/fs/__tests__/mock.d.ts.map +1 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/models/__tests__/config.d.ts +2 -0
- package/lib/models/__tests__/config.d.ts.map +1 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.d.ts +2 -0
- package/lib/models/__tests__/glossary.d.ts.map +1 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.d.ts +2 -0
- package/lib/models/__tests__/glossaryEntry.d.ts.map +1 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.d.ts +2 -0
- package/lib/models/__tests__/page.d.ts.map +1 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.d.ts +2 -0
- package/lib/models/__tests__/plugin.d.ts.map +1 -0
- package/lib/models/__tests__/plugin.js +50 -0
- package/lib/models/__tests__/pluginDependency.d.ts +2 -0
- package/lib/models/__tests__/pluginDependency.d.ts.map +1 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.d.ts +2 -0
- package/lib/models/__tests__/summary.d.ts.map +1 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.d.ts +2 -0
- package/lib/models/__tests__/summaryArticle.d.ts.map +1 -0
- package/lib/models/__tests__/summaryArticle.js +117 -0
- package/lib/models/__tests__/summaryPart.d.ts +2 -0
- package/lib/models/__tests__/summaryPart.d.ts.map +1 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.d.ts +2 -0
- package/lib/models/__tests__/templateBlock.d.ts.map +1 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.d.ts +2 -0
- package/lib/models/__tests__/templateEngine.d.ts.map +1 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/modifiers/config/__tests__/addPlugin.d.ts +2 -0
- package/lib/modifiers/config/__tests__/addPlugin.d.ts.map +1 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.d.ts +2 -0
- package/lib/modifiers/config/__tests__/removePlugin.d.ts.map +1 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.d.ts +2 -0
- package/lib/modifiers/config/__tests__/togglePlugin.d.ts.map +1 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/insertArticle.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/insertPart.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/moveArticle.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.d.ts +2 -0
- package/lib/modifiers/summary/__tests__/removeArticle.d.ts.map +1 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/output/__tests__/ebook.d.ts +2 -0
- package/lib/output/__tests__/ebook.d.ts.map +1 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.d.ts +2 -0
- package/lib/output/__tests__/json.d.ts.map +1 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.d.ts +2 -0
- package/lib/output/__tests__/plugin-hooks.d.ts.map +1 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.d.ts +2 -0
- package/lib/output/__tests__/website.d.ts.map +1 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/modifiers/__tests__/addHeadingId.d.ts +2 -0
- package/lib/output/modifiers/__tests__/addHeadingId.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.d.ts +2 -0
- package/lib/output/modifiers/__tests__/annotateText.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/annotateText.js +71 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.d.ts +2 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +69 -0
- package/lib/output/modifiers/__tests__/highlightCode.d.ts +2 -0
- package/lib/output/modifiers/__tests__/highlightCode.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.d.ts +2 -0
- package/lib/output/modifiers/__tests__/inlinePng.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.d.ts +2 -0
- package/lib/output/modifiers/__tests__/inlineSvg.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.d.ts +2 -0
- package/lib/output/modifiers/__tests__/resolveImages.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.d.ts +2 -0
- package/lib/output/modifiers/__tests__/resolveLinks.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.d.ts +2 -0
- package/lib/output/modifiers/__tests__/svgToImg.d.ts.map +1 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/website/__tests__/i18n.d.ts +2 -0
- package/lib/output/website/__tests__/i18n.d.ts.map +1 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/parse/__tests__/listAssets.d.ts +2 -0
- package/lib/parse/__tests__/listAssets.d.ts.map +1 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.d.ts +2 -0
- package/lib/parse/__tests__/parseBook.d.ts.map +1 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.d.ts +2 -0
- package/lib/parse/__tests__/parseGlossary.d.ts.map +1 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.d.ts +2 -0
- package/lib/parse/__tests__/parseIgnore.d.ts.map +1 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.d.ts +2 -0
- package/lib/parse/__tests__/parsePageFromString.d.ts.map +1 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.d.ts +2 -0
- package/lib/parse/__tests__/parseReadme.d.ts.map +1 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.d.ts +2 -0
- package/lib/parse/__tests__/parseSummary.d.ts.map +1 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/plugins/__tests__/listDependencies.d.ts +2 -0
- package/lib/plugins/__tests__/listDependencies.d.ts.map +1 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.d.ts +2 -0
- package/lib/plugins/__tests__/sortDependencies.d.ts.map +1 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.d.ts +2 -0
- package/lib/plugins/__tests__/validatePlugin.d.ts.map +1 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/templating/__tests__/conrefsLoader.d.ts +2 -0
- package/lib/templating/__tests__/conrefsLoader.d.ts.map +1 -0
- package/lib/templating/__tests__/conrefsLoader.js +90 -0
- package/lib/templating/__tests__/postRender.d.ts +2 -0
- package/lib/templating/__tests__/postRender.d.ts.map +1 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.d.ts +2 -0
- package/lib/templating/__tests__/replaceShortcuts.d.ts.map +1 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/utils/__tests__/git.d.ts +2 -0
- package/lib/utils/__tests__/git.d.ts.map +1 -0
- package/lib/utils/__tests__/git.js +46 -0
- package/lib/utils/__tests__/location.d.ts +2 -0
- package/lib/utils/__tests__/location.d.ts.map +1 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.d.ts +2 -0
- package/lib/utils/__tests__/path.d.ts.map +1 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/package.json +17 -19
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const page_1 = __importDefault(require("../page"));
|
|
8
|
+
describe("Page", () => {
|
|
9
|
+
describe("toText", () => {
|
|
10
|
+
test("must not prepend frontmatter if no attributes", () => {
|
|
11
|
+
const page = new page_1.default().merge({
|
|
12
|
+
content: "Hello World",
|
|
13
|
+
});
|
|
14
|
+
expect(page.toText()).toBe("Hello World");
|
|
15
|
+
});
|
|
16
|
+
test("must prepend frontmatter if attributes", () => {
|
|
17
|
+
const page = new page_1.default().merge({
|
|
18
|
+
content: "Hello World",
|
|
19
|
+
attributes: immutable_1.default.fromJS({
|
|
20
|
+
hello: "world",
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
expect(page.toText()).toBe("---\nhello: world\n---\n\nHello World");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/plugin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const plugin_1 = __importDefault(require("../plugin"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
describe("Plugin", () => {
|
|
9
|
+
describe("createFromString", () => {
|
|
10
|
+
test("must parse name", () => {
|
|
11
|
+
const plugin = plugin_1.default.createFromString("hello");
|
|
12
|
+
expect(plugin.getName()).toBe("hello");
|
|
13
|
+
expect(plugin.getVersion()).toBe("*");
|
|
14
|
+
});
|
|
15
|
+
test("must parse version", () => {
|
|
16
|
+
const plugin = plugin_1.default.createFromString("hello@1.0.0");
|
|
17
|
+
expect(plugin.getName()).toBe("hello");
|
|
18
|
+
expect(plugin.getVersion()).toBe("1.0.0");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("getNpmId", () => {
|
|
22
|
+
it("should return package's name", () => {
|
|
23
|
+
const plugin = new plugin_1.default({
|
|
24
|
+
name: "testplugin",
|
|
25
|
+
version: "*",
|
|
26
|
+
path: "test.js",
|
|
27
|
+
package: immutable_1.default.fromJS({
|
|
28
|
+
name: "testplugin-name"
|
|
29
|
+
}),
|
|
30
|
+
content: immutable_1.default.fromJS({
|
|
31
|
+
hooks: {
|
|
32
|
+
"page:before": function (page) {
|
|
33
|
+
return page;
|
|
34
|
+
},
|
|
35
|
+
page: function (page) {
|
|
36
|
+
return page;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
expect(plugin.getNpmID()).toBe("testplugin-name");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("isLoaded", () => {
|
|
45
|
+
test("must return false for empty plugin", () => {
|
|
46
|
+
const plugin = plugin_1.default.createFromString("hello");
|
|
47
|
+
expect(plugin.isLoaded()).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginDependency.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/pluginDependency.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const pluginDependency_1 = __importDefault(require("../pluginDependency"));
|
|
8
|
+
describe("PluginDependency", () => {
|
|
9
|
+
describe("createFromString", () => {
|
|
10
|
+
test("must parse name", () => {
|
|
11
|
+
const plugin = pluginDependency_1.default.createFromString("hello");
|
|
12
|
+
expect(plugin.getName()).toBe("hello");
|
|
13
|
+
expect(plugin.getVersion()).toBe("*");
|
|
14
|
+
});
|
|
15
|
+
test("must parse state", () => {
|
|
16
|
+
const plugin = pluginDependency_1.default.createFromString("-hello");
|
|
17
|
+
expect(plugin.getName()).toBe("hello");
|
|
18
|
+
expect(plugin.isEnabled()).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
describe("Version", () => {
|
|
21
|
+
test("must parse version", () => {
|
|
22
|
+
const plugin = pluginDependency_1.default.createFromString("hello@1.0.0");
|
|
23
|
+
expect(plugin.getName()).toBe("hello");
|
|
24
|
+
expect(plugin.getVersion()).toBe("1.0.0");
|
|
25
|
+
});
|
|
26
|
+
test("must parse semver", () => {
|
|
27
|
+
const plugin = pluginDependency_1.default.createFromString("hello@>=4.0.0");
|
|
28
|
+
expect(plugin.getName()).toBe("hello");
|
|
29
|
+
expect(plugin.getVersion()).toBe(">=4.0.0");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("GIT Version", () => {
|
|
33
|
+
test("must handle HTTPS urls", () => {
|
|
34
|
+
const plugin = pluginDependency_1.default.createFromString("hello@git+https://github.com/GitbookIO/plugin-ga.git");
|
|
35
|
+
expect(plugin.getName()).toBe("hello");
|
|
36
|
+
expect(plugin.getVersion()).toBe("git+https://github.com/GitbookIO/plugin-ga.git");
|
|
37
|
+
});
|
|
38
|
+
test("must handle SSH urls", () => {
|
|
39
|
+
const plugin = pluginDependency_1.default.createFromString("hello@git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
|
|
40
|
+
expect(plugin.getName()).toBe("hello");
|
|
41
|
+
expect(plugin.getVersion()).toBe("git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("listToArray", () => {
|
|
45
|
+
test("must create an array from a list of plugin dependencies", () => {
|
|
46
|
+
const list = pluginDependency_1.default.listToArray(immutable_1.default.List([
|
|
47
|
+
pluginDependency_1.default.createFromString("hello@1.0.0"),
|
|
48
|
+
pluginDependency_1.default.createFromString("noversion"),
|
|
49
|
+
pluginDependency_1.default.createFromString("-disabled"),
|
|
50
|
+
]));
|
|
51
|
+
expect(list).toEqual(["hello@1.0.0", "noversion", "-disabled"]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("listFromArray", () => {
|
|
55
|
+
test("must create an array from a list of plugin dependencies", () => {
|
|
56
|
+
const arr = immutable_1.default.fromJS([
|
|
57
|
+
"hello@1.0.0",
|
|
58
|
+
{
|
|
59
|
+
name: "plugin-ga",
|
|
60
|
+
version: "git+ssh://samy@github.com/GitbookIO/plugin-ga.git",
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
const list = pluginDependency_1.default.listFromArray(arr);
|
|
64
|
+
expect(list.first().getName()).toBe("hello");
|
|
65
|
+
expect(list.first().getVersion()).toBe("1.0.0");
|
|
66
|
+
expect(list.last().getName()).toBe("plugin-ga");
|
|
67
|
+
expect(list.last().getVersion()).toBe("git+ssh://samy@github.com/GitbookIO/plugin-ga.git");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/summary.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const summary_1 = __importDefault(require("../summary"));
|
|
7
|
+
const file_1 = __importDefault(require("../file"));
|
|
8
|
+
describe("Summary", () => {
|
|
9
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
10
|
+
{
|
|
11
|
+
articles: [
|
|
12
|
+
// 1.1
|
|
13
|
+
{
|
|
14
|
+
title: "My First Article",
|
|
15
|
+
ref: "README.md",
|
|
16
|
+
},
|
|
17
|
+
// 1.2
|
|
18
|
+
{
|
|
19
|
+
title: "My Second Article",
|
|
20
|
+
ref: "article.md",
|
|
21
|
+
},
|
|
22
|
+
// 1.3
|
|
23
|
+
{
|
|
24
|
+
title: "My Third Article with anchor",
|
|
25
|
+
ref: "article-anchor.md",
|
|
26
|
+
articles: [
|
|
27
|
+
{
|
|
28
|
+
title: "Article with anchor",
|
|
29
|
+
ref: "article-anchor.md#anchor",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
// 1.4
|
|
34
|
+
{
|
|
35
|
+
title: "Article without ref",
|
|
36
|
+
},
|
|
37
|
+
// 1.5
|
|
38
|
+
{
|
|
39
|
+
title: "Article with absolute ref",
|
|
40
|
+
ref: "https://google.fr",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: "Test",
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
describe("createFromEntries", () => {
|
|
49
|
+
test("must add all parts", () => {
|
|
50
|
+
const parts = summary.getParts();
|
|
51
|
+
expect(parts.size).toBe(2);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("getNextArticle", () => {
|
|
55
|
+
it("return next article", () => {
|
|
56
|
+
const nextArticle = summary.getNextArticle("1.1");
|
|
57
|
+
expect(nextArticle.getLevel()).toBe("1.2");
|
|
58
|
+
});
|
|
59
|
+
it("ignore anchor article", () => {
|
|
60
|
+
const nextArticle = summary.getNextArticle("1.3"); // next is anchor
|
|
61
|
+
expect(nextArticle.getLevel()).toBe("1.4");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("getPrevArticle", () => {
|
|
65
|
+
it("return prev article", () => {
|
|
66
|
+
const prevArticle = summary.getPrevArticle("1.2");
|
|
67
|
+
expect(prevArticle.getLevel()).toBe("1.1");
|
|
68
|
+
});
|
|
69
|
+
it("ignore anchor article", () => {
|
|
70
|
+
const prevArticle = summary.getPrevArticle("1.4");
|
|
71
|
+
expect(prevArticle.getLevel()).toBe("1.3");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("getByLevel", () => {
|
|
75
|
+
test("can return a Part", () => {
|
|
76
|
+
const part = summary.getByLevel("1");
|
|
77
|
+
expect(part).toBeDefined();
|
|
78
|
+
expect(part.getArticles().size).toBe(5);
|
|
79
|
+
});
|
|
80
|
+
test("can return a Part (2)", () => {
|
|
81
|
+
const part = summary.getByLevel("2");
|
|
82
|
+
expect(part).toBeDefined();
|
|
83
|
+
expect(part.getTitle()).toBe("Test");
|
|
84
|
+
expect(part.getArticles().size).toBe(0);
|
|
85
|
+
});
|
|
86
|
+
test("can return an Article", () => {
|
|
87
|
+
const article = summary.getByLevel("1.1");
|
|
88
|
+
expect(article).toBeDefined();
|
|
89
|
+
expect(article.getTitle()).toBe("My First Article");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe("getByPath", () => {
|
|
93
|
+
test("return correct article", () => {
|
|
94
|
+
const article = summary.getByPath("README.md");
|
|
95
|
+
expect(article).toBeDefined();
|
|
96
|
+
expect(article.getTitle()).toBe("My First Article");
|
|
97
|
+
});
|
|
98
|
+
test("return correct article", () => {
|
|
99
|
+
const article = summary.getByPath("article.md");
|
|
100
|
+
expect(article).toBeDefined();
|
|
101
|
+
expect(article.getTitle()).toBe("My Second Article");
|
|
102
|
+
});
|
|
103
|
+
test("return undefined if not found", () => {
|
|
104
|
+
const article = summary.getByPath("NOT_EXISTING.md");
|
|
105
|
+
expect(article).toBeFalsy();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("toText", () => {
|
|
109
|
+
test("return as markdown", () => {
|
|
110
|
+
return summary.toText(".md").then((text) => {
|
|
111
|
+
expect(text).toContain("# Summary");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summaryArticle.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/summaryArticle.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const summaryArticle_1 = __importDefault(require("../summaryArticle"));
|
|
7
|
+
const file_1 = __importDefault(require("../file"));
|
|
8
|
+
const encodeSummaryArticleWithCache_1 = __importDefault(require("../../json/encodeSummaryArticleWithCache"));
|
|
9
|
+
const encodeSummaryArticle_1 = __importDefault(require("../../json/encodeSummaryArticle"));
|
|
10
|
+
describe("SummaryArticle", () => {
|
|
11
|
+
describe("createChildLevel", () => {
|
|
12
|
+
test("must create the right level", () => {
|
|
13
|
+
const article = summaryArticle_1.default.create({}, "1.1");
|
|
14
|
+
expect(article.createChildLevel()).toBe("1.1.1");
|
|
15
|
+
});
|
|
16
|
+
test("must create the right level when has articles", () => {
|
|
17
|
+
const article = summaryArticle_1.default.create({
|
|
18
|
+
articles: [
|
|
19
|
+
{
|
|
20
|
+
title: "Test",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}, "1.1");
|
|
24
|
+
expect(article.createChildLevel()).toBe("1.1.2");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("isFile", () => {
|
|
28
|
+
test("must return true when exactly the file", () => {
|
|
29
|
+
const article = summaryArticle_1.default.create({
|
|
30
|
+
ref: "hello.md",
|
|
31
|
+
}, "1.1");
|
|
32
|
+
const file = file_1.default.createWithFilepath("hello.md");
|
|
33
|
+
expect(article.isFile(file)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
test("must return true when path is not normalized", () => {
|
|
36
|
+
const article = summaryArticle_1.default.create({
|
|
37
|
+
ref: "/hello.md",
|
|
38
|
+
}, "1.1");
|
|
39
|
+
const file = file_1.default.createWithFilepath("hello.md");
|
|
40
|
+
expect(article.isFile(file)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
test("must return false when has anchor", () => {
|
|
43
|
+
const article = summaryArticle_1.default.create({
|
|
44
|
+
ref: "hello.md#world",
|
|
45
|
+
}, "1.1");
|
|
46
|
+
const file = file_1.default.createWithFilepath("hello.md");
|
|
47
|
+
expect(article.isFile(file)).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe("hasAnchor", function () {
|
|
51
|
+
it("must return false when ref does not have anchor", function () {
|
|
52
|
+
var article = summaryArticle_1.default.create({
|
|
53
|
+
ref: "hello.md",
|
|
54
|
+
}, "1.1");
|
|
55
|
+
expect(article.hasAnchor()).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
it("must return true when has anchor", function () {
|
|
58
|
+
var article = summaryArticle_1.default.create({
|
|
59
|
+
ref: "hello.md#world",
|
|
60
|
+
}, "1.1");
|
|
61
|
+
expect(article.hasAnchor()).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("withCache", function () {
|
|
65
|
+
it("encodeSummaryArticle (non cached) should return an object", function () {
|
|
66
|
+
var article = summaryArticle_1.default.create({
|
|
67
|
+
ref: "1-1.md",
|
|
68
|
+
}, "1.1");
|
|
69
|
+
expect((0, encodeSummaryArticle_1.default)(article)).toBeInstanceOf(Object);
|
|
70
|
+
});
|
|
71
|
+
it("encodeSummaryArticleWithCache (cached) should return an object", function () {
|
|
72
|
+
var article = summaryArticle_1.default.create({
|
|
73
|
+
ref: "1-1.md",
|
|
74
|
+
}, "1.1");
|
|
75
|
+
expect((0, encodeSummaryArticleWithCache_1.default)(article)).toBeInstanceOf(Object);
|
|
76
|
+
});
|
|
77
|
+
it("encodeSummaryArticle (non cached) should return different object when pass difference SummaryArticle", function () {
|
|
78
|
+
var article_1 = summaryArticle_1.default.create({
|
|
79
|
+
ref: "1-1.md"
|
|
80
|
+
}, "1.1");
|
|
81
|
+
var article_2 = summaryArticle_1.default.create({
|
|
82
|
+
ref: "1-2.md"
|
|
83
|
+
}, "1.2");
|
|
84
|
+
expect((0, encodeSummaryArticle_1.default)(article_1)).not.toStrictEqual((0, encodeSummaryArticle_1.default)(article_2));
|
|
85
|
+
});
|
|
86
|
+
it("encodeSummaryArticle (non cached) should return same object when pass same SummaryArticle", function () {
|
|
87
|
+
var article = summaryArticle_1.default.create({
|
|
88
|
+
ref: "1-1.md"
|
|
89
|
+
}, "1.1");
|
|
90
|
+
expect((0, encodeSummaryArticle_1.default)(article)).toStrictEqual((0, encodeSummaryArticle_1.default)(article));
|
|
91
|
+
});
|
|
92
|
+
it("encodeSummaryArticleWithCache (cached) should return different object when pass difference SummaryArticle", function () {
|
|
93
|
+
var article_1 = summaryArticle_1.default.create({
|
|
94
|
+
ref: "1-1.md"
|
|
95
|
+
}, "1.1");
|
|
96
|
+
var article_2 = summaryArticle_1.default.create({
|
|
97
|
+
ref: "1-2.md"
|
|
98
|
+
}, "1.2");
|
|
99
|
+
expect((0, encodeSummaryArticle_1.default)(article_1)).not.toStrictEqual((0, encodeSummaryArticleWithCache_1.default)(article_2));
|
|
100
|
+
});
|
|
101
|
+
it("encodeSummaryArticleWithCache (cached) should return same object when pass same SummaryArticle", function () {
|
|
102
|
+
var article = summaryArticle_1.default.create({
|
|
103
|
+
ref: "1-1.md"
|
|
104
|
+
}, "1.1");
|
|
105
|
+
expect((0, encodeSummaryArticle_1.default)(article)).toStrictEqual((0, encodeSummaryArticle_1.default)(article));
|
|
106
|
+
});
|
|
107
|
+
it("encodeSummaryArticle (non cached) and encodeSummaryArticleWithCache (cached) should return same object when pass same SummaryArticle", function () {
|
|
108
|
+
var article = summaryArticle_1.default.create({
|
|
109
|
+
ref: "1-1.md",
|
|
110
|
+
articles: [summaryArticle_1.default.create({
|
|
111
|
+
ref: "2-1.md",
|
|
112
|
+
}, "2.1")]
|
|
113
|
+
}, "1.1");
|
|
114
|
+
expect((0, encodeSummaryArticle_1.default)(article)).toStrictEqual((0, encodeSummaryArticleWithCache_1.default)(article));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summaryPart.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/summaryPart.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const summaryPart_1 = __importDefault(require("../summaryPart"));
|
|
7
|
+
describe("SummaryPart", () => {
|
|
8
|
+
describe("createChildLevel", () => {
|
|
9
|
+
test("must create the right level", () => {
|
|
10
|
+
const article = summaryPart_1.default.create({}, "1");
|
|
11
|
+
expect(article.createChildLevel()).toBe("1.1");
|
|
12
|
+
});
|
|
13
|
+
test("must create the right level when has articles", () => {
|
|
14
|
+
const article = summaryPart_1.default.create({
|
|
15
|
+
articles: [
|
|
16
|
+
{
|
|
17
|
+
title: "Test",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
}, "1");
|
|
21
|
+
expect(article.createChildLevel()).toBe("1.2");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateBlock.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/templateBlock.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
9
|
+
const templateBlock_1 = __importDefault(require("../templateBlock"));
|
|
10
|
+
describe("TemplateBlock", () => {
|
|
11
|
+
describe("create", () => {
|
|
12
|
+
test("must initialize a simple TemplateBlock from a function", () => {
|
|
13
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
14
|
+
return {
|
|
15
|
+
body: "<p>Hello, World!</p>",
|
|
16
|
+
parse: true,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
// Check basic templateBlock properties
|
|
20
|
+
expect(templateBlock.getName()).toBe("sayhello");
|
|
21
|
+
expect(templateBlock.getEndTag()).toBe("endsayhello");
|
|
22
|
+
expect(templateBlock.getBlocks().size).toBe(0);
|
|
23
|
+
expect(templateBlock.getExtensionName()).toBe("BlocksayhelloExtension");
|
|
24
|
+
// Check result of applying block
|
|
25
|
+
return (0, promise_1.default)()
|
|
26
|
+
.then(() => {
|
|
27
|
+
return templateBlock.applyBlock();
|
|
28
|
+
})
|
|
29
|
+
.then((result) => {
|
|
30
|
+
expect(result.name).toBe("sayhello");
|
|
31
|
+
expect(result.body).toBe("<p>Hello, World!</p>");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("getShortcuts", () => {
|
|
36
|
+
test("must return undefined if no shortcuts", () => {
|
|
37
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
38
|
+
return {
|
|
39
|
+
body: "<p>Hello, World!</p>",
|
|
40
|
+
parse: true,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
expect(templateBlock.getShortcuts()).toBeFalsy();
|
|
44
|
+
});
|
|
45
|
+
test("must return complete shortcut", () => {
|
|
46
|
+
const templateBlock = templateBlock_1.default.create("sayhello", {
|
|
47
|
+
process: function (block) {
|
|
48
|
+
return "<p>Hello, World!</p>";
|
|
49
|
+
},
|
|
50
|
+
shortcuts: {
|
|
51
|
+
parsers: ["markdown"],
|
|
52
|
+
start: "$",
|
|
53
|
+
end: "-",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const shortcut = templateBlock.getShortcuts();
|
|
57
|
+
expect(shortcut).toBeDefined();
|
|
58
|
+
expect(shortcut.getStart()).toEqual("$");
|
|
59
|
+
expect(shortcut.getEnd()).toEqual("-");
|
|
60
|
+
expect(shortcut.getStartTag()).toEqual("sayhello");
|
|
61
|
+
expect(shortcut.getEndTag()).toEqual("endsayhello");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("toNunjucksExt()", () => {
|
|
65
|
+
test("should replace by block anchor", () => {
|
|
66
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
67
|
+
return "Hello";
|
|
68
|
+
});
|
|
69
|
+
let blocks = {};
|
|
70
|
+
// Create a fresh Nunjucks environment
|
|
71
|
+
const env = new nunjucks_1.default.Environment(null, { autoescape: false });
|
|
72
|
+
// Add template block to environement
|
|
73
|
+
const Ext = templateBlock.toNunjucksExt({}, blocks);
|
|
74
|
+
env.addExtension(templateBlock.getExtensionName(), new Ext());
|
|
75
|
+
// Render a template using the block
|
|
76
|
+
const src = "{% sayhello %}{% endsayhello %}";
|
|
77
|
+
return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
|
|
78
|
+
blocks = immutable_1.default.fromJS(blocks);
|
|
79
|
+
expect(blocks.size).toBe(1);
|
|
80
|
+
const blockId = blocks.keySeq().get(0);
|
|
81
|
+
const block = blocks.get(blockId);
|
|
82
|
+
expect(res).toBe(`{{-%${blockId}%-}}`);
|
|
83
|
+
expect(block.get("body")).toBe("Hello");
|
|
84
|
+
expect(block.get("name")).toBe("sayhello");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
test("must create a valid nunjucks extension", () => {
|
|
88
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
89
|
+
return {
|
|
90
|
+
body: "<p>Hello, World!</p>",
|
|
91
|
+
parse: true,
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
// Create a fresh Nunjucks environment
|
|
95
|
+
const env = new nunjucks_1.default.Environment(null, { autoescape: false });
|
|
96
|
+
// Add template block to environement
|
|
97
|
+
const Ext = templateBlock.toNunjucksExt();
|
|
98
|
+
env.addExtension(templateBlock.getExtensionName(), new Ext());
|
|
99
|
+
// Render a template using the block
|
|
100
|
+
const src = "{% sayhello %}{% endsayhello %}";
|
|
101
|
+
return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
|
|
102
|
+
expect(res).toBe("<p>Hello, World!</p>");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
test("must apply block arguments correctly", () => {
|
|
106
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
107
|
+
return {
|
|
108
|
+
body: `<${block.kwargs.tag}>Hello, ${block.kwargs.name}!</${block.kwargs.tag}>`,
|
|
109
|
+
parse: true,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
// Create a fresh Nunjucks environment
|
|
113
|
+
const env = new nunjucks_1.default.Environment(null, { autoescape: false });
|
|
114
|
+
// Add template block to environement
|
|
115
|
+
const Ext = templateBlock.toNunjucksExt();
|
|
116
|
+
env.addExtension(templateBlock.getExtensionName(), new Ext());
|
|
117
|
+
// Render a template using the block
|
|
118
|
+
const src = '{% sayhello name="Samy", tag="p" %}{% endsayhello %}';
|
|
119
|
+
return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
|
|
120
|
+
expect(res).toBe("<p>Hello, Samy!</p>");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
test("must accept an async function", () => {
|
|
124
|
+
const templateBlock = templateBlock_1.default.create("sayhello", (block) => {
|
|
125
|
+
return (0, promise_1.default)().then(() => {
|
|
126
|
+
return {
|
|
127
|
+
body: `Hello ${block.body}`,
|
|
128
|
+
parse: true,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
// Create a fresh Nunjucks environment
|
|
133
|
+
const env = new nunjucks_1.default.Environment(null, { autoescape: false });
|
|
134
|
+
// Add template block to environement
|
|
135
|
+
const Ext = templateBlock.toNunjucksExt();
|
|
136
|
+
env.addExtension(templateBlock.getExtensionName(), new Ext());
|
|
137
|
+
// Render a template using the block
|
|
138
|
+
const src = "{% sayhello %}Samy{% endsayhello %}";
|
|
139
|
+
return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
|
|
140
|
+
expect(res).toBe("Hello Samy");
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
test("must handle nested blocks", () => {
|
|
144
|
+
const templateBlock = new templateBlock_1.default({
|
|
145
|
+
name: "yoda",
|
|
146
|
+
blocks: immutable_1.default.List(["start", "end"]),
|
|
147
|
+
process: function (block) {
|
|
148
|
+
const nested = {};
|
|
149
|
+
block.blocks.forEach((blk) => {
|
|
150
|
+
nested[blk.name] = blk.body.trim();
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
body: `<p class="yoda">${nested.end} ${nested.start}</p>`,
|
|
154
|
+
parse: true,
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
// Create a fresh Nunjucks environment
|
|
159
|
+
const env = new nunjucks_1.default.Environment(null, { autoescape: false });
|
|
160
|
+
// Add template block to environement
|
|
161
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'toNunjucksExt' does not exist on type 'M... Remove this comment to see the full error message
|
|
162
|
+
const Ext = templateBlock.toNunjucksExt();
|
|
163
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'getExtensionName' does not exist on type... Remove this comment to see the full error message
|
|
164
|
+
env.addExtension(templateBlock.getExtensionName(), new Ext());
|
|
165
|
+
// Render a template using the block
|
|
166
|
+
const src = "{% yoda %}{% start %}this sentence should be{% end %}inverted{% endyoda %}";
|
|
167
|
+
return promise_1.default.nfcall(env.renderString.bind(env), src).then((res) => {
|
|
168
|
+
expect(res).toBe('<p class="yoda">inverted this sentence should be</p>');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateEngine.d.ts","sourceRoot":"","sources":["../../../src/models/__tests__/templateEngine.ts"],"names":[],"mappings":""}
|