-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(docs): use 'dot' to generate the message documentation
- Loading branch information
1 parent
3b85a30
commit ceea9fe
Showing
5 changed files
with
75 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
let tm = require('../index'), | ||
g = tm.grammar, | ||
fs = require('fs'), | ||
mkdirp = require('mkdirp'), | ||
path = require('path'), | ||
dot = require('dot'), | ||
home = './dist/doc'; | ||
|
||
mkdirp.sync(home); | ||
|
||
dot.templateSettings.strip = false; | ||
var render = dot.process({ path: path.dirname(module.filename)}); | ||
|
||
function save(name, page) { | ||
fs.writeFileSync(home + '/' + name + '.html', page); | ||
} | ||
|
||
// An array of message info sorted by message name | ||
let messages = g.root | ||
.terms.map(rule => rule.name) | ||
.sort(); | ||
messages = messages.map(name => { | ||
var example, ast; | ||
g.rules[name].example(g, (e,s) => { example = s; }); | ||
tm.parse(example, (e,o) => { ast = JSON.stringify(o, null, 4); }); | ||
return { | ||
name: name, | ||
example: example, | ||
ast: ast | ||
}; | ||
}); | ||
|
||
module.exports.run = function run() { | ||
save('index', render.messages({ messages: messages })); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Messages</title> | ||
</head> | ||
<body> | ||
|
||
|
||
{{~it.messages :m:index}} | ||
<div><a href="#{{=m.name}}-msg">{{=m.name}}</a></div> | ||
{{~}} | ||
|
||
{{~it.messages :m:index}} | ||
<h3 id="{{=m.name}}-msg"> {{=m.name}} Message</h3> | ||
<p>...</p> | ||
|
||
<h4>Definition</h4> | ||
... | ||
|
||
<h4>Example</h4> | ||
<code>{{=m.example}}</code> | ||
|
||
<h4>Syntax Tree</h4> | ||
<code><pre>{{=m.ast}}</pre></code> | ||
|
||
{{~}} | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters