Mercurial > piecrust2
comparison piecrust/templating/jinjaengine.py @ 662:cbd5cdec0695
jinja: Add `md5` filter.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 01 Mar 2016 22:27:04 -0800 |
parents | 7df0a959791c |
children | a14371c5cda7 |
comparison
equal
deleted
inserted
replaced
661:2f780b191541 | 662:cbd5cdec0695 |
---|---|
1 import re | 1 import re |
2 import time | 2 import time |
3 import os.path | 3 import os.path |
4 import hashlib | |
4 import logging | 5 import logging |
5 import threading | 6 import threading |
6 import email.utils | 7 import email.utils |
7 import strict_rfc3339 | 8 import strict_rfc3339 |
8 from jinja2 import Environment, FileSystemLoader, TemplateNotFound | 9 from jinja2 import Environment, FileSystemLoader, TemplateNotFound |
219 'nocache': add_no_cache_parameter, | 220 'nocache': add_no_cache_parameter, |
220 'wordcount': get_word_count, | 221 'wordcount': get_word_count, |
221 'stripoutertag': strip_outer_tag, | 222 'stripoutertag': strip_outer_tag, |
222 'stripslash': strip_slash, | 223 'stripslash': strip_slash, |
223 'titlecase': title_case, | 224 'titlecase': title_case, |
225 'md5': make_md5, | |
224 'atomdate': get_xml_date, | 226 'atomdate': get_xml_date, |
225 'xmldate': get_xml_date, | 227 'xmldate': get_xml_date, |
226 'emaildate': get_email_date, | 228 'emaildate': get_email_date, |
227 'date': get_date}) | 229 'date': get_date}) |
228 | 230 |
308 | 310 |
309 def title_case(value): | 311 def title_case(value): |
310 return value.title() | 312 return value.title() |
311 | 313 |
312 | 314 |
315 def make_md5(value): | |
316 return hashlib.md5(value.lower().encode('utf8')).hexdigest() | |
317 | |
318 | |
313 def get_xml_date(value): | 319 def get_xml_date(value): |
320 """ Formats timestamps like 1985-04-12T23:20:50.52Z | |
321 """ | |
314 if value == 'now': | 322 if value == 'now': |
315 value = time.time() | 323 value = time.time() |
316 return strict_rfc3339.timestamp_to_rfc3339_localoffset(int(value)) | 324 return strict_rfc3339.timestamp_to_rfc3339_localoffset(int(value)) |
317 | 325 |
318 | 326 |
319 def get_email_date(value, localtime=False): | 327 def get_email_date(value, localtime=False): |
328 """ Formats timestamps like Fri, 09 Nov 2001 01:08:47 -0000 | |
329 """ | |
320 if value == 'now': | 330 if value == 'now': |
321 value = time.time() | 331 value = time.time() |
322 return email.utils.formatdate(value, localtime=localtime) | 332 return email.utils.formatdate(value, localtime=localtime) |
323 | 333 |
324 | 334 |