refactor(index.html): non-redundant data access

Previously we would define information about the program types
in two places, once for the index, and once per program type.
Now within the index.html, we just load the respective program type
information to have access to the latest at all times.

Closes #104
[skip ci]
This commit is contained in:
Sebastian Thiel
2015-05-10 08:36:36 +02:00
parent e86e55cae7
commit 5c284e1c41
3 changed files with 22 additions and 17 deletions

View File

@@ -138,7 +138,7 @@ publish${agsuffix}: | gen-all${agsuffix} ${space_join(4)}
gen-all${agsuffix}: ${space_join(0)}
% if global_targets:
${doc_index}: ${' '.join('docs-' + ti.id for ti in make.types)} ${' '.join(gen_type_cfg_path(ti.id) for ti in make.types)}
${doc_index}: ${' '.join('docs-' + api_name for api_name in make.types)} ${' '.join(gen_type_cfg_path(api_name) for api_name 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}

View File

@@ -1,17 +1,25 @@
<%
import os
import yaml
from util import (gen_crate_dir, api_index)
title = 'Google Service Documentation for Rust'
# type cache: {'api': type-api.yaml-contents }
tc = dict()
for api_type in make.types:
data = yaml.load_all(open(os.path.join(directories.api_base, 'type-%s.yaml' % api_type)))
tc[api_type] = type(directories)(data.next())
# end for each type to load cache for
first_api_prefix = None
for ti in make.types:
if ti.documentation_engine != 'rustdoc':
for ad in tc.values():
if ad.make.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)
if api_index(DOC_ROOT, an, v, ad.make):
first_api_prefix = gen_crate_dir(an, v, ad.make)
break
# for each version
# for each api name
@@ -46,19 +54,20 @@ DO NOT EDIT !
% for v in api.list[an]:
<%
has_any_index = False
types = list()
for ti in make.types:
if api_index(DOC_ROOT, an, v, ti):
type_names = list()
for api_name, ad in tc.iteritems():
if api_index(DOC_ROOT, an, v, ad.make):
has_any_index = True
types.append(ti)
type_names.append(api_name)
# 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>
% for api_name in type_names:
<% ad = tc[api_name] %>
<a class="mod" href="${api_index(DOC_ROOT, an, v, ad.make)}" title="${ad.make.id.upper()} docs for the ${an} ${v}">${ad.make.id.upper()}</a>
% if not loop.last:
,
% endif