Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify API web design #776

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 1 addition & 217 deletions docs/generate_api_navbar_and_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,210 +29,9 @@
'parent_pages': [],
'child_pages': [],
},
{
'page': 'data.tex',
'title': 'Data',
'parent_pages': [],
'child_pages': [],
},
{
'page': 'model.tex',
'title': 'Model',
'parent_pages': [],
'child_pages': [
'model-compositionality.tex',
'model-development.tex',
],
},
{
'page': 'model-compositionality.tex',
'title': 'Compositionality',
'parent_pages': [
'model.tex'
],
'child_pages': [],
},
{
'page': 'model-development.tex',
'title': 'Development',
'parent_pages': [
'model.tex'
],
'child_pages': [],
},
{
'page': 'inference.tex',
'title': 'Inference',
'parent_pages': [],
'child_pages': [
'inference-classes.tex',
'inference-compositionality.tex',
'inference-data-subsampling.tex',
'inference-development.tex',
],
},
{
'page': 'inference-classes.tex',
'title': 'Classes',
'parent_pages': [
'inference.tex'
],
'child_pages': [],
},
{
'page': 'inference-compositionality.tex',
'title': 'Compositionality',
'parent_pages': [
'inference.tex'
],
'child_pages': [],
},
{
'page': 'inference-data-subsampling.tex',
'title': 'Data Subsampling',
'parent_pages': [
'inference.tex'
],
'child_pages': [],
},
{
'page': 'inference-development.tex',
'title': 'Development',
'parent_pages': [
'inference.tex'
],
'child_pages': [],
},
{
'page': 'criticism.tex',
'title': 'Criticism',
'parent_pages': [],
'child_pages': [],
},
{
'page': 'reference.tex',
'title': 'Reference',
'parent_pages': [],
'child_pages': [],
},
]


def generate_navbar(page_data):
"""Return a string. It is the navigation bar for ``page_data``."""
def generate_top_navbar():
# Create top of navbar. (Note this can be cached and not run within a loop.)
top_navbar = """\\begin{abstract}
\section{API and Documentation}
\\begin{lstlisting}[raw=html]
<div class="row" style="padding-bottom: 5%">
<div class="row" style="padding-bottom: 1%">"""
for page_data in PAGES:
title = page_data['title']
page_name = page_data['page']
parent_pages = page_data['parent_pages']
if len(parent_pages) == 0 and \
page_name not in ['index.tex', 'reference.tex']:
top_navbar += '\n'
top_navbar += '<a class="button3" href="/api/'
top_navbar += page_name.replace('.tex', '')
top_navbar += '">'
top_navbar += title
top_navbar += '</a>'

top_navbar += '\n'
top_navbar += '</div>'
return top_navbar

page_name = page_data['page']
title = page_data['title']
parent_pages = page_data['parent_pages']
child_pages = page_data['child_pages']

navbar = generate_top_navbar()
# Create bottom of navbar if there are child pages for that section.
if len(child_pages) > 0 or len(parent_pages) > 0:
if len(parent_pages) > 0:
parent = parent_pages[0]
parent_page = [page_data for page_data in PAGES
if page_data['page'] == parent][0]
pgs = parent_page['child_pages']
else:
pgs = child_pages

navbar += '\n'
navbar += '<div class="row">'
for child_page in pgs:
navbar += '\n'
navbar += '<a class="button4" href="/api/'
navbar += child_page.replace('.tex', '')
navbar += '">'
navbar += [page_data for page_data in PAGES
if page_data['page'] == child_page][0]['title']
navbar += '</a>'

navbar += '\n'
navbar += '</div>'

navbar += '\n'
navbar += """</div>
\end{lstlisting}
\end{abstract}"""

# Set primary button in navbar. If a child page, set primary buttons
# for both top and bottom of navbar.
search_term = '" href="/api/' + page_name.replace('.tex', '') + '">'
navbar = navbar.replace(search_term, ' button-primary' + search_term)
if len(parent_pages) > 0:
parent = parent_pages[0]
search_term = '" href="/api/' + parent.replace('.tex', '') + '">'
navbar = navbar.replace(search_term, ' button-primary' + search_term)

return navbar


def generate_models():
import edward.models as module
from edward.models import RandomVariable
objs = [getattr(module, name) for name in dir(module)]
objs = [obj for obj in objs
if (isinstance(obj, type) and
issubclass(obj, RandomVariable) and
obj != RandomVariable
)
]
objs = sorted(objs, key=lambda cls: cls.__name__)

links = [('@{{ed.models.{}}}').format(cls.__name__) for cls in objs]
return '\n\item'.join(links)


def generate_criticisms():
import edward.criticisms as module
objs = [getattr(module, name) for name in dir(module)]
objs = [obj for obj in objs
if (hasattr(obj, '__call__') or
isinstance(obj, type))
]
objs = sorted(objs, key=lambda cls: cls.__name__)

links = [('@{{ed.criticisms.{}}}').format(cls.__name__) for cls in objs]
return '\n\item'.join(links)


def generate_util():
import edward.util as module
objs = [getattr(module, name) for name in dir(module)]
objs = [obj for obj in objs
if (hasattr(obj, '__call__') or
isinstance(obj, type))
]
objs = sorted(objs, key=lambda cls: cls.__name__)

links = [('@{{ed.util.{}}}').format(cls.__name__) for cls in objs]
return '\n\item'.join(links)


def get_tensorflow_version():
import tensorflow
return str(getattr(tensorflow, '__version__', '<unknown verison>'))
Expand All @@ -248,24 +47,9 @@ def get_tensorflow_version():
path = os.path.join(out_dir, 'api', page_name)
print(path)

# Generate navigation bar.
navbar = generate_navbar(page_data)

# TODO do for /api/ed
# Insert autogenerated content into page.
document = open(path).read()
assert '{{navbar}}' in document, \
("File found for " + path + " but missing {{navbar}} tag.")
document = document.replace('{{navbar}}', navbar)

if '{{models}}' in document:
document = document.replace('{{models}}', generate_models())

if '{{criticisms}}' in document:
document = document.replace('{{criticisms}}', generate_criticisms())

if '{{util}}' in document:
document = document.replace('{{util}}', generate_util())

if '{{tensorflow_version}}' in document:
document = document.replace('{{tensorflow_version}}',
get_tensorflow_version())
Expand Down
3 changes: 0 additions & 3 deletions docs/generate_api_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
toc = ''
for entry in data_map['toc']:
title = entry['title']
if title == 'ed':
continue

section = entry['section']
assert section[0]['title'] == 'Overview'
path = section[0]['path']
Expand Down
8 changes: 4 additions & 4 deletions docs/parser/generate_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def write_docs(output_dir, parser_config, yaml_toc):
symbol_to_file[full_name] + '\n')

# Write a global index containing all full names with links.
# with open(os.path.join(output_dir, 'index.md'), 'w') as f:
# f.write(
# parser.generate_global_index('Edward', parser_config.index,
# parser_config.reference_resolver))
with open(os.path.join(output_dir, 'overview.md'), 'w') as f:
f.write(
parser.generate_global_index('Edward', parser_config.index,
parser_config.reference_resolver))


def add_dict_to_dict(add_from, add_to):
Expand Down
44 changes: 0 additions & 44 deletions docs/tex/api/criticism.tex

This file was deleted.

4 changes: 2 additions & 2 deletions docs/tex/api/index.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\title{API}

{{navbar}}
\section{API and Documentation}

Edward's design reflects the building blocks for probabilistic
modeling. It defines interchangeable components, enabling rapid
Expand Down Expand Up @@ -36,6 +36,6 @@

Navigate modules enabling this analysis above.
See the
\href{/api/reference}{reference page} for a list of the API.
\href{/api/overview}{overview page} for a list of the API.

\subsubsection{References}\label{references}
Loading