renderer.py 2.1 KB
Newer Older
1 2 3 4
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
Sli's avatar
Sli committed
5
# - Sli <antoine@bartuccio.fr>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License a published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
#
#

26 27 28
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
Sli's avatar
Sli committed
29
from core.scss.processor import ScssProcessor
30 31
from django.utils.html import escape

32
from core.markdown import markdown as md
33 34 35 36 37 38

register = template.Library()

@register.filter(is_safe=False)
@stringfilter
def markdown(text):
39
    return mark_safe(md(text))
40

Skia's avatar
Skia committed
41 42 43 44 45 46 47 48 49 50 51 52
@register.filter()
@stringfilter
def datetime_format_python_to_PHP(python_format_string):
    """
    Given a python datetime format string, attempts to convert it to the nearest PHP datetime format string possible.
    """
    python2PHP = {"%a": "D", "%a": "D", "%A": "l", "%b": "M", "%B": "F", "%c": "", "%d": "d", "%H": "H", "%I": "h", "%j": "z", "%m": "m", "%M": "i", "%p": "A", "%S": "s", "%U": "", "%w": "w", "%W": "W", "%x": "", "%X": "", "%y": "y", "%Y": "Y", "%Z": "e" }

    php_format_string = python_format_string
    for py, php in python2PHP.items():
        php_format_string = php_format_string.replace(py, php)
    return php_format_string
53

Sli's avatar
Sli committed
54 55
@register.simple_tag()
def scss(path):
Sli's avatar
Sli committed
56 57 58
    """
        Return path of the corresponding css file after compilation
    """
Sli's avatar
Sli committed
59 60
    processor = ScssProcessor(path)
    return processor.get_converted_scss()