-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Initial rework of gen_gallery.py #714
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
# generate a thumbnail gallery of examples | ||
template = """\ | ||
{%% extends "layout.html" %%} | ||
|
@@ -9,6 +11,11 @@ | |
<h3>Click on any image to see full size image and source code</h3> | ||
<br/> | ||
|
||
<li><a class="reference internal" href="#">Gallery</a><ul> | ||
%s | ||
</ul> | ||
</li> | ||
|
||
%s | ||
{%% endblock %%} | ||
""" | ||
|
@@ -42,15 +49,33 @@ def gen_gallery(app, doctree): | |
'matplotlib_icon', | ||
]) | ||
|
||
data = [] | ||
thumbnails = {} | ||
rows = [] | ||
toc_rows = [] | ||
|
||
link_template = """\ | ||
<a href="%s"><img src="%s" border="0" alt="%s"/></a> | ||
""" | ||
|
||
header_template = """<div class="section" id="%s">\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the div class could be "gallery" so that someone can change the style for the gallery later. The image gallery is different than most pages (mostly images instead of text) and may require different styling (for example, underline the heading, extra spacing between sections, etc.) |
||
<h4>%s<a class="headerlink" href="#%s" title="Permalink to this headline">¶</a></h4>""" | ||
|
||
toc_template = """\ | ||
<li><a class="reference internal" href="#%s">%s</a></li>""" | ||
|
||
dirs = ('api', 'pylab_examples', 'mplot3d', 'widgets', 'axes_grid' ) | ||
|
||
for subdir in dirs : | ||
rows.append(header_template % (subdir, subdir, subdir)) | ||
toc_rows.append(toc_template % (subdir, subdir)) | ||
|
||
for subdir in ('api', 'pylab_examples', 'mplot3d', 'widgets', 'axes_grid' ): | ||
origdir = os.path.join('build', rootdir, subdir) | ||
thumbdir = os.path.join(outdir, rootdir, subdir, 'thumbnails') | ||
if not os.path.exists(thumbdir): | ||
os.makedirs(thumbdir) | ||
|
||
data = [] | ||
|
||
for filename in sorted(glob.glob(os.path.join(origdir, '*.png'))): | ||
if filename.endswith("hires.png"): | ||
continue | ||
|
@@ -77,22 +102,26 @@ def gen_gallery(app, doctree): | |
data.append((subdir, basename, | ||
os.path.join(rootdir, subdir, 'thumbnails', filename))) | ||
|
||
link_template = """\ | ||
<a href="%s"><img src="%s" border="0" alt="%s"/></a> | ||
""" | ||
|
||
if len(data) == 0: | ||
warnings.warn("No thumbnails were found") | ||
|
||
rows = [] | ||
for (subdir, basename, thumbfile) in data: | ||
if thumbfile is not None: | ||
link = 'examples/%s/%s.html'%(subdir, basename) | ||
rows.append(link_template%(link, thumbfile, basename)) | ||
|
||
for (subdir, basename, thumbfile) in data: | ||
if thumbfile is not None: | ||
link = 'examples/%s/%s.html'%(subdir, basename) | ||
rows.append(link_template%(link, thumbfile, basename)) | ||
|
||
if len(data) == 0: | ||
warnings.warn("No thumbnails were found in %s" % subdir) | ||
|
||
# Close out the <div> opened up at the top of this loop | ||
rows.append("</div>") | ||
|
||
content = template % ('\n'.join(toc_rows), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename to |
||
'\n'.join(rows)) | ||
|
||
# Only write out the file if the contents have actually changed. | ||
# Otherwise, this triggers a full rebuild of the docs | ||
content = template%'\n'.join(rows) | ||
|
||
gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html') | ||
if os.path.exists(gallery_path): | ||
fh = file(gallery_path, 'r') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to
body_rows
orgallery_rows
ordata_rows
(but this may be confusing b/c it has no relation to the existingdata
variable)?