Commit bb20eca5 authored by Emmanuele Bassi's avatar Emmanuele Bassi 👣
Browse files

Add the "generate" command

Generate an API reference for a given project using a template and the
introspection data for that project.

The basic template is still a work in progress.
parent 78c81ba3
This diff is collapsed.
......@@ -7,7 +7,7 @@ import sys
import traceback
from . import log
from . import gdindex
from . import gdindex, gdgenerate
class GIDocGenApp:
"""
......@@ -35,6 +35,10 @@ class GIDocGenApp:
add_args_func=gdindex.add_args,
run_func=gdindex.run,
help_msg=gdindex.HELP_MSG)
self.add_command('generate',
add_args_func=gdgenerate.add_args,
run_func=gdgenerate.run,
help_msg=gdgenerate.HELP_MSG)
def run(self, args):
"""
......
......@@ -404,6 +404,14 @@ class Interface(Type):
self.fields = []
self.prerequisite = None
@property
def type_struct(self) -> str:
return self.gtype.type_struct
@property
def type_func(self) -> str:
return self.gtype.type_func
def set_methods(self, methods: T.List[Method]) -> None:
self.methods.extend(methods)
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{{ LIBRARY_NAME }}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<meta property="og:site_name" content="{{ SITENAME }}"/>
<meta property="og:title" content="{{ SITENAME }}"/>
<meta property="og:url" content="{{ SITEURL }}"/>
<meta property="og:type" content="website"/>
{% if LOGO_FILE %}
<meta property="og:image:width" content="512"/>
<meta property="og:image:height" content="512"/>
<meta property="og:image:secure_url" content="{{ SITEURL }}/{{ LOGO_FILE }}"/>
<meta property="og:image:alt" content="{{ LIBRARY_NAME }}"/>
{% endif %}
{% block meta_other %}{% endblock %}
<meta name="twitter:title" content="{{ SITENAME }}"/>
<meta name="twitter:url" content="{{ SITEURL }}"/>
<meta name="twitter:card" content="summary"/>
<link rel="canonical" href="{{ SITEURL }}"/>
<link rel="stylesheet" href="style.css" type="text/css" />
{% block style_other %}{% endblock %}
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<div id="body-wrapper" tabindex="-1">
{% block sidebar %}{% endblock %}
{% block navbar %}{% endblock %}
{% block content %}{% endblock %}
{% block footer %}{% endblock %}
</div>
</body>
</html>
[metadata]
name = "Basic"
author_name = "Emmanuele Bassi"
author_email = "ebassi@gnome.org"
copyright_year = "2021"
license = "Apache-2.0 OR GPL-3.0-or-later"
[templates]
class = "class.html"
interface = "interface.html"
content = "content.html"
property = "property.html"
signal = "signal.html"
vfunc = "vfunc.html"
method = "method.html"
type_func = "type_func.html"
class_method = "class_method.html"
namespace = "namespace.html"
error = "enum.html"
flags = "enum.html"
enum = "enum.html"
[css]
style = "style.css"
[extra_files]
files = ["main.js", "pygment.css"]
{% extends "base.html" %}
{% block title %}{{ namespace.name }}.{{ class.name }}{% endblock %}
{% block meta_other %}
<meta name="og:title" content="{{ namespace.name }}.{{ class.name }}"/>
<meta name="og:description" content="Reference for {{ namespace.name }}.{{ class.name }}"/>
{% endblock %}
{% block sidebar %}
<nav class="sidebar">
<div class="namespace">
<h3><a href="index.html">{{ namespace.name }} &mdash; {{ namespace.version }}</a></h3>
</div>
<div class="section">
<h5>Class</h5>
<div class="links">
<a class="current" href="class.{{ class.name }}.html#description">{{ class.name }}</a>
</div>
</div>
<div class="section">
<h5>Instance methods</h5>
<div class="links">
{% for m in class.methods %}
<a class="method" href="method.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Class methods</h5>
<div class="links">
{% for m in class.class_methods %}
<a class="method" href="class_method.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Type functions</h5>
<div class="links">
{% for m in class.type_funcs %}
<a class="method" href="type_func.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Properties</h5>
<div class="links">
{% for p in class.properties %}
<a href="property.{{ class.name }}.{{ p.name }}.html">{{ p.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Signals</h5>
<div class="links">
{% for s in class.signals %}
<a href="signal.{{ class.name }}.{{ s.name }}.html">{{ s.name }}</a>
{% endfor %}
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<section id="main" class="content">
<header>
<h3>Class</h3>
<h1><a href="index.html">{{ namespace.name }}</a>.{{ class.name }}</h1>
</header>
<section>
<summary>
<div class="collapse-toggle">
<h4><a name="description">Description</a></h4>
<pre><code>{% if not class.class_struct or not class.instance_struct %}final {% endif -%}class {{ namespace.name }}.{{ class.name }} : {{ class.parent }} { }</code></pre>
<div>
{{ class.description|safe }}
</div>
</div>
</summary>
{% if class.interfaces %}
<div>
<h4><a name="implements">Implements</a></h4>
<ul>
{% for iface in class.interfaces %}
<li class="interface"><a href="iface.{{ iface.name }}.html">{{ namespace.name }}.{{ iface.name }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if class.methods %}
<div class="methods">
<h4><a name="methods">Instance methods</a></h4>
{% for method in class.methods %}
<div>
<h6><a href="method.{{ class.name}}.{{ method.name }}.html">{{ method.identifier }}</a> ();</h6>
</div>
{% endfor %}
</div>
{% endif %}
{% if class.properties %}
<div class="properties">
<h4><a name="properties">Properties</a></h4>
{% for property in class.properties %}
<div>
<h6><a href="property.{{ class.name }}.{{ property.name }}.html">{{ namespace.name }}.{{ class.name }}:{{ property.name }}</a></h6>
</div>
{% endfor %}
</div>
{% endif %}
{% if class.signals %}
<div class="signals">
<h4><a name="signals">Signals</a></h4>
{% for signal in class.signals %}
<div>
<h6><a href="signal.{{ class.name }}.{{ signal.name }}.html">{{ namespace.name }}.{{ class.name }}::{{ signal.name }}</a></h6>
</div>
{% endfor %}
</div>
{% endif %}
{% if class.class_name %}
<div class="class">
<h4><a name="class">Class structure</a></h4>
<pre><code>struct {{ namespace.name}}.{{ class.class_name }} {
{% for field in class.class_fields %}
{{ field.name }}: {{ field.type_name }};
{% else %}/* no available fields */{% endfor %}
}</code></pre>
{% if class.class_fields %}
<div>
<h6>Class members</h6>
<table>
{% for field in class.class_fields %}
<tr>
<td><code>{{ field.name }}</code></td>
<td>{{ field.description|safe }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endif %}
{% if class.class_methods %}
<div class="methods">
<h4><a name="class-functions">Class methods</a></h4>
{% for method in class.class_methods %}
<div>
<h6><a href="class_method.{{ class.class_name }}.{{ method.name }}.html">{{ method.identifier }}</a> ();</h6>
</div>
{% endfor %}
</div>
{% endif %}
{% if class.functions %}
<div class="methods">
<h4><a name="type-functions">Type functions</a></h4>
{% for func in class.type_funcs %}
<div>
<h6><a href="type_func.{{ class.name }}.{{ func.name }}.html">{{ func.identifier }}</a> ();</h6>
</div>
{% endfor %}
</div>
{% endif %}
</section>
</section>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ namespace.name }}.{{ class.class_name }}.{{ class_method.name }}{% endblock %}
{% block meta_other %}
<meta name="og:title" content="{{ namespace.name }}.{{ class.class_name }}.{{ class_method.name }}"/>
<meta name="og:description" content="Reference for {{ namespace.name }}.{{ class.class_name }}.{{ class_method.name }}"/>
{% endblock %}
{% block sidebar %}
<nav class="sidebar">
<div class="namespace">
<h3><a href="index.html">{{ namespace.name }} &mdash; {{ namespace.version }}</a></h3>
</div>
<div class="section">
<h5>Type</h5>
<div class="links">
<a href="{{ class.link_prefix }}.{{ class.name }}.html">{{ class.name }}</a>
</div>
</div>
<div class="section">
<h5>Instance methods</h5>
<div class="links">
{% for m in class.methods %}
<a class="method" href="method.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Class methods</h5>
<div class="links">
{% for m in class.class_methods %}
<a class="method{% if class_method.name == m.name %} current{% endif %}" href="class_method.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Type functions</h5>
<div class="links">
{% for m in class.type_funcs %}
<a class="method" href="type_func.{{ class.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Properties</h5>
<div class="links">
{% for p in class.properties %}
<a href="property.{{ class.name }}.{{ p.name }}.html">{{ p.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Signals</h5>
<div class="links">
{% for s in class.signals %}
<a href="signal.{{ class.name }}.{{ s.name }}.html">{{ s.name }}</a>
{% endfor %}
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<section id="main" class="content">
<header>
<h3>Class method</h3>
<h1><a href="index.html">{{ namespace.name }}</a>.<a href="{{ class.link_prefix }}.{{ class.name }}.html">{{ class.class_name }}</a>.{{ class_method.name }}</h1>
</header>
<section>
<div class="declaration">
<h4><a name="declaration">Declaration</a></h4>
<div>
<pre><code>{% if class_method.return_value %}{{ class_method.return_value.type_cname }}{% else %}void{% endif %}
{{class_method.identifier }} (
{{ class.class_name }}* class_{% if class_method.arguments|length != 0 %},{% endif %}
{% for arg in class_method.arguments %}{{ arg.type_cname }} {{ arg.name }}{% if not loop.last %},{% endif %}{% endfor %}
)</code></pre>
</div>
{% if class_method.arguments|length != 0 %}
<div class="parameters">
<h4><a name="parameters">Parameters</a></h4>
<table>
{% for arg in class_method.arguments %}
<tr>
<td><code>{{ arg.name }}: {{ arg.type_cname }}</code></td>
<td>{{ arg.description|safe }}</td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
{% if class_method.return_value %}
<div class="returns">
<h4><a name="returns">Return value</a></h4>
{{ class_method.return_value.description|safe }}
</div>
{% endif %}
<div class="description">
<h4><a name="description">Description</a></h4>
{{ class_method.description|safe }}
</div>
</section>
</section>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ namespace.name }} &ndash; {{ namespace.version }}: {{ content_title }}{% endblock %}
{% block meta_other %}
<meta name="og:title" content="{{ namespace.name }}-{{ namespace.version }}: {{ content_title }}"/>
<meta name="og:description" content="Reference for {{ namespace.name }}-{{ namespace.version }}"/>
{% endblock %}
{% block navbar %}
<nav class="sidebar">
<div class="namespace">
<h3><a href="index.html">{{ namespace.name }} &mdash; {{ namespace.version }}</a></h3>
</div>
<div class="section">
<h5>Classes</h5>
<div class="links">
{% for class in symbols.classes %}
<a href="class.{{ class.name }}.html">{{ class.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Interfaces</h5>
<div class="links">
{% for iface in symbols.interfaces %}
<a href="iface.{{ iface.name }}.html">{{ iface.name }}</a>
{% endfor %}
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<section id="main" class="content">
<header>
<h1>{{ content_title }}</h1>
</header>
<section>
{{ content_data|safe }}
</section>
</section>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ namespace.name }}.{{ enum.name }}{% endblock %}
{% block meta_other %}
<meta name="og:title" content="{{ namespace.name }}.{{ enum.name }}"/>
<meta name="og:description" content="Reference for {{ namespace.name }}.{{ enum.name }}"/>
{% endblock %}
{% block sidebar %}
<nav class="sidebar">
<div class="namespace">
<h3><a href="index.html">{{ namespace.name }} &mdash; {{ namespace.version }}</a></h3>
</div>
<div class="section">
<h5>Type</h5>
<div class="links">
<a class="current" href="{{ enum.link_prefix }}.{{ enum.name }}.html">{{ enum.name }}</a>
</div>
</div>
<div class="section">
<h5>Type functions</h5>
<div class="links">
{% for m in enum.type_funcs %}
<a class="method" href="type_func.{{ enum.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<section id="main" class="content">
<header>
<h3>Enumeration</h3>
<h1><a href="index.html">{{ namespace.name }}</a>.{{ enum.name }}</h1>
</header>
<section>
<div class="declaration">
<h4><a name="declaration">Declaration</a></h4>
<div class="collapse-toggle">
{% if enum.error %}
<pre><code>error {{ namespace.name }}.{{ enum.name }}</code></pre>
{% elif enum.bitfield %}
<pre><code>flags {{ namespace.name }}.{{ enum.name }}</code></pre>
{% else %}
<pre><code>enum {{ namespace.name }}.{{ enum.name }}</code></pre>
{% endif %}
</div>
</div>
<div class="description collapse-toggle">
<h4><a name="description">Description</a></h4>
{{ enum.description|safe }}
</div>
<div class="members">
<h4><a name="members">Members</a></h4>
<table>
{% for member in enum.members %}
<tr>
<td><code>{{ member.name }}</code></td>
<td><code>{{ member.value }}</code></td>
<td><code>&quot;{{ member.nick }}&quot;</code></td>
<td>{{ member.description|safe }}</td>
</tr>
{% endfor %}
</table>
</div>
{% if enum.error_domain %}
<div class="error-domain">
<h4><a name="error-domain">Error domain</a></h4>
<pre><code>&quot;{{ enum.domain }}&quot;</code></pre>
</div>
{% endif %}
{% if enum.type_funcs %}
<div class="type-funcs">
<h4><a name="type-funcs">Type functions</a></h4>
<ul>
{% for func in enum.type_funcs %}
<li><a href="type_func.{{ enum.name }}.{{ func.name }}.html">{{ func.identifier }} ();</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
</section>
</section>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ namespace.name }}.{{ interface.name }}{% endblock %}
{% block meta_other %}
<meta name="og:title" content="{{ namespace.name }}.{{ interface.name }}"/>
<meta name="og:description" content="Reference for {{ namespace.name }}.{{ interface.name }}"/>
{% endblock %}
{% block sidebar %}
<nav class="sidebar">
<div class="namespace">
<h3><a href="index.html">{{ namespace.name }} &mdash; {{ namespace.version }}</a></h3>
</div>
<div class="section">
<h5>Interface</h5>
<div class="links">
<a class="current" href="iface.{{ interface.name }}.html#description">{{ interface.name }}</a>
</div>
</div>
<div class="section">
<h5>Instance methods</h5>
<div class="links">
{% for m in interface.methods %}
<a class="method" href="method.{{ interface.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Interface methods</h5>
<div class="links">
{% for m in interface.class_methods %}
<a class="method" href="class_method.{{ interface.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Type functions</h5>
<div class="links">
{% for m in interface.type_funcs %}
<a class="method" href="type_func.{{ interface.name }}.{{ m.name }}.html">{{ m.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Properties</h5>
<div class="links">
{% for p in interface.properties %}
<a href="property.{{ interface.name }}.{{ p.name }}.html">{{ p.name }}</a>
{% endfor %}
</div>
</div>
<div class="section">
<h5>Signals</h5>
<div class="links">
{% for s in interface.signals %}
<a href="signal.{{ interface.name }}.{{ s.name }}.html">{{ s.name }}</a>
{% endfor %}
</div>
</div>
</nav>
{% endblock %}