-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the structure of gallery examples (#1223)
- Loading branch information
Showing
4 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Add custom filters to the Jinja2 environment. | ||
""" | ||
import hashlib | ||
|
||
from sphinx.jinja2glue import BuiltinTemplateLoader | ||
|
||
|
||
def _filemd5(file): | ||
""" | ||
Return the MD5 hash of the file contents. | ||
""" | ||
with open(file, "r") as fp: | ||
data = fp.read() | ||
return hashlib.md5(data.encode()).hexdigest() | ||
|
||
|
||
class MyTemplateBridge(BuiltinTemplateLoader): | ||
""" | ||
Inherit from the default template bridge and add custom filters. | ||
""" | ||
|
||
def init(self, builder, template_name): | ||
super().init(builder, template_name) | ||
# Add custom filters | ||
self.environment.filters["filemd5"] = _filemd5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters