Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed tests/builddocs in favor of integrating it into the documenta…

…tion builder for the site in general

git-svn-id: http://code.djangoproject.com/svn/django/trunk@371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c73f4cd48697b7680fa95acb47f74720a1dce68f 1 parent 440a2a9
Jacob Kaplan-Moss authored August 01, 2005

Showing 1 changed file with 0 additions and 82 deletions. Show diff stats Hide diff stats

  1. 82  tests/builddocs.py
82  tests/builddocs.py
... ...
@@ -1,82 +0,0 @@
1  
-#!/usr/bin/env python
2  
-"""
3  
-This module builds HTML documentation for models by introspecting the model
4  
-unit tests.
5  
-"""
6  
-
7  
-from django.core import meta, template
8  
-import runtests
9  
-import inspect, os, re, sys
10  
-
11  
-MODEL_DOC_TEMPLATE = """
12  
-<div class="document" id="model-{{ model_name }}">
13  
-
14  
-<h1 class="title">{{ title }}</h1>
15  
-{{ blurb }}
16  
-
17  
-<h2>Model source code</h2>
18  
-<pre class="literal-block">{{ model_source }}</pre>
19  
-
20  
-<h2>API reference</h2>
21  
-
22  
-{% for model in models %}
23  
-<h3>{{ model.name }} objects have the following methods:</h3>
24  
-<ul>
25  
-{% for method in model.methods %}<li><tt class="docutils literal"><span class="pre">{{ method }}()</span></tt></li>
26  
-{% endfor %}</ul>
27  
-{% endfor %}
28  
-
29  
-<h2>Sample API usage</h2>
30  
-<pre class="literal-block">{{ api_usage }}</pre>
31  
-</div>
32  
-"""
33  
-
34  
-def make_docs_from_model_tests(output_dir):
35  
-    from django.conf import settings
36  
-
37  
-    # Manually set INSTALLED_APPS to point to the test app.
38  
-    settings.INSTALLED_APPS = (runtests.APP_NAME,)
39  
-
40  
-    for model_name in runtests.get_test_models():
41  
-        mod = meta.get_app(model_name)
42  
-
43  
-        # Clean up the title and blurb.
44  
-        title, blurb = mod.__doc__.strip().split('\n', 1)
45  
-        blurb = '<p>%s</p>' % blurb.strip().replace('\n\n', '</p><p>')
46  
-        blurb = re.sub(r'``(.*?)``', '<tt class="docutils literal"><span class="pre">\\1</span></tt>', blurb)
47  
-        api_usage = mod.API_TESTS
48  
-
49  
-        # Get the source code of the model, without the docstring or the
50  
-        # API_TESTS variable.
51  
-        model_source = inspect.getsource(mod)
52  
-        model_source = model_source.replace(mod.__doc__, '')
53  
-        model_source = model_source.replace(mod.API_TESTS, '')
54  
-        model_source = model_source.replace('""""""\n', '\n')
55  
-        model_source = model_source.replace('API_TESTS = ', '')
56  
-        model_source = model_source.strip()
57  
-
58  
-        models = []
59  
-        for m in mod._MODELS:
60  
-            models.append({
61  
-                'name': m._meta.object_name,
62  
-                'methods': [method for method in dir(m) if not method.startswith('_')],
63  
-            })
64  
-
65  
-        # Run this through the template system.
66  
-        t = template.Template(MODEL_DOC_TEMPLATE)
67  
-        c = template.Context(locals())
68  
-        html = t.render(c)
69  
-
70  
-        file_name = os.path.join(output_dir, 'model_' + model_name + '.html')
71  
-        try:
72  
-            fp = open(file_name, 'w')
73  
-        except IOError:
74  
-            sys.stderr.write("Couldn't write to %s.\n" % file_name)
75  
-            continue
76  
-        else:
77  
-            fp.write(html)
78  
-            fp.close()
79  
-
80  
-if __name__ == "__main__":
81  
-    import sys
82  
-    make_docs_from_model_tests(sys.argv[1])

0 notes on commit c73f4cd

Please sign in to comment.
Something went wrong with that request. Please try again.