diff --git a/doc/sphinxext/gen_gallery.py b/doc/sphinxext/gen_gallery.py
index aadc2c0e9b8c..3b1323345934 100644
--- a/doc/sphinxext/gen_gallery.py
+++ b/doc/sphinxext/gen_gallery.py
@@ -1,3 +1,5 @@
+# -*- coding: UTF-8 -*-
+
# generate a thumbnail gallery of examples
template = """\
{%% extends "layout.html" %%}
@@ -9,6 +11,11 @@
\
+
%s
"""
+
+ toc_template = """\
+
%s"""
+
+ 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 = """\
-

- """
- 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
opened up at the top of this loop
+ rows.append("
")
+
+ content = template % ('\n'.join(toc_rows),
+ '\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')