Add templates and example files for Python, Go, and JavaScript
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-31 00:58:44 +00:00
parent 0bffceff13
commit 9d45ae8eb7

131
doc2man/templates/html.j2 Normal file
View File

@@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; color: #333; }
h1 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px; }
h2 { color: #34495e; margin-top: 30px; }
h3 { color: #7f8c8d; }
code { background-color: #f4f4f4; padding: 2px 6px; border-radius: 4px; font-family: 'Monaco', monospace; font-size: 0.9em; }
pre { background-color: #2c3e50; color: #ecf0f1; padding: 15px; border-radius: 8px; overflow-x: auto; }
pre code { background: none; padding: 0; color: inherit; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
th { background-color: #3498db; color: white; }
tr:nth-child(even) { background-color: #f9f9f9; }
.description { background-color: #f8f9fa; padding: 15px; border-left: 4px solid #3498db; margin: 20px 0; }
.example { margin: 20px 0; }
.raises { background-color: #fff3cd; padding: 10px; border-radius: 4px; margin: 10px 0; }
hr { border: none; border-top: 1px solid #ddd; margin: 30px 0; }
.file-path { color: #7f8c8d; font-size: 0.9em; }
.nav { margin-bottom: 20px; }
.nav a { margin-right: 15px; color: #3498db; text-decoration: none; }
.nav a:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="nav">
<a href="#">Top</a>
{% for item in data %}
{% set funcs = item.data.functions|default([], true) %}
{% if funcs %}
{% for func in funcs %}
<a href="#{{ func.name }}">{{ func.name }}</a>
{% endfor %}
{% endif %}
{% endfor %}
</div>
<h1>{{ title }}</h1>
{% if data %}
{% for item in data %}
{% set file_path = item.file|default('Unknown', true) %}
{% set funcs = item.data.functions|default([], true) %}
{% set classes = item.data.classes|default([], true) %}
{% set desc = item.data.description|default('', true) %}
<p class="file-path">Source: {{ file_path }}</p>
{% if desc %}
<div class="description">{{ desc }}</div>
{% endif %}
{% if funcs %}
<h2>Functions</h2>
{% for func in funcs %}
<h3 id="{{ func.name }}">{{ func.name }}</h3>
{% if func.description %}<p>{{ func.description }}</p>{% endif %}
{% if func.args|default([], true) %}
<h4>Parameters</h4>
<table>
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
{% for param in func.args %}
<tr>
<td><code>{{ param.name }}</code></td>
<td><code>{{ param.type|default('any', true) }}</code></td>
<td>{{ param.description|default('', true) }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if func.returns %}
<h4>Returns</h4>
<p>{% if func.returns.type %}<code>{{ func.returns.type }}</code> {% endif %}{{ func.returns.description|default('', true) }}</p>
{% endif %}
{% if func.raises|default([], true) %}
<h4>Raises</h4>
{% for raise in func.raises %}
<div class="raises"><code>{{ raise.exception }}</code>: {{ raise.description|default('', true) }}</div>
{% endfor %}
{% endif %}
{% if func.examples|default([], true) %}
<h4>Examples</h4>
{% for example in func.examples %}
<div class="example"><pre><code>{{ example }}</code></pre></div>
{% endfor %}
{% endif %}
<hr>
{% endfor %}
{% endif %}
{% if classes %}
<h2>Classes</h2>
{% for cls in classes %}
<h3>{{ cls.name }}</h3>
{% if cls.description %}<p>{{ cls.description }}</p>{% endif %}
{% if cls.methods|default([], true) %}
<h4>Methods</h4>
<ul>
{% for method in cls.methods %}
<li><code>{{ method.name }}</code>: {% if method.description %}{{ method.description|first_line }}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}
<hr>
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
<p>No documentation found.</p>
{% endif %}
<footer><p>Generated by <a href="https://github.com/example/doc2man">Doc2Man</a></p></footer>
</body>
</html>