Created
August 28, 2012 15:27
-
-
Save Alquimista/3499097 to your computer and use it in GitHub Desktop.
jinja2 filters
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
def gist(id, filename=None): | |
if filename: | |
embedgist = ( | |
'<script src="https://gist.github.com/%s.js?file=%s"></script>' % ( | |
id, filename)) | |
else: | |
embedgist = ( | |
'<script src="https://gist.github.com/%s.js"></script>' % id) | |
return embedgist |
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
def gravatar(email, size=100, rating='g', default='retro', force_default=False, | |
force_lower=False, use_ssl=False): | |
if use_ssl: | |
url = "https://secure.gravatar.com/avatar/" | |
else: | |
url = "http://www.gravatar.com/avatar/" | |
if force_lower: | |
email = email.lower() | |
hashemail = hashlib.md5(email).hexdigest() | |
link = "{url}{hashemail}?s={size}&d={default}&r={rating}".format( | |
url=url, hashemail=hashemail, size=size, | |
default=default, rating=rating) | |
if force_default: | |
link = link + "&f=y" | |
return link |
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
def videohtml5(url, width, height, autoplay=False, controls=True, preload=False): | |
autoplay = 'autoplay="autoplay"' if autoplay else '' | |
controls = 'controls="controls"' if controls else '' | |
preload = 'preload="preload"' if preload else '' | |
return """ | |
<video src="{src}" width="{width}" height="{height}" {autoplay} {controls} {preload}> | |
<p> | |
If you can't see this video, try with Frefox:<br /> | |
<a href="http://www.mozilla.org/firefox/"><img | |
border="0" alt="Get Firefox" title="Get Firefox" | |
src="http://sfx-images.mozilla.org/affiliates/Buttons/180x60/trust.gif" /></a> | |
</p> | |
</video> | |
""".format(src=url, width=width, height=height, autoplay=autoplay, controls=controls, preload=preload) | |
def audiohtml5(url, autoplay=False, controls=True, preload=False): | |
autoplay = 'autoplay="autoplay"' if autoplay else '' | |
controls = 'controls="controls"' if controls else '' | |
preload = 'preload="preload"' if preload else '' | |
return """ | |
<audio src="{src}" {autoplay} {controls} {preload}> | |
<p> | |
If you can't heard this sound, try with Firefox:<br /> | |
<a href="http://www.mozilla.org/firefox/"><img | |
border="0" alt="Get Firefox" title="Get Firefox" | |
src="http://sfx-images.mozilla.org/affiliates/Buttons/180x60/trust.gif" /></a> | |
</p> | |
</video> | |
""".format(src=url, autoplay=autoplay, controls=controls, preload=preload) |
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
def latex_math(latex): | |
return "https://chart.googleapis.com/chart?cht=tx&chl=" + latex |
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
def placekitten(width, height, color): | |
host = "http://placekitten.com/g/" if color else "http://placekitten.com/" | |
url = "%s%d/%d" % (host, width, height) | |
return '<img src="%s" width="%d" height="%d" alt="I can haz placeholder?" />' % (url, width, height) |
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
def youtube(id, width=560, height=315, related_videos=True, ssl=False, cookie=True): | |
related = "" if related_videos else "?rel=0" | |
protocol = "https://" if ssl else "http://" | |
embed_youtube_url = protocol + "www.youtube.com/embed/" if cookie else "www.youtube-nocookie.com/embed/" | |
return '<iframe width="%d" height="%d" src="%s%s%s" frameborder="0" allowfullscreen></iframe>' % (width, height, embed_youtube_url, id, related) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import hashlib
def gravatar(email, size=100, rating='g', default='retro', force_default=False,
force_lower=False, use_ssl=False):
if use_ssl:
url = "https://secure.gravatar.com/avatar/"
else:
url = "http://www.gravatar.com/avatar/"
if force_lower:
email = email.lower()
hashemail = hashlib.md5(email).hexdigest()
link = "{url}{hashemail}?s={size}&d={default}&r={rating}".format(
url=url, hashemail=hashemail, size=size,
default=default, rating=rating)
if force_default:
link = link + "&f=y"