#!/usr/bin/python3
# -*- coding: utf-8 -*-
from exporter import DocExporter
class HtmlExporter(DocExporter):
"""Exporte une documentation sous forme HTML."""
def open(self, name, fullname):
"""Initialise les propriétés utiles."""
self._filename = fullname + '.html'
self._fd = open(self._filename, 'w')
self._fd.write("""\
Documentation
""")
def close(self):
"""Termine l'édition de la documentation."""
self._fd.write("""
""")
self._fd.close()
def _normalize_desc(self, desc):
"""S'assure d'un bon rendu HTML d'un commentaire prévu pour."""
return desc.replace(" ", " ").replace("<", "<").replace(">", ">").replace("\n", "
")
def show_list_sub_modules(self, gparent, parent, others, builder):
"""Affiche des renvois vers les sous-parties présentes."""
if len(others) > 0 or gparent != None:
self._fd.write('Sub modules
')
self._fd.write('')
if gparent != None:
self._fd.write('- ..
' % gparent)
for o in others:
fullname = builder(parent, o._name)
self._fd.write('- %s
' % (fullname, fullname))
self._fd.write('
')
def show_list_sub_classes(self, parent, classes, builder):
"""Affiche des renvois vers les sous-parties présentes."""
if len(classes) > 0:
self._fd.write('Classes
')
self._fd.write('')
for cls in classes:
self._fd.write('- %s
'
% (parent, cls, builder(parent, cls)))
self._fd.write('
')
def describe_module(self, desc):
"""Affiche la description du module courant."""
self._fd.write('Description
')
self._fd.write('%s
' % self._normalize_desc(desc))
def start_main_section(self, title):
"""Affiche un en-tête pour la zone des classes."""
self._fd.write('%s
' % title)
def show_class_info(self, name, desc):
"""Affiche les informations générales d'une classe."""
self._fd.write('%s
' % (name, name))
self._fd.write('%s
' % self._normalize_desc(desc))
def show_info_section(self, title):
"""Affiche une section d'informations particulières."""
self._fd.write('%s
' % title)
def print_hierarchy_level(self, fullname, name, page, level):
"""Affiche un élément hiérarchique."""
if level > 0:
self._fd.write('')
for i in range(level - 1):
self._fd.write(' ' * 5)
self._fd.write(' ╰── ')
self._fd.write('')
if page != None:
self._fd.write('' % (page, name))
self._fd.write(fullname)
if page != None:
self._fd.write('')
self._fd.write('
')
def show_constant_info(self, name):
"""Affiche un élément de type 'constant'."""
self._fd.write('%s
' % name)
def show_data_info(self, name, value):
"""Affiche un élément de type 'donnée'."""
self._fd.write('%s = %s
' % (name, self._normalize_desc(value)))
def show_attribute_info(self, name, desc):
"""Affiche un élément de type 'attribut'."""
self._fd.write('%s
%s
' % (name, self._normalize_desc(desc)))
def show_callable_info(self, ret, name, args, desc):
"""Affiche un élément de type 'routine'."""
if args == None:
args = '()'
self._fd.write('%s(%s)
%s
' % (name, args, self._normalize_desc(desc)))