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
@@ -74,22 +99,26 @@ def gen_gallery(app, doctree):
74
99
data .append ((subdir , basename ,
75
100
os .path .join (rootdir , subdir , 'thumbnails' , filename )))
76
101
77
- link_template = """\
78
- <a href="%s"><img src="%s" border="0" alt="%s"/></a>
79
- """
80
102
81
- if len (data ) == 0 :
82
- warnings .warn ("No thumbnails were found" )
83
103
84
- rows = []
85
- for (subdir , basename , thumbfile ) in data :
86
- if thumbfile is not None :
87
- link = 'examples/%s/%s.html' % (subdir , basename )
88
- rows .append (link_template % (link , thumbfile , basename ))
104
+
105
+ for (subdir , basename , thumbfile ) in data :
106
+ if thumbfile is not None :
107
+ link = 'examples/%s/%s.html' % (subdir , basename )
108
+ rows .append (link_template % (link , thumbfile , basename ))
109
+
110
+ if len (data ) == 0 :
111
+ warnings .warn ("No thumbnails were found in %s" % subdir )
112
+
113
+ # Close out the <div> opened up at the top of this loop
114
+ rows .append ("</div>" )
115
+
116
+ content = template % ('\n ' .join (toc_rows ),
117
+ '\n ' .join (rows ))
89
118
90
119
# Only write out the file if the contents have actually changed.
91
120
# Otherwise, this triggers a full rebuild of the docs
92
- content = template % ' \n ' . join ( rows )
121
+
93
122
gallery_path = os .path .join (app .builder .srcdir , '_templates' , 'gallery.html' )
94
123
if os .path .exists (gallery_path ):
95
124
fh = file (gallery_path , 'r' )
0 commit comments