Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mdboom merged 1 commit intomatplotlib:masterfromWeatherGod:docs/gallery_remake
Sep 5, 2012
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletionsdoc/sphinxext/gen_gallery.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
# -*- coding: UTF-8 -*-

# generate a thumbnail gallery of examples
template = """\
{%% extends "layout.html" %%}
Expand All@@ -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 %%}
"""
Expand DownExpand Up@@ -42,15 +49,33 @@ def gen_gallery(app, doctree):
'matplotlib_icon',
])

data = []
thumbnails = {}
rows = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe rename tobody_rows orgallery_rows ordata_rows (but this may be confusing b/c it has no relation to the existingdata variable)?

toc_rows = []

link_template = """\
<a href="%s"><img src="%s" border="0" alt="%s"/></a>
"""

header_template = """<div class="section" id="%s">\
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand All@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe rename togallery_template to contrast it with the new templates you added?

'\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')
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp