docs(index): integrate different program types

* put program type inforamtion into shared.yaml to allow accessing it
  from the index.html.mako template.

Fixes #51
This commit is contained in:
Sebastian Thiel
2015-04-26 09:42:01 +02:00
parent b6a48bdcd5
commit fbec9bdbba
4 changed files with 68 additions and 29 deletions

View File

@@ -11,6 +11,15 @@ api:
# when a resource is supposed to be uploaded
upload_action: upload
# Contains values shared among all API implementations
make:
# All known program ids.
types:
- id: api
target_suffix: ''
documentation_engine: rustdoc
- id: cli
target_suffix: -cli
documentation_engine: mkdocs
directories:
# directory under which all generated sources should reside
output: gen

View File

@@ -50,6 +50,9 @@
import os
import json
def gen_type_cfg_path(id):
return '$(API_DIR)/type-' + id + '.yaml'
CMN_SRC = '/src/cmn.rs'
api_name = util.library_name(an, version)
@@ -76,8 +79,8 @@
api_crate_publish_file = api_meta_dir + '/crates/' + util.crate_version(cargo.build_version +
make.aggregated_target_suffix, json.load(open(api_json, 'r')).get('revision', '00000000'))
api_json_overrides = api_meta_dir + '/' + an + '-api_overrides.yaml'
type_specific_json = '$(API_DIR)/type-' + make.id + '.yaml'
api_json_inputs = api_json + ' $(API_SHARED_INFO) ' + type_specific_json
type_specific_cfg = gen_type_cfg_path(make.id)
api_json_inputs = api_json + ' $(API_SHARED_INFO) ' + type_specific_cfg
if os.path.isfile(api_json_overrides):
api_json_inputs += ' ' + api_json_overrides
api_info.append((api_target, api_clean, api_cargo, api_doc, api_crate_publish_file, gen_root))
@@ -135,8 +138,8 @@ publish${agsuffix}: | gen-all${agsuffix} ${space_join(4)}
gen-all${agsuffix}: ${space_join(0)}
% if global_targets:
${doc_index}: docs${agsuffix} ${type_specific_json} ## TODO: all type dependencies: docs-api, docs-cli
$(PYPATH) $(MAKO) --var DOC_ROOT=${doc_root} -io $(MAKO_SRC)/index.html.mako=$@ --data-files $(API_SHARED_INFO) $(API_LIST) ${type_specific_json}
${doc_index}: ${' '.join('docs-' + ti.id for ti in make.types)} ${' '.join(gen_type_cfg_path(ti.id) for ti in make.types)}
$(PYPATH) $(MAKO) --var DOC_ROOT=${doc_root} -io $(MAKO_SRC)/index.html.mako=$@ --data-files $(API_SHARED_INFO) $(API_LIST)
@echo Documentation index created at '$@'
docs-all: ${doc_index}
docs-all-clean:

View File

@@ -1,27 +1,21 @@
<%
import os
from util import (library_name, library_to_crate_name, to_extern_crate_name)
from util import (gen_crate_dir, api_index)
def gen_crate_dir(name, version):
return to_extern_crate_name(library_to_crate_name(library_name(name, version), make.target_suffix))
def api_index(name, version):
crate_dir = gen_crate_dir(name, version)
index_file_path = crate_dir + '/' + crate_dir + '/index.html'
if os.path.isfile(DOC_ROOT + '/' + index_file_path):
return index_file_path
return None
title = 'Google Rust Client API Docs'
title = 'Google Service Documentation for Rust'
first_api_prefix = None
for an in sorted(api.list.keys()):
for v in api.list[an]:
if api_index(an, v):
first_api_prefix = gen_crate_dir(an, v)
break
# for each version
# for each api name
for ti in make.types:
if ti.documentation_engine != 'rustdoc':
continue
for an in sorted(api.list.keys()):
for v in api.list[an]:
if api_index(DOC_ROOT, an, v, ti):
first_api_prefix = gen_crate_dir(an, v, ti)
break
# for each version
# for each api name
# end for each type
assert first_api_prefix
%>\
<!DOCTYPE html>
@@ -34,6 +28,10 @@ DO NOT EDIT !
<head>
<link rel="stylesheet" href="${first_api_prefix}/main.css">
<style type="text/css">
.text {
color: #000000;
font-size: 20px
}
.mod {
color: #4d76ae;
font-size: 20px
@@ -46,12 +44,28 @@ DO NOT EDIT !
<ul>
% for an in sorted(api.list.keys()):
% for v in api.list[an]:
% if not api_index(an, v):
<% continue %>\
% endif
<a class="mod" href="${api_index(an, v)}" title="API docs for ${an} ${v}">${an} ${v}</a><br/>
% endfor
% endfor
<%
has_any_index = False
types = list()
for ti in make.types:
if api_index(DOC_ROOT, an, v, ti):
has_any_index = True
types.append(ti)
# end for each type
%>\
% if not has_any_index:
<% continue %>\
% endif
<span class="text">${an} ${v} (
% for ti in types:
<a class="mod" href="${api_index(DOC_ROOT, an, v, ti)}" title="${ti.id.upper()} docs for the ${an} ${v}">${ti.id.upper()}</a>
% if not loop.last:
,
% endif
% endfor # each program type
)</span><br/>
% endfor # each version
% endfor # each API
</ul>
</body>
</html>

View File

@@ -829,6 +829,19 @@ def crate_version(build_version, revision):
def to_extern_crate_name(crate_name):
return crate_name.replace('-', '_')
def gen_crate_dir(name, version, ti):
return to_extern_crate_name(library_to_crate_name(library_name(name, version), ti.target_suffix))
def api_index(DOC_ROOT, name, version, ti):
crate_dir = gen_crate_dir(name, version, ti)
if ti.documentation_engine == 'rustdoc':
index_file_path = crate_dir + '/' + crate_dir + '/index.html'
else:
index_file_path = crate_dir + '/' + '/index.html'
if os.path.isfile(DOC_ROOT + '/' + index_file_path):
return index_file_path
return None
# return type name of a resource method builder, from a resource name
def rb_type(r):
return "%sMethods" % singular(canonical_type_name(r))