summaryrefslogtreecommitdiff
path: root/giscanner/docwriter.py
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2015-06-06 17:10:52 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2018-05-25 20:00:43 -0700
commite85a46ea5414e7f684277ec611c3a9effca51e42 (patch)
treed9c7e393f26641b8d0f1f45a9804a5e76bfdbe86 /giscanner/docwriter.py
parentbd67726644d6466031010e766c1fb6cc7969e5b7 (diff)
downloadgobject-introspection-e85a46ea5414e7f684277ec611c3a9effca51e42.tar.gz
docwriter: Option to select output format
For generating other output formats such as DevDocs-ready HTML, we add an output format option (-f). The default output format is "mallard" which leaves the existing behaviour unchanged. We can fold the existing --write-sections-file option into the new output format option, as a new "sections" format. Closes #134.
Diffstat (limited to 'giscanner/docwriter.py')
-rw-r--r--giscanner/docwriter.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index cfc41729..d9c2ed57 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -462,6 +462,8 @@ class DocFormatter(object):
class DocFormatterC(DocFormatter):
language = "C"
mime_type = "text/x-csrc"
+ output_format = "mallard"
+ output_extension = ".page"
fundamentals = {
"TRUE": "TRUE",
@@ -507,6 +509,8 @@ class DocFormatterIntrospectableBase(DocFormatter):
class DocFormatterPython(DocFormatterIntrospectableBase):
language = "Python"
mime_type = "text/python"
+ output_format = "mallard"
+ output_extension = ".page"
fundamentals = {
"TRUE": "True",
@@ -514,6 +518,12 @@ class DocFormatterPython(DocFormatterIntrospectableBase):
"NULL": "None",
}
+ def get_output_format(self):
+ return 'mallard'
+
+ def get_output_extension(self):
+ return 'page'
+
def should_render_node(self, node):
if getattr(node, "is_constructor", False):
return False
@@ -585,6 +595,8 @@ class DocFormatterPython(DocFormatterIntrospectableBase):
class DocFormatterGjs(DocFormatterIntrospectableBase):
language = "Gjs"
mime_type = "text/x-gjs"
+ output_format = "mallard"
+ output_extension = ".page"
fundamentals = {
"TRUE": "true",
@@ -878,20 +890,23 @@ class DocFormatterGjs(DocFormatterIntrospectableBase):
for p in construct_params)
LANGUAGES = {
- "c": DocFormatterC,
- "python": DocFormatterPython,
- "gjs": DocFormatterGjs,
+ "mallard": {
+ "c": DocFormatterC,
+ "python": DocFormatterPython,
+ "gjs": DocFormatterGjs,
+ },
}
class DocWriter(object):
- def __init__(self, transformer, language):
+ def __init__(self, transformer, language, output_format):
self._transformer = transformer
try:
- formatter_class = LANGUAGES[language.lower()]
+ formatter_class = LANGUAGES[output_format][language.lower()]
except KeyError:
- raise SystemExit("Unsupported language: %s" % (language, ))
+ raise SystemExit("Unsupported language %s for output format %s" %
+ (language, output_format))
self._formatter = formatter_class(self._transformer)
self._language = self._formatter.language
@@ -905,7 +920,8 @@ class DocWriter(object):
else:
srcdir = os.path.dirname(__file__)
- template_dir = os.path.join(srcdir, 'doctemplates')
+ template_dir = os.path.join(srcdir, 'doctemplates',
+ self._formatter.output_format)
return TemplateLookup(directories=[template_dir],
module_directory=tempfile.mkdtemp(),
@@ -955,7 +971,8 @@ class DocWriter(object):
formatter=self._formatter,
ast=ast)
+ output_base_name = page_id + self._formatter.output_extension
output_file_name = os.path.join(os.path.abspath(output),
- page_id + '.page')
+ output_base_name)
with open(output_file_name, 'wb') as fp:
fp.write(result)