honkit 3.6.21
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/LICENSE +202 -0
- package/README.md +10 -0
- package/bin/honkit.js +8 -0
- package/lib/BuildGenerator.js +2 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/githon.js +11 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/snapshot-honkit.js +45 -0
- package/lib/api/decodeConfig.js +17 -0
- package/lib/api/decodeGlobal.js +21 -0
- package/lib/api/decodePage.js +41 -0
- package/lib/api/deprecate.js +113 -0
- package/lib/api/encodeConfig.js +30 -0
- package/lib/api/encodeGlobal.js +226 -0
- package/lib/api/encodeNavigation.js +60 -0
- package/lib/api/encodePage.js +37 -0
- package/lib/api/encodeProgress.js +58 -0
- package/lib/api/encodeSummary.js +52 -0
- package/lib/api/index.js +15 -0
- package/lib/bin.js +46 -0
- package/lib/browser.js +41 -0
- package/lib/cli/build.js +36 -0
- package/lib/cli/buildEbook.js +63 -0
- package/lib/cli/getBook.js +24 -0
- package/lib/cli/getOutputFolder.js +19 -0
- package/lib/cli/index.js +11 -0
- package/lib/cli/init.js +17 -0
- package/lib/cli/options.js +38 -0
- package/lib/cli/parse.js +65 -0
- package/lib/cli/serve.js +184 -0
- package/lib/cli/server.js +116 -0
- package/lib/cli/watch.js +35 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/constants/configDefault.js +9 -0
- package/lib/constants/configFiles.js +3 -0
- package/lib/constants/configSchema.js +235 -0
- package/lib/constants/defaultBlocks.js +48 -0
- package/lib/constants/defaultFilters.js +18 -0
- package/lib/constants/defaultPlugins.js +20 -0
- package/lib/constants/extsAsciidoc.js +3 -0
- package/lib/constants/extsMarkdown.js +3 -0
- package/lib/constants/ignoreFiles.js +3 -0
- package/lib/constants/pluginAssetsFolder.js +3 -0
- package/lib/constants/pluginHooks.js +3 -0
- package/lib/constants/pluginPrefix.js +3 -0
- package/lib/constants/pluginResources.js +7 -0
- package/lib/constants/templatesFolder.js +3 -0
- package/lib/constants/themePrefix.js +3 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/fs/mock.js +88 -0
- package/lib/fs/node.js +44 -0
- package/lib/honkit.js +34 -0
- package/lib/index.js +17 -0
- package/lib/init.js +79 -0
- package/lib/json/encodeBook.js +41 -0
- package/lib/json/encodeBookWithPage.js +25 -0
- package/lib/json/encodeFile.js +20 -0
- package/lib/json/encodeGlossary.js +22 -0
- package/lib/json/encodeGlossaryEntry.js +16 -0
- package/lib/json/encodeLanguages.js +29 -0
- package/lib/json/encodeOutput.js +26 -0
- package/lib/json/encodeOutputWithPage.js +26 -0
- package/lib/json/encodePage.js +38 -0
- package/lib/json/encodeReadme.js +19 -0
- package/lib/json/encodeSummary.js +22 -0
- package/lib/json/encodeSummaryArticle.js +25 -0
- package/lib/json/encodeSummaryPart.js +19 -0
- package/lib/json/index.js +27 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.js +26 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.js +62 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/models/book.js +312 -0
- package/lib/models/config.js +152 -0
- package/lib/models/file.js +83 -0
- package/lib/models/fs.js +255 -0
- package/lib/models/glossary.js +90 -0
- package/lib/models/glossaryEntry.js +34 -0
- package/lib/models/hash.js +191 -0
- package/lib/models/ignore.js +40 -0
- package/lib/models/language.js +22 -0
- package/lib/models/languages.js +64 -0
- package/lib/models/output.js +109 -0
- package/lib/models/page.js +91 -0
- package/lib/models/parser.js +102 -0
- package/lib/models/plugin.js +139 -0
- package/lib/models/pluginDependency.js +192 -0
- package/lib/models/readme.js +38 -0
- package/lib/models/summary.js +199 -0
- package/lib/models/summaryArticle.js +169 -0
- package/lib/models/summaryPart.js +53 -0
- package/lib/models/templateBlock.js +230 -0
- package/lib/models/templateEngine.js +115 -0
- package/lib/models/templateOutput.js +36 -0
- package/lib/models/templateShortcut.js +65 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/config/addPlugin.js +27 -0
- package/lib/modifiers/config/editPlugin.js +13 -0
- package/lib/modifiers/config/getPluginConfig.js +22 -0
- package/lib/modifiers/config/hasPlugin.js +15 -0
- package/lib/modifiers/config/index.js +21 -0
- package/lib/modifiers/config/isDefaultPlugin.js +17 -0
- package/lib/modifiers/config/removePlugin.js +27 -0
- package/lib/modifiers/config/togglePlugin.js +32 -0
- package/lib/modifiers/index.js +11 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/modifiers/summary/editArticleRef.js +20 -0
- package/lib/modifiers/summary/editArticleTitle.js +20 -0
- package/lib/modifiers/summary/editPartTitle.js +21 -0
- package/lib/modifiers/summary/index.js +27 -0
- package/lib/modifiers/summary/indexArticleLevels.js +21 -0
- package/lib/modifiers/summary/indexLevels.js +18 -0
- package/lib/modifiers/summary/indexPartLevels.js +25 -0
- package/lib/modifiers/summary/insertArticle.js +47 -0
- package/lib/modifiers/summary/insertPart.js +21 -0
- package/lib/modifiers/summary/mergeAtLevel.js +68 -0
- package/lib/modifiers/summary/moveArticle.js +27 -0
- package/lib/modifiers/summary/moveArticleAfter.js +59 -0
- package/lib/modifiers/summary/removeArticle.js +36 -0
- package/lib/modifiers/summary/removePart.js +18 -0
- package/lib/modifiers/summary/unshiftArticle.js +27 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/callHook.js +51 -0
- package/lib/output/callPageHook.js +23 -0
- package/lib/output/createTemplateEngine.js +42 -0
- package/lib/output/ebook/getConvertOptions.js +69 -0
- package/lib/output/ebook/getCoverPath.js +30 -0
- package/lib/output/ebook/getPDFTemplate.js +40 -0
- package/lib/output/ebook/index.js +16 -0
- package/lib/output/ebook/onFinish.js +84 -0
- package/lib/output/ebook/onPage.js +23 -0
- package/lib/output/ebook/options.js +17 -0
- package/lib/output/generateAssets.js +26 -0
- package/lib/output/generateBook.js +167 -0
- package/lib/output/generatePage.js +90 -0
- package/lib/output/generatePages.js +52 -0
- package/lib/output/getModifiers.js +63 -0
- package/lib/output/helper/fileToOutput.js +30 -0
- package/lib/output/helper/fileToURL.js +30 -0
- package/lib/output/helper/index.js +3 -0
- package/lib/output/helper/resolveFileToURL.js +25 -0
- package/lib/output/helper/writeFile.js +26 -0
- package/lib/output/index.js +27 -0
- package/lib/output/json/index.js +14 -0
- package/lib/output/json/onFinish.js +39 -0
- package/lib/output/json/onPage.js +37 -0
- package/lib/output/json/options.js +11 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.js +39 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/modifiers/addHeadingId.js +26 -0
- package/lib/output/modifiers/annotateText.js +76 -0
- package/lib/output/modifiers/editHTMLElement.js +17 -0
- package/lib/output/modifiers/fetchRemoteImages.js +42 -0
- package/lib/output/modifiers/highlightCode.js +59 -0
- package/lib/output/modifiers/index.js +26 -0
- package/lib/output/modifiers/inlineAssets.js +29 -0
- package/lib/output/modifiers/inlinePng.js +43 -0
- package/lib/output/modifiers/inlineSvg.js +39 -0
- package/lib/output/modifiers/modifyHTML.js +27 -0
- package/lib/output/modifiers/resolveImages.js +30 -0
- package/lib/output/modifiers/resolveLinks.js +46 -0
- package/lib/output/modifiers/svgToImg.js +58 -0
- package/lib/output/page-cache.js +15 -0
- package/lib/output/prepareAssets.js +22 -0
- package/lib/output/preparePages.js +25 -0
- package/lib/output/preparePlugins.js +36 -0
- package/lib/output/testing/createMock.js +39 -0
- package/lib/output/testing/generateMock.js +55 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/output/website/copyPluginAssets.js +92 -0
- package/lib/output/website/createTemplateEngine.js +136 -0
- package/lib/output/website/index.js +22 -0
- package/lib/output/website/listSearchPaths.js +20 -0
- package/lib/output/website/onAsset.js +29 -0
- package/lib/output/website/onFinish.js +35 -0
- package/lib/output/website/onInit.js +19 -0
- package/lib/output/website/onPage.js +73 -0
- package/lib/output/website/options.js +15 -0
- package/lib/output/website/prepareI18n.js +28 -0
- package/lib/output/website/prepareResources.js +49 -0
- package/lib/output/website/state.js +20 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/parse/findParsableFile.js +33 -0
- package/lib/parse/index.js +31 -0
- package/lib/parse/listAssets.js +36 -0
- package/lib/parse/lookupStructureFile.js +21 -0
- package/lib/parse/parseBook.js +68 -0
- package/lib/parse/parseConfig.js +52 -0
- package/lib/parse/parseGlossary.js +25 -0
- package/lib/parse/parseIgnore.js +43 -0
- package/lib/parse/parseLanguages.js +26 -0
- package/lib/parse/parsePage.js +21 -0
- package/lib/parse/parsePageFromString.js +25 -0
- package/lib/parse/parsePagesList.js +80 -0
- package/lib/parse/parseReadme.js +26 -0
- package/lib/parse/parseStructureFile.js +64 -0
- package/lib/parse/parseSummary.js +43 -0
- package/lib/parse/validateConfig.js +31 -0
- package/lib/parse/walkSummary.js +34 -0
- package/lib/parsers.js +60 -0
- package/lib/plugins/PluginResolver.js +84 -0
- package/lib/plugins/__tests__/findInstalled.js +25 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/plugins/findInstalled.js +87 -0
- package/lib/plugins/index.js +17 -0
- package/lib/plugins/listBlocks.js +19 -0
- package/lib/plugins/listDependencies.js +33 -0
- package/lib/plugins/listDepsForBook.js +20 -0
- package/lib/plugins/listFilters.js +18 -0
- package/lib/plugins/listResources.js +44 -0
- package/lib/plugins/loadForBook.js +38 -0
- package/lib/plugins/loadPlugin.js +89 -0
- package/lib/plugins/package-name-util.js +48 -0
- package/lib/plugins/sortDependencies.js +30 -0
- package/lib/plugins/toNames.js +16 -0
- package/lib/plugins/validateConfig.js +60 -0
- package/lib/plugins/validatePlugin.js +36 -0
- package/lib/templating/__tests__/conrefsLoader.js +93 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/templating/conrefsLoader.js +88 -0
- package/lib/templating/index.js +19 -0
- package/lib/templating/listShortcuts.js +29 -0
- package/lib/templating/postRender.js +46 -0
- package/lib/templating/render.js +41 -0
- package/lib/templating/renderFile.js +39 -0
- package/lib/templating/replaceShortcuts.js +36 -0
- package/lib/templating/themesLoader.js +98 -0
- package/lib/utils/__tests__/git.js +47 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/lib/utils/command.js +104 -0
- package/lib/utils/error.js +88 -0
- package/lib/utils/fs.js +163 -0
- package/lib/utils/genKey.js +13 -0
- package/lib/utils/git.js +116 -0
- package/lib/utils/images.js +22 -0
- package/lib/utils/location.js +129 -0
- package/lib/utils/logger.js +158 -0
- package/lib/utils/mergeDefaults.js +18 -0
- package/lib/utils/path.js +62 -0
- package/lib/utils/promise.js +142 -0
- package/lib/utils/reducedObject.js +31 -0
- package/lib/utils/timing.js +90 -0
- package/package.json +112 -0
|
@@ -0,0 +1,32 @@
|
|
|
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 pluginDependency_1 = __importDefault(require("../../models/pluginDependency"));
|
|
7
|
+
const hasPlugin_1 = __importDefault(require("./hasPlugin"));
|
|
8
|
+
const isDefaultPlugin_1 = __importDefault(require("./isDefaultPlugin"));
|
|
9
|
+
/**
|
|
10
|
+
* Enable/disable a plugin dependency
|
|
11
|
+
* @param {Config} config
|
|
12
|
+
* @param {string} pluginName
|
|
13
|
+
* @param {boolean} state (optional)
|
|
14
|
+
* @return {Config}
|
|
15
|
+
*/
|
|
16
|
+
function togglePlugin(config, pluginName, state) {
|
|
17
|
+
let deps = config.getPluginDependencies();
|
|
18
|
+
// For default plugin, we should ensure it's listed first
|
|
19
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
20
|
+
if (isDefaultPlugin_1.default(pluginName) && !hasPlugin_1.default(deps, pluginName)) {
|
|
21
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
|
|
22
|
+
deps = deps.push(pluginDependency_1.default.create(pluginName));
|
|
23
|
+
}
|
|
24
|
+
deps = deps.map((dep) => {
|
|
25
|
+
if (dep.getName() === pluginName) {
|
|
26
|
+
return dep.toggle(state);
|
|
27
|
+
}
|
|
28
|
+
return dep;
|
|
29
|
+
});
|
|
30
|
+
return config.setPluginDependencies(deps);
|
|
31
|
+
}
|
|
32
|
+
exports.default = togglePlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 config_1 = __importDefault(require("./config"));
|
|
8
|
+
exports.default = {
|
|
9
|
+
Summary: summary_1.default,
|
|
10
|
+
Config: config_1.default,
|
|
11
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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("../../../models/summary"));
|
|
7
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
8
|
+
const editPartTitle_1 = __importDefault(require("../editPartTitle"));
|
|
9
|
+
describe("editPartTitle", () => {
|
|
10
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
11
|
+
{
|
|
12
|
+
articles: [
|
|
13
|
+
{
|
|
14
|
+
title: "My First Article",
|
|
15
|
+
path: "README.md",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: "My Second Article",
|
|
19
|
+
path: "article.md",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: "Test",
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
test("should correctly set title of first part", () => {
|
|
28
|
+
const newSummary = editPartTitle_1.default(summary, 0, "Hello World");
|
|
29
|
+
const part = newSummary.getPart(0);
|
|
30
|
+
expect(part.getTitle()).toBe("Hello World");
|
|
31
|
+
});
|
|
32
|
+
test("should correctly set title of second part", () => {
|
|
33
|
+
const newSummary = editPartTitle_1.default(summary, 1, "Hello");
|
|
34
|
+
const part = newSummary.getPart(1);
|
|
35
|
+
expect(part.getTitle()).toBe("Hello");
|
|
36
|
+
});
|
|
37
|
+
test("should not fail if part doesn't exist", () => {
|
|
38
|
+
const newSummary = editPartTitle_1.default(summary, 3, "Hello");
|
|
39
|
+
expect(newSummary.getParts().size).toBe(2);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
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("../../../models/summary"));
|
|
7
|
+
const summaryArticle_1 = __importDefault(require("../../../models/summaryArticle"));
|
|
8
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
9
|
+
const insertArticle_1 = __importDefault(require("../insertArticle"));
|
|
10
|
+
describe("insertArticle", () => {
|
|
11
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
12
|
+
{
|
|
13
|
+
articles: [
|
|
14
|
+
{
|
|
15
|
+
title: "1.1",
|
|
16
|
+
path: "1.1",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: "1.2",
|
|
20
|
+
path: "1.2",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Part I",
|
|
26
|
+
articles: [
|
|
27
|
+
{
|
|
28
|
+
title: "2.1",
|
|
29
|
+
path: "2.1",
|
|
30
|
+
articles: [
|
|
31
|
+
{
|
|
32
|
+
title: "2.1.1",
|
|
33
|
+
path: "2.1.1",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "2.1.2",
|
|
37
|
+
path: "2.1.2",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: "2.2",
|
|
43
|
+
path: "2.2",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
test("should insert an article at a given level", () => {
|
|
49
|
+
const article = summaryArticle_1.default.create({
|
|
50
|
+
title: "Inserted",
|
|
51
|
+
}, "fake.level");
|
|
52
|
+
const newSummary = insertArticle_1.default(summary, article, "2.1.1");
|
|
53
|
+
const inserted = newSummary.getByLevel("2.1.1");
|
|
54
|
+
const nextOne = newSummary.getByLevel("2.1.2");
|
|
55
|
+
expect(inserted.getTitle()).toBe("Inserted");
|
|
56
|
+
expect(inserted.getLevel()).toBe("2.1.1");
|
|
57
|
+
expect(nextOne.getTitle()).toBe("2.1.1");
|
|
58
|
+
expect(nextOne.getLevel()).toBe("2.1.2");
|
|
59
|
+
});
|
|
60
|
+
test("should insert an article in last position", () => {
|
|
61
|
+
const article = summaryArticle_1.default.create({
|
|
62
|
+
title: "Inserted",
|
|
63
|
+
}, "fake.level");
|
|
64
|
+
const newSummary = insertArticle_1.default(summary, article, "2.2");
|
|
65
|
+
const inserted = newSummary.getByLevel("2.2");
|
|
66
|
+
const previousOne = newSummary.getByLevel("2.1");
|
|
67
|
+
expect(inserted.getTitle()).toBe("Inserted");
|
|
68
|
+
expect(inserted.getLevel()).toBe("2.2");
|
|
69
|
+
expect(previousOne.getTitle()).toBe("2.1"); // Unchanged
|
|
70
|
+
expect(previousOne.getLevel()).toBe("2.1");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
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("../../../models/summary"));
|
|
7
|
+
const summaryPart_1 = __importDefault(require("../../../models/summaryPart"));
|
|
8
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
9
|
+
const insertPart_1 = __importDefault(require("../insertPart"));
|
|
10
|
+
describe("insertPart", () => {
|
|
11
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
12
|
+
{
|
|
13
|
+
articles: [
|
|
14
|
+
{
|
|
15
|
+
title: "1.1",
|
|
16
|
+
path: "1.1",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "Part I",
|
|
22
|
+
articles: [
|
|
23
|
+
{
|
|
24
|
+
title: "2.1",
|
|
25
|
+
path: "2.1",
|
|
26
|
+
articles: [],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: "2.2",
|
|
30
|
+
path: "2.2",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
]);
|
|
35
|
+
test("should insert an part at a given level", () => {
|
|
36
|
+
const part = summaryPart_1.default.create({
|
|
37
|
+
title: "Inserted",
|
|
38
|
+
}, "meaningless.level");
|
|
39
|
+
const newSummary = insertPart_1.default(summary, part, 1);
|
|
40
|
+
const inserted = newSummary.getPart(1);
|
|
41
|
+
expect(inserted.getTitle()).toBe("Inserted");
|
|
42
|
+
expect(newSummary.getParts().count()).toBe(3);
|
|
43
|
+
const otherArticle = newSummary.getByLevel("3.1");
|
|
44
|
+
expect(otherArticle.getTitle()).toBe("2.1");
|
|
45
|
+
expect(otherArticle.getLevel()).toBe("3.1");
|
|
46
|
+
});
|
|
47
|
+
test("should insert an part in last position", () => {
|
|
48
|
+
const part = summaryPart_1.default.create({
|
|
49
|
+
title: "Inserted",
|
|
50
|
+
}, "meaningless.level");
|
|
51
|
+
const newSummary = insertPart_1.default(summary, part, 2);
|
|
52
|
+
const inserted = newSummary.getPart(2);
|
|
53
|
+
expect(inserted.getTitle()).toBe("Inserted");
|
|
54
|
+
expect(newSummary.getParts().count()).toBe(3);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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 summary_1 = __importDefault(require("../../../models/summary"));
|
|
8
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
9
|
+
const mergeAtLevel_1 = __importDefault(require("../mergeAtLevel"));
|
|
10
|
+
describe("mergeAtLevel", () => {
|
|
11
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
12
|
+
{
|
|
13
|
+
articles: [
|
|
14
|
+
{
|
|
15
|
+
title: "1.1",
|
|
16
|
+
path: "1.1",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: "1.2",
|
|
20
|
+
path: "1.2",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Part I",
|
|
26
|
+
articles: [],
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
test("should edit a part", () => {
|
|
30
|
+
const beforeChildren = summary.getByLevel("1").getArticles();
|
|
31
|
+
const newSummary = mergeAtLevel_1.default(summary, "1", { title: "Part O" });
|
|
32
|
+
const edited = newSummary.getByLevel("1");
|
|
33
|
+
expect(edited.getTitle()).toBe("Part O");
|
|
34
|
+
// Same children
|
|
35
|
+
expect(immutable_1.default.is(beforeChildren, edited.getArticles())).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
test("should edit a part", () => {
|
|
38
|
+
const beforePath = summary.getByLevel("1.2").getPath();
|
|
39
|
+
const newSummary = mergeAtLevel_1.default(summary, "1.2", { title: "Renamed article" });
|
|
40
|
+
const edited = newSummary.getByLevel("1.2");
|
|
41
|
+
expect(edited.getTitle()).toBe("Renamed article");
|
|
42
|
+
// Same children
|
|
43
|
+
expect(immutable_1.default.is(beforePath, edited.getPath())).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
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 summary_1 = __importDefault(require("../../../models/summary"));
|
|
8
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
9
|
+
const moveArticle_1 = __importDefault(require("../moveArticle"));
|
|
10
|
+
describe("moveArticle", () => {
|
|
11
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
12
|
+
{
|
|
13
|
+
articles: [
|
|
14
|
+
{
|
|
15
|
+
title: "1.1",
|
|
16
|
+
path: "1.1",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: "1.2",
|
|
20
|
+
path: "1.2",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Part I",
|
|
26
|
+
articles: [
|
|
27
|
+
{
|
|
28
|
+
title: "2.1",
|
|
29
|
+
path: "2.1",
|
|
30
|
+
articles: [
|
|
31
|
+
{
|
|
32
|
+
title: "2.1.1",
|
|
33
|
+
path: "2.1.1",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "2.1.2",
|
|
37
|
+
path: "2.1.2",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: "2.2",
|
|
43
|
+
path: "2.2",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
test("should move an article to the same place", () => {
|
|
49
|
+
const newSummary = moveArticle_1.default(summary, "2.1", "2.1");
|
|
50
|
+
expect(immutable_1.default.is(summary, newSummary)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
test("should move an article to an previous level", () => {
|
|
53
|
+
const newSummary = moveArticle_1.default(summary, "2.2", "2.1");
|
|
54
|
+
const moved = newSummary.getByLevel("2.1");
|
|
55
|
+
const other = newSummary.getByLevel("2.2");
|
|
56
|
+
expect(moved.getTitle()).toBe("2.2");
|
|
57
|
+
expect(other.getTitle()).toBe("2.1");
|
|
58
|
+
});
|
|
59
|
+
test("should move an article to a next level", () => {
|
|
60
|
+
const newSummary = moveArticle_1.default(summary, "2.1", "2.2");
|
|
61
|
+
const moved = newSummary.getByLevel("2.1");
|
|
62
|
+
const other = newSummary.getByLevel("2.2");
|
|
63
|
+
expect(moved.getTitle()).toBe("2.2");
|
|
64
|
+
expect(other.getTitle()).toBe("2.1");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 summary_1 = __importDefault(require("../../../models/summary"));
|
|
8
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
9
|
+
const moveArticleAfter_1 = __importDefault(require("../moveArticleAfter"));
|
|
10
|
+
describe("moveArticleAfter", () => {
|
|
11
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
12
|
+
{
|
|
13
|
+
articles: [
|
|
14
|
+
{
|
|
15
|
+
title: "1.1",
|
|
16
|
+
path: "1.1",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: "1.2",
|
|
20
|
+
path: "1.2",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Part I",
|
|
26
|
+
articles: [
|
|
27
|
+
{
|
|
28
|
+
title: "2.1",
|
|
29
|
+
path: "2.1",
|
|
30
|
+
articles: [
|
|
31
|
+
{
|
|
32
|
+
title: "2.1.1",
|
|
33
|
+
path: "2.1.1",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "2.1.2",
|
|
37
|
+
path: "2.1.2",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: "2.2",
|
|
43
|
+
path: "2.2",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
test("moving right after itself should be invariant", () => {
|
|
49
|
+
const newSummary = moveArticleAfter_1.default(summary, "2.1", "2.1");
|
|
50
|
+
expect(immutable_1.default.is(summary, newSummary)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
test("moving after previous one should be invariant too", () => {
|
|
53
|
+
const newSummary = moveArticleAfter_1.default(summary, "2.1", "2.0");
|
|
54
|
+
expect(immutable_1.default.is(summary, newSummary)).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
test("should move an article after a previous level", () => {
|
|
57
|
+
const newSummary = moveArticleAfter_1.default(summary, "2.2", "2.0");
|
|
58
|
+
const moved = newSummary.getByLevel("2.1");
|
|
59
|
+
expect(moved.getTitle()).toBe("2.2");
|
|
60
|
+
expect(newSummary.getByLevel("2.2").getTitle()).toBe("2.1");
|
|
61
|
+
});
|
|
62
|
+
test("should move an article after a previous and less deep level", () => {
|
|
63
|
+
const newSummary = moveArticleAfter_1.default(summary, "2.1.1", "2.0");
|
|
64
|
+
const moved = newSummary.getByLevel("2.1");
|
|
65
|
+
expect(moved.getTitle()).toBe("2.1.1");
|
|
66
|
+
expect(newSummary.getByLevel("2.2.1").getTitle()).toBe("2.1.2");
|
|
67
|
+
expect(newSummary.getByLevel("2.2").getTitle()).toBe("2.1");
|
|
68
|
+
});
|
|
69
|
+
test("should move an article after a next level", () => {
|
|
70
|
+
const newSummary = moveArticleAfter_1.default(summary, "2.1", "2.2");
|
|
71
|
+
const moved = newSummary.getByLevel("2.2");
|
|
72
|
+
expect(moved.getTitle()).toBe("2.1");
|
|
73
|
+
expect(newSummary.getByLevel("2.1").getTitle()).toBe("2.2");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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("../../../models/summary"));
|
|
7
|
+
const file_1 = __importDefault(require("../../../models/file"));
|
|
8
|
+
const removeArticle_1 = __importDefault(require("../removeArticle"));
|
|
9
|
+
describe("removeArticle", () => {
|
|
10
|
+
const summary = summary_1.default.createFromParts(new file_1.default(), [
|
|
11
|
+
{
|
|
12
|
+
articles: [
|
|
13
|
+
{
|
|
14
|
+
title: "1.1",
|
|
15
|
+
path: "1.1",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: "1.2",
|
|
19
|
+
path: "1.2",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: "Part I",
|
|
25
|
+
articles: [
|
|
26
|
+
{
|
|
27
|
+
title: "2.1",
|
|
28
|
+
path: "2.1",
|
|
29
|
+
articles: [
|
|
30
|
+
{
|
|
31
|
+
title: "2.1.1",
|
|
32
|
+
path: "2.1.1",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: "2.1.2",
|
|
36
|
+
path: "2.1.2",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "2.2",
|
|
42
|
+
path: "2.2",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
test("should remove an article at a given level", () => {
|
|
48
|
+
const newSummary = removeArticle_1.default(summary, "2.1.1");
|
|
49
|
+
const removed = newSummary.getByLevel("2.1.1");
|
|
50
|
+
const nextOne = newSummary.getByLevel("2.1.2");
|
|
51
|
+
expect(removed.getTitle()).toBe("2.1.2");
|
|
52
|
+
expect(nextOne).toBe(null);
|
|
53
|
+
});
|
|
54
|
+
});
|