Skip to content

Commit 578e3ea

Browse files
committed
more progress on examples
1 parent 518a727 commit 578e3ea

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

docs/bin/example_pages.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ def _make_html(examples):
5353
accum.append('<div class="section">\n')
5454
accum.append(' <div class="row auto-eg-padding">\n')
5555

56-
accum.append(_make_html_name(path, header))
56+
_make_html_name(accum, path, header)
5757

5858
accum.append(' <div class="row">\n')
59-
accum.append(_make_html_text(path, header, content))
59+
_make_html_text(accum, path, header, content)
60+
_make_plot_url(accum, path, header, content)
6061
accum.append(" </div>\n")
6162

6263
accum.append(" </div>\n")
@@ -74,12 +75,12 @@ def _make_html(examples):
7475
"""
7576

7677

77-
def _make_html_name(path, header):
78+
def _make_html_name(accum, path, header):
7879
"""Make example name block."""
7980
name = header["name"] if header["name"] else ""
8081
_log(not name, f"{path} does not have name")
8182
name = _strip_html(name.replace(" ", "-").replace(",", "").lower())
82-
return HTML_NAME.format(name=name)
83+
accum.append(HTML_NAME.format(name=name))
8384

8485

8586
HTML_TEXT = """\
@@ -103,7 +104,7 @@ def _make_html_name(path, header):
103104
"""
104105

105106

106-
def _make_html_text(path, header, content):
107+
def _make_html_text(accum, path, header, content):
107108
"""Make text of example."""
108109
columns = "twelve" if "horizontal" in header.get("arrangement", "") else "six"
109110
markdown_content = markdown(header.get("markdown_content", ""))
@@ -112,12 +113,58 @@ def _make_html_text(path, header, content):
112113
)
113114
description = header.get("description", "")
114115
description = HTML_TEXT_DESCRIPTION.format(text=description) if description else ""
115-
return HTML_TEXT.format(
116+
accum.append(HTML_TEXT.format(
116117
columns=columns,
117118
markdown_content=markdown_content,
118119
page_content=page_content,
119120
description=description,
120-
)
121+
))
122+
123+
124+
125+
PLOT_URL = """\
126+
<div class="{columns} columns">
127+
{plot_url_img}
128+
{plot_url_embed}
129+
</div>
130+
"""
131+
132+
PLOT_URL_IMG = """\
133+
<img src="{plot_url}" />
134+
"""
135+
136+
PLOT_URL_EMBED = """\
137+
<iframe id="auto-examples" src="{plot_url}{embed_class}"
138+
style="width: {width} height: {height} border: none;"></iframe>
139+
"""
140+
141+
def _make_plot_url(accum, path, header, content):
142+
"""Handle specified plot URL."""
143+
plot_url = header.get("plot_url")
144+
if not plot_url:
145+
return
146+
columns = "twelve" if "horizontal" in header.get("arrangement", "") else "six"
147+
148+
plot_url_img = ""
149+
plot_url_embed = ""
150+
if (".gif" in plot_url) or (".png" in plot_url):
151+
plot_url_img = PLOT_URL_IMG.format(plot_url=plot_url)
152+
else:
153+
embed_class = ".embed" if "plot.ly" in plot_url else ""
154+
width = f"{header.get('width', '550')}px"
155+
height = f"{header.get('height', '550')}px"
156+
plot_url_embed = PLOT_URL_EMBED.format(
157+
plot_url=plot_url,
158+
embed_class=embed_class,
159+
width=width,
160+
height=height,
161+
)
162+
accum.append(PLOT_URL.format(
163+
columns=columns,
164+
plot_url=plot_url,
165+
plot_url_img=plot_url_img,
166+
plot_url_embed=plot_url_embed,
167+
))
121168

122169

123170
def _parse_args():

0 commit comments

Comments
 (0)