convert pystache to private library since it doesn't behave like upstream

This commit is contained in:
Damien Elmes 2010-11-29 22:51:55 +09:00
parent dfb21a0f71
commit a5af8fb8e9
9 changed files with 24 additions and 16 deletions

View file

@ -9,7 +9,7 @@ The Deck
__docformat__ = 'restructuredtext'
import tempfile, time, os, random, sys, re, stat, shutil
import types, traceback, simplejson, datetime, pystache
import types, traceback, simplejson, datetime
from anki.db import *
from anki.lang import _, ngettext
@ -25,6 +25,7 @@ from anki.tags import initTagTables, tagIds
from operator import itemgetter
from itertools import groupby
from anki.hooks import runHook, hookEmpty
from anki.template import render
# ensure all the metadata in other files is loaded before proceeding
import anki.models, anki.facts, anki.cards, anki.stats
@ -1450,8 +1451,8 @@ and due < :now""", now=time.time())
empty['tags'] = ""
local['tags'] = fact.tags
try:
if (pystache.render(format, local) ==
pystache.render(format, empty)):
if (render(format, local) ==
render(format, empty)):
ok = False
break
except (KeyError, TypeError, ValueError):

View file

@ -12,7 +12,7 @@ Model - define the way in which facts are added and shown
"""
import time, re, pystache
import time, re
from sqlalchemy.ext.orderinglist import ordering_list
from anki.db import *
from anki.utils import genID, canonifyTags
@ -20,6 +20,7 @@ from anki.fonts import toPlatformFont
from anki.utils import parseTags, hexifyID, checksum, stripHTML
from anki.lang import _
from anki.hooks import runFilter
from anki.template import render
from copy import copy
def alignmentLabels():
@ -154,7 +155,7 @@ def formatQA(cid, mid, fact, tags, cm):
format = re.sub("%\((.+?)\)s", "{{\\1}}", format)
# allow custom rendering functions & info
fields = runFilter("prepareFields", fields, cid, mid, fact, tags, cm)
html = pystache.render(format, fields)
html = render(format, fields)
d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm)
return d

View file

@ -0,0 +1,6 @@
Anki uses a modified version of Pystache to provide Mustache-like syntax.
Behaviour is a little different from standard Mustache:
- {{text}} returns text verbatim with no HTML escaping
- {{{text}}} strips an outer span tag
- partial rendering is disabled for security reasons

View file

@ -1,5 +1,5 @@
from pystache.template import Template
from pystache.view import View
from anki.template.template import Template
from anki.template.view import View
def render(template, context=None, **kwargs):
context = context and context.copy() or {}

View file

@ -1,4 +1,4 @@
from pystache import Template
from anki.template import Template
import os.path
import re

View file

@ -24,7 +24,7 @@ setup(name='anki',
author_email='anki@ichi2.net',
url='http://ichi2.net/anki/index.html',
license='GPLv3',
packages=["anki", "anki.importing", "pystache"],
packages=["anki", "anki.importing", "anki.template"],
package_data={'anki': ['locale/*/*/*'],},
include_package_data=True,
zip_safe=False,