Browse Source

Class diagrams

pull/31/head
Jure Šorn 5 years ago
parent
commit
9ef6c68882
2 changed files with 69 additions and 19 deletions
  1. 36
      README.md
  2. 52
      parse.js

36
README.md

@ -1534,28 +1534,28 @@ class MyClass(metaclass=MyMetaClass):
#### Type diagram ('abc' is a str, str is a type, ...):
```text
┏━━━━━━━━━┯━━━━━━━━━━━━━┓
┃ classes │ metaclasses ┃
┠─────────┼─────────────┨
┃ MyClass → MyMetaClass ┃
┃ │ ↓ ┃
┃ object ───→ type ←╮ ┃
┃ │ ↑ ╰───╯ ┃
┃ str ───────╯ ┃
┗━━━━━━━━━┷━━━━━━━━━━━━━┛
+---------+-------------+
| classes | metaclasses |
+---------|-------------|
| MyClass > MyMetaClass |
| | v |
| object ---> type <+ |
| | ^ +---+ |
| str -------+ |
+---------+-------------+
```
#### Inheritance diagram (str inherits from object, ...):
```text
┏━━━━━━━━━┯━━━━━━━━━━━━━┓
┃ classes │ metaclasses ┃
┠─────────┼─────────────┨
┃ MyClass │ MyMetaClass ┃
┃ ↓ │ ↓ ┃
┃ object ←─── type ┃
┃ ↑ │ ┃
┃ str │ ┃
┗━━━━━━━━━┷━━━━━━━━━━━━━┛
+---------+-------------+
| classes | metaclasses |
+---------|-------------|
| MyClass | MyMetaClass |
| v | v |
| object <--- type |
| ^ | |
| str | |
+---------+-------------+
```

52
parse.js

@ -30,6 +30,50 @@ const TOC =
'}\n' +
'</code></pre>\n';
const DIAGRAM_1_A =
'+---------+-------------+\n' +
'| classes | metaclasses |\n' +
'+---------|-------------|\n' +
'| MyClass > MyMetaClass |\n' +
'| | v |\n' +
'| object ---> type <+ |\n' +
'| | ^ +---+ |\n' +
'| str -------+ |\n' +
'+---------+-------------+\n';
const DIAGRAM_1_B =
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
'┃ classes │ metaclasses ┃\n' +
'┠─────────┼─────────────┨\n' +
'┃ MyClass → MyMetaClass ┃\n' +
'┃ │ ↓ ┃\n' +
'┃ object ───→ type ←╮ ┃\n' +
'┃ │ ↑ ╰───╯ ┃\n' +
'┃ str ───────╯ ┃\n' +
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
const DIAGRAM_2_A =
'+---------+-------------+\n' +
'| classes | metaclasses |\n' +
'+---------|-------------|\n' +
'| MyClass | MyMetaClass |\n' +
'| v | v |\n' +
'| object <--- type |\n' +
'| ^ | |\n' +
'| str | |\n' +
'+---------+-------------+\n';
const DIAGRAM_2_B =
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
'┃ classes │ metaclasses ┃\n' +
'┠─────────┼─────────────┨\n' +
'┃ MyClass │ MyMetaClass ┃\n' +
'┃ ↓ │ ↓ ┃\n' +
'┃ object ←─── type ┃\n' +
'┃ ↑ │ ┃\n' +
'┃ str │ ┃\n' +
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
function main() {
const html = getMd();
@ -50,11 +94,17 @@ function initDom(html) {
}
function getMd() {
const readme = readFile('README.md');
var readme = readFile('README.md');
readme = switchClassDiagrams(readme);
const converter = new showdown.Converter();
return converter.makeHtml(readme);
}
function switchClassDiagrams(readme) {
readme = readme.replace(DIAGRAM_1_A, DIAGRAM_1_B)
return readme.replace(DIAGRAM_2_A, DIAGRAM_2_B)
}
function modifyPage() {
removeOrigToc();
addToc();

Loading…
Cancel
Save