1
+ # -*- coding: UTF-8 -*-
2
+
1
3
# generate a thumbnail gallery of examples
2
4
template = """\
3
5
{%% extends "layout.html" %%}
9
11
<h3>Click on any image to see full size image and source code</h3>
10
12
<br/>
11
13
14
+ <li><a class="reference internal" href="#">Gallery</a><ul>
15
+ %s
16
+ </ul>
17
+ </li>
18
+
12
19
%s
13
20
{%% endblock %%}
14
21
"""
@@ -42,15 +49,33 @@ def gen_gallery(app, doctree):
42
49
'matplotlib_icon' ,
43
50
])
44
51
45
- data = []
46
52
thumbnails = {}
53
+ rows = []
54
+ toc_rows = []
55
+
56
+ link_template = """\
57
+ <a href="%s"><img src="%s" border="0" alt="%s"/></a>
58
+ """
59
+
60
+ header_template = """<div class="section" id="%s">\
61
+ <h4>%s<a class="headerlink" href="#%s" title="Permalink to this headline">¶</a></h4>"""
62
+
63
+ toc_template = """\
64
+ <li><a class="reference internal" href="#%s">%s</a></li>"""
65
+
66
+ dirs = ('api' , 'pylab_examples' , 'mplot3d' , 'widgets' , 'axes_grid' )
67
+
68
+ for subdir in dirs :
69
+ rows .append (header_template % (subdir , subdir , subdir ))
70
+ toc_rows .append (toc_template % (subdir , subdir ))
47
71
48
- for subdir in ('api' , 'pylab_examples' , 'mplot3d' , 'widgets' , 'axes_grid' ):
49
72
origdir = os .path .join ('build' , rootdir , subdir )
50
73
thumbdir = os .path .join (outdir , rootdir , subdir , 'thumbnails' )
51
74
if not os .path .exists (thumbdir ):
52
75
os .makedirs (thumbdir )
53
76
77
+ data = []
78
+
54
79
for filename in sorted (glob .glob (os .path .join (origdir , '*.png' ))):
55
80
if filename .endswith ("hires.png" ):
56
81
continue
@@ -77,22 +102,26 @@ def gen_gallery(app, doctree):
77
102
data .append ((subdir , basename ,
78
103
os .path .join (rootdir , subdir , 'thumbnails' , filename )))
79
104
80
- link_template = """\
81
- <a href="%s"><img src="%s" border="0" alt="%s"/></a>
82
- """
83
105
84
- if len (data ) == 0 :
85
- warnings .warn ("No thumbnails were found" )
86
106
87
- rows = []
88
- for (subdir , basename , thumbfile ) in data :
89
- if thumbfile is not None :
90
- link = 'examples/%s/%s.html' % (subdir , basename )
91
- rows .append (link_template % (link , thumbfile , basename ))
107
+
108
+ for (subdir , basename , thumbfile ) in data :
109
+ if thumbfile is not None :
110
+ link = 'examples/%s/%s.html' % (subdir , basename )
111
+ rows .append (link_template % (link , thumbfile , basename ))
112
+
113
+ if len (data ) == 0 :
114
+ warnings .warn ("No thumbnails were found in %s" % subdir )
115
+
116
+ # Close out the <div> opened up at the top of this loop
117
+ rows .append ("</div>" )
118
+
119
+ content = template % ('\n ' .join (toc_rows ),
120
+ '\n ' .join (rows ))
92
121
93
122
# Only write out the file if the contents have actually changed.
94
123
# Otherwise, this triggers a full rebuild of the docs
95
- content = template % ' \n ' . join ( rows )
124
+
96
125
gallery_path = os .path .join (app .builder .srcdir , '_templates' , 'gallery.html' )
97
126
if os .path .exists (gallery_path ):
98
127
fh = file (gallery_path , 'r' )
0 commit comments