mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
convert pystache to private library since it doesn't behave like upstream
This commit is contained in:
parent
dfb21a0f71
commit
a5af8fb8e9
9 changed files with 24 additions and 16 deletions
|
@ -9,7 +9,7 @@ The Deck
|
||||||
__docformat__ = 'restructuredtext'
|
__docformat__ = 'restructuredtext'
|
||||||
|
|
||||||
import tempfile, time, os, random, sys, re, stat, shutil
|
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.db import *
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
|
@ -25,6 +25,7 @@ from anki.tags import initTagTables, tagIds
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from anki.hooks import runHook, hookEmpty
|
from anki.hooks import runHook, hookEmpty
|
||||||
|
from anki.template import render
|
||||||
|
|
||||||
# ensure all the metadata in other files is loaded before proceeding
|
# ensure all the metadata in other files is loaded before proceeding
|
||||||
import anki.models, anki.facts, anki.cards, anki.stats
|
import anki.models, anki.facts, anki.cards, anki.stats
|
||||||
|
@ -1450,8 +1451,8 @@ and due < :now""", now=time.time())
|
||||||
empty['tags'] = ""
|
empty['tags'] = ""
|
||||||
local['tags'] = fact.tags
|
local['tags'] = fact.tags
|
||||||
try:
|
try:
|
||||||
if (pystache.render(format, local) ==
|
if (render(format, local) ==
|
||||||
pystache.render(format, empty)):
|
render(format, empty)):
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
except (KeyError, TypeError, ValueError):
|
except (KeyError, TypeError, ValueError):
|
||||||
|
|
|
@ -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 sqlalchemy.ext.orderinglist import ordering_list
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
from anki.utils import genID, canonifyTags
|
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.utils import parseTags, hexifyID, checksum, stripHTML
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
|
from anki.template import render
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
def alignmentLabels():
|
def alignmentLabels():
|
||||||
|
@ -154,7 +155,7 @@ def formatQA(cid, mid, fact, tags, cm):
|
||||||
format = re.sub("%\((.+?)\)s", "{{\\1}}", format)
|
format = re.sub("%\((.+?)\)s", "{{\\1}}", format)
|
||||||
# allow custom rendering functions & info
|
# allow custom rendering functions & info
|
||||||
fields = runFilter("prepareFields", fields, cid, mid, fact, tags, cm)
|
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)
|
d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
6
anki/template/README.anki
Normal file
6
anki/template/README.anki
Normal 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
|
|
@ -1,5 +1,5 @@
|
||||||
from pystache.template import Template
|
from anki.template.template import Template
|
||||||
from pystache.view import View
|
from anki.template.view import View
|
||||||
|
|
||||||
def render(template, context=None, **kwargs):
|
def render(template, context=None, **kwargs):
|
||||||
context = context and context.copy() or {}
|
context = context and context.copy() or {}
|
|
@ -1,4 +1,4 @@
|
||||||
from pystache import Template
|
from anki.template import Template
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ setup(name='anki',
|
||||||
author_email='anki@ichi2.net',
|
author_email='anki@ichi2.net',
|
||||||
url='http://ichi2.net/anki/index.html',
|
url='http://ichi2.net/anki/index.html',
|
||||||
license='GPLv3',
|
license='GPLv3',
|
||||||
packages=["anki", "anki.importing", "pystache"],
|
packages=["anki", "anki.importing", "anki.template"],
|
||||||
package_data={'anki': ['locale/*/*/*'],},
|
package_data={'anki': ['locale/*/*/*'],},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
|
Loading…
Reference in a new issue