Mercurial > jouvence
annotate scripts/fontaine @ 9:a5488b474c6b
Add HTML renderer.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Jan 2017 02:56:08 -0800 |
parents | 9053902c750e |
children | 2cea36073188 |
rev | line source |
---|---|
4
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import os.path |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import sys |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 import argparse |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 def main(): |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 parser = argparse.ArgumentParser( |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 description='Fontaine command line utility') |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 parser.add_argument('script') |
9 | 14 parser.add_argument('out_file', nargs='?') |
4
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 args = parser.parse_args() |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 from fontaine.parser import FontaineParser |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 p = FontaineParser() |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 doc = p.parse(args.script) |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
9 | 21 if not args.out_file: |
22 from fontaine.console import ConsoleDocumentRenderer | |
23 rdr = ConsoleDocumentRenderer() | |
24 rdr.render_doc(doc, sys.stdout) | |
25 else: | |
26 from fontaine.html import HtmlDocumentRenderer | |
27 rdr = HtmlDocumentRenderer() | |
28 with open(args.out_file, 'w') as fp: | |
29 rdr.render_doc(doc, fp) | |
4
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 if __name__ == '__main__': |
9053902c750e
Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 main() |