| 1 |
|
|---|
| 2 |
import os |
|---|
| 3 |
import sys |
|---|
| 4 |
from docutils import nodes, utils |
|---|
| 5 |
from docutils.core import publish_file |
|---|
| 6 |
from docutils.parsers.rst import roles |
|---|
| 7 |
|
|---|
| 8 |
def mochi_name(text): |
|---|
| 9 |
name = text.split('(', 1)[0].split()[0] |
|---|
| 10 |
base = '' |
|---|
| 11 |
if name.startswith('MochiKit.'): |
|---|
| 12 |
|
|---|
| 13 |
parts = name.split('.') |
|---|
| 14 |
base = parts[1] + '.html' |
|---|
| 15 |
if parts[-1] in ("call", "apply"): |
|---|
| 16 |
parts.pop() |
|---|
| 17 |
name = '.'.join(parts[2:]) |
|---|
| 18 |
return base, name |
|---|
| 19 |
|
|---|
| 20 |
def role_mochiref(role, rawtext, text, lineno, inliner, options=None, content=[]): |
|---|
| 21 |
if options is None: |
|---|
| 22 |
options = {} |
|---|
| 23 |
base, name = mochi_name(text) |
|---|
| 24 |
ref = base |
|---|
| 25 |
if name: |
|---|
| 26 |
ref += '#fn-' + name.lower() |
|---|
| 27 |
roles.set_classes(options) |
|---|
| 28 |
options.setdefault('classes', []).append('mochiref') |
|---|
| 29 |
node = nodes.reference( |
|---|
| 30 |
text, utils.unescape(text), refuri=ref, **options) |
|---|
| 31 |
return [node], [] |
|---|
| 32 |
|
|---|
| 33 |
roles.register_canonical_role('mochiref', role_mochiref) |
|---|
| 34 |
|
|---|
| 35 |
def role_mochidef(role, rawtext, text, lineno, inliner, options=None, content=[]): |
|---|
| 36 |
if options is None: |
|---|
| 37 |
options = {} |
|---|
| 38 |
base, name = mochi_name(text) |
|---|
| 39 |
assert base == '' |
|---|
| 40 |
ref = 'fn-' + utils.unescape(name.lower()) |
|---|
| 41 |
anchor = nodes.raw('', '\n<a name="%s"></a>\n' % (ref,), format='html') |
|---|
| 42 |
roles.set_classes(options) |
|---|
| 43 |
options.setdefault('classes', []).append('mochidef') |
|---|
| 44 |
node = nodes.reference( |
|---|
| 45 |
text, utils.unescape(text), refuri='#' + ref, **options) |
|---|
| 46 |
return [anchor, node], [] |
|---|
| 47 |
|
|---|
| 48 |
roles.register_canonical_role('mochidef', role_mochidef) |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
def main(): |
|---|
| 53 |
basepath = os.path.join('doc/rst', '') |
|---|
| 54 |
destpath = os.path.join('doc/html', '') |
|---|
| 55 |
for root, dirs, files in os.walk(basepath): |
|---|
| 56 |
if '.svn' in dirs: |
|---|
| 57 |
dirs.remove('.svn') |
|---|
| 58 |
destroot = destpath + root[len(basepath):] |
|---|
| 59 |
if not os.path.exists(destroot): |
|---|
| 60 |
os.makedirs(destroot) |
|---|
| 61 |
for fn in files: |
|---|
| 62 |
basefn, ext = os.path.splitext(fn) |
|---|
| 63 |
if ext == '.rst': |
|---|
| 64 |
srcfn = os.path.join(root, fn) |
|---|
| 65 |
dest = os.path.join(destroot, basefn + '.html') |
|---|
| 66 |
if basefn != "index": |
|---|
| 67 |
try: |
|---|
| 68 |
if os.path.getmtime(dest) >= os.path.getmtime(srcfn): |
|---|
| 69 |
print srcfn, "not changed" |
|---|
| 70 |
continue |
|---|
| 71 |
except OSError: |
|---|
| 72 |
pass |
|---|
| 73 |
print srcfn |
|---|
| 74 |
res = publish_file( |
|---|
| 75 |
source_path=srcfn, |
|---|
| 76 |
destination_path=dest, |
|---|
| 77 |
writer_name='html', |
|---|
| 78 |
settings_overrides=dict( |
|---|
| 79 |
input_encoding='utf8', |
|---|
| 80 |
output_encoding='utf8', |
|---|
| 81 |
embed_stylesheet=False, |
|---|
| 82 |
stylesheet_path='include/css/documentation.css', |
|---|
| 83 |
), |
|---|
| 84 |
) |
|---|
| 85 |
|
|---|
| 86 |
if __name__ == '__main__': |
|---|
| 87 |
main() |
|---|