Skip to content

Commit

Permalink
PR (#218)
Browse files Browse the repository at this point in the history
- Remove substeps from TOC template helper
- Update all dependencies
- Use snapshots instead of manually written test files
  • Loading branch information
leonardoventurini authored Feb 17, 2020
1 parent 846363f commit a996c95
Show file tree
Hide file tree
Showing 12 changed files with 2,496 additions and 2,222 deletions.
56 changes: 27 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,43 @@
"precommit": "lint-staged"
},
"dependencies": {
"@types/fs-extra": "7.0.0",
"@types/handlebars": "4.1.0",
"@types/i18next": "12.1.0",
"@types/inquirer": "6.0.3",
"@types/minimist": "1.2.0",
"@types/node": "12.0.4",
"@types/semver": "6.0.0",
"@types/tmp": "0.1.0",
"commander": "2.20.0",
"fs-extra": "8.0.1",
"handlebars": "4.1.2",
"i18next": "16.0.0",
"inquirer": "6.3.1",
"commander": "4.1.1",
"fs-extra": "8.1.0",
"handlebars": "4.7.2",
"i18next": "19.1.0",
"inquirer": "7.0.4",
"minimist": "1.2.0",
"node-localstorage": "1.3.1",
"open": "6.3.0",
"parse-diff": "0.5.1",
"readline-sync": "1.4.9",
"semver": "6.1.1",
"node-localstorage": "2.1.5",
"open": "7.0.2",
"parse-diff": "0.6.0",
"readline-sync": "1.4.10",
"semver": "7.1.2",
"tmp": "0.1.0"
},
"devDependencies": {
"@types/jest": "24.0.13",
"@types/jest": "25.1.2",
"@types/fs-extra": "8.0.1",
"@types/inquirer": "6.5.0",
"@types/minimist": "1.2.0",
"@types/node": "13.7.0",
"@types/semver": "7.1.0",
"@types/tmp": "0.1.0",
"babel-register": "6.26.0",
"copyfiles": "2.1.0",
"copyfiles": "2.2.0",
"escape-string-regexp": "2.0.0",
"husky": "2.3.0",
"jest": "24.8.0",
"lint-staged": "8.1.7",
"prettier": "1.17.1",
"rimraf": "2.6.3",
"ts-jest": "24.0.2",
"tslint": "5.17.0",
"husky": "4.2.1",
"jest": "25.1.0",
"lint-staged": "10.0.7",
"prettier": "1.19.1",
"rimraf": "3.0.1",
"ts-jest": "25.2.0",
"tslint": "6.0.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.5.1"
"typescript": "3.7.5"
},
"engines": {
"node": ">=0.10",
"git": ">=1.7.4.2 || ^2.17.0"
"git": ">=1.7.4.2 || ^2.20.1"
},
"jest": {
"testEnvironment": "node",
Expand Down
30 changes: 3 additions & 27 deletions src/renderer/helpers/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,20 @@ import { localStorage as LocalStorage } from '../../local-storage';
import { Renderer } from '../index';

/**
* Must insert second-level headers for sub-steps manually for now, with the same text present on the commit or the
* Table of Contents item, so the "#" anchors match exactly. Tried to mimic GitHub "#" anchor generation as best
* as possible but there might be some divergences there at some point, specially if the titles get too long.
*
* TODO: Find work-around for anchor consistency.
* TODO: Internationalization support.
* TODO: Other flavors of TOC/Anchor generation besides GitHub.
*/

interface IStep {
title: string;
url: string;
children?: IStep[];
}

const generateAnchor = (title: string) =>
title
.toLowerCase()
.replace(/[^a-z0-9 -]/g, '')
.replace(/ /g, '-');

const generateURL = (title: string, superstep: number) => `.tortilla/manuals/views/step${superstep}.md#${generateAnchor(title)}`;

const extractChildren = (slice: string[], superstep: number) => {
return slice
.filter(title => new RegExp(`^Step ${superstep}\.[0-9]+:`).test(title))
.map((title) => ({
title,
url: generateURL(title, superstep)
}))
.reverse();
};
const generateURL = (superstep: number) => `.tortilla/manuals/views/step${superstep}.md`;

const parseLog = (logs: string[]) => {
const results: IStep[] = [];

logs.forEach((title, index) => {
logs.forEach(title => {

const match = title.match(/^Step (\d+):/);

Expand All @@ -47,8 +24,7 @@ const parseLog = (logs: string[]) => {

results.push({
title,
url: generateURL(title, superstep),
children: extractChildren(logs.slice(index + 1), superstep)
url: generateURL(superstep)
});
}
});
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/templates/toc.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{{#each steps}}
- [{{ title }}]({{ url }})
{{#each children}}
- [{{ title }}]({{ url }})
{{/each}}
{{/each}}
17 changes: 11 additions & 6 deletions src/translator/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import i18n from 'i18next';
import * as Path from 'path';
import { Paths } from '../paths';
import { Utils } from '../utils';
import { Translation } from './translation';

import i18default from 'i18next';

// tslint:disable-next-line:no-var-requires
const i18n: typeof i18default = require('i18next');

const superTranslate = i18n.t.bind(i18n);

i18n.init({
lng: 'en',
initImmediate: true,
initImmediate: false,
resources: {
en: { translation: getTranslationResource('en') },
he: { translation: getTranslationResource('he') },
},
he: { translation: getTranslationResource('he') }
}
});


// Gets a locale and returns the full resource object
function getTranslationResource(locale) {
let paths: any = Paths;
Expand All @@ -27,7 +32,7 @@ function getTranslationResource(locale) {
// Static locales
Path.resolve(paths.tortilla.translator.locales, `${locale}.json`),
// User defined locales
Path.resolve(paths.locales, `${locale}.json`),
Path.resolve(paths.locales, `${locale}.json`)
];

// Unite all resources and return a single one
Expand Down Expand Up @@ -71,5 +76,5 @@ function scopeLanguage(language, fn) {
// Shallow cloning i18n so it won't be changed
export const Translator = Utils.extend(i18n, {
translate,
scopeLanguage,
scopeLanguage
});
149 changes: 138 additions & 11 deletions tests/__snapshots__/manual.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,146 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Manual render target set to Medium should render all manual files through out history 1`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
<b>║</b> <a href=\\".tortilla/manuals/views/step1.md\\">BEGIN TUTORIAL</a>
[}]: #"
`;
exports[`Manual render target set to Medium should render root manual if specified 1`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
<b>║</b> <a href=\\".tortilla/manuals/views/step1.md\\">BEGIN TUTORIAL</a>
[}]: #"
`;
exports[`Manual should not create a symlink to root manual if already exists 1`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
| [Begin Tutorial >](.tortilla/manuals/views/step1.md) |
|----------------------:|
[}]: #"
`;
exports[`Manual should not create a symlink to root manual if already exists 2`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
| [Begin Tutorial >](.tortilla/manuals/views/step1.md) |
|----------------------:|
[}]: #"
`;
exports[`Manual should render all manual files through out history 1`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
| [Begin Tutorial >](.tortilla/manuals/views/step1.md) |
|----------------------:|
[}]: #"
`;
exports[`Manual should render root manual if specified and create a symlink to it 1`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
| [Begin Tutorial >](.tortilla/manuals/views/step1.md) |
|----------------------:|
[}]: #"
`;
exports[`Manual should render root manual if specified and create a symlink to it 2`] = `
"# Test tortilla project
[//]: # (head-end)
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
[//]: # (foot-start)
[{]: <helper> (navStep)
| [Begin Tutorial >](.tortilla/manuals/views/step1.md) |
|----------------------:|
[}]: #"
`;
exports[`Manual should render table of contents in a step as well: toc-render-step 1`] = `
"# Step 3: dummy
[//]: # (head-end)
Step 3 manual
- [Step 1: dummy](.tortilla/manuals/views/step1.md#step-1-dummy)
- [Step 2: dummy](.tortilla/manuals/views/step2.md#step-2-dummy)
- [Step 3: dummy](.tortilla/manuals/views/step3.md#step-3-dummy)
- [Step 1: dummy](.tortilla/manuals/views/step1.md)
- [Step 2: dummy](.tortilla/manuals/views/step2.md)
- [Step 3: dummy](.tortilla/manuals/views/step3.md)
Expand All @@ -30,14 +161,10 @@ exports[`Manual should render table of contents: toc-render 1`] = `
A newly created Tortilla project. For more information, see https://github.com/Urigo/tortilla.
- [Step 1: dummy](.tortilla/manuals/views/step1.md#step-1-dummy)
- [Step 2: dummy](.tortilla/manuals/views/step2.md#step-2-dummy)
- [Step 3: dummy](.tortilla/manuals/views/step3.md#step-3-dummy)
- [Step 4: Add Comments](.tortilla/manuals/views/step4.md#step-4-add-comments)
- [Step 4.1: Add First Comment](.tortilla/manuals/views/step4.md#step-41-add-first-comment)
- [Step 4.2: Add Second Comment](.tortilla/manuals/views/step4.md#step-42-add-second-comment)
- [Step 4.3: Add Third Comment](.tortilla/manuals/views/step4.md#step-43-add-third-comment)
- [Step 4.4: Add Fourth Comment](.tortilla/manuals/views/step4.md#step-44-add-fourth-comment)
- [Step 1: dummy](.tortilla/manuals/views/step1.md)
- [Step 2: dummy](.tortilla/manuals/views/step2.md)
- [Step 3: dummy](.tortilla/manuals/views/step3.md)
- [Step 4: Add Comments](.tortilla/manuals/views/step4.md)
Expand Down
Loading

0 comments on commit a996c95

Please sign in to comment.