Add the mathjax version to the compiled js

This commit is contained in:
Kovid Goyal 2016-05-01 20:17:36 +05:30
parent 6531811efa
commit 6b5ecdc7e1
5 changed files with 13 additions and 3 deletions

1
.gitignore vendored
View File

@ -23,6 +23,7 @@ resources/user-manual-translation-stats.json
resources/content-server/index-generated.html resources/content-server/index-generated.html
resources/content-server/locales.zip resources/content-server/locales.zip
resources/content-server/mathjax.zip.xz resources/content-server/mathjax.zip.xz
resources/content-server/mathjax.version
resources/mozilla-ca-certs.pem resources/mozilla-ca-certs.pem
icons/icns/*.iconset icons/icns/*.iconset
setup/installer/windows/calibre/build.log setup/installer/windows/calibre/build.log

View File

@ -327,7 +327,7 @@ class Bootstrap(Command):
description = 'Bootstrap a fresh checkout of calibre from git to a state where it can be installed. Requires various development tools/libraries/headers' description = 'Bootstrap a fresh checkout of calibre from git to a state where it can be installed. Requires various development tools/libraries/headers'
TRANSLATIONS_REPO = 'https://github.com/kovidgoyal/calibre-translations.git' TRANSLATIONS_REPO = 'https://github.com/kovidgoyal/calibre-translations.git'
sub_commands = 'cacerts build iso639 iso3166 translations gui resources mathjax'.split() sub_commands = 'cacerts build iso639 iso3166 translations gui mathjax resources'.split()
def pre_sub_commands(self, opts): def pre_sub_commands(self, opts):
tdir = self.j(self.d(self.SRC), 'translations') tdir = self.j(self.d(self.SRC), 'translations')

View File

@ -82,3 +82,5 @@ class MathJax(Command):
t.seek(0) t.seek(0)
with open(self.j(self.RESOURCES, 'content-server', 'mathjax.zip.xz'), 'wb') as f: with open(self.j(self.RESOURCES, 'content-server', 'mathjax.zip.xz'), 'wb') as f:
compress(t, f, level=9) compress(t, f, level=9)
with open(self.j(self.RESOURCES, 'content-server', 'mathjax.version'), 'wb') as f:
f.write(zf.comment)

View File

@ -110,10 +110,16 @@ def compile_srv():
rb = os.path.join(base, 'src', 'calibre', 'srv', 'render_book.py') rb = os.path.join(base, 'src', 'calibre', 'srv', 'render_book.py')
with lopen(rb, 'rb') as f: with lopen(rb, 'rb') as f:
rv = str(int(re.search(br'^RENDER_VERSION\s+=\s+(\d+)', f.read(), re.M).group(1))) rv = str(int(re.search(br'^RENDER_VERSION\s+=\s+(\d+)', f.read(), re.M).group(1)))
try:
mathjax_version = P('content-server/mathjax.version', data=True, allow_user_override=False).decode('utf-8')
except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
mathjax_version = '0'
base = P('content-server', allow_user_override=False) base = P('content-server', allow_user_override=False)
fname = os.path.join(rapydscript_dir, 'srv.pyj') fname = os.path.join(rapydscript_dir, 'srv.pyj')
with lopen(fname, 'rb') as f: with lopen(fname, 'rb') as f:
js = compile_pyj(f.read(), fname).replace('__RENDER_VERSION__', rv).encode('utf-8') js = compile_pyj(f.read(), fname).replace('__RENDER_VERSION__', rv).replace('__MATHJAX_VERSION__', mathjax_version).encode('utf-8')
with lopen(os.path.join(base, 'index.html'), 'rb') as f: with lopen(os.path.join(base, 'index.html'), 'rb') as f:
html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1) html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1)
with lopen(os.path.join(base, 'index-generated.html'), 'wb') as f: with lopen(os.path.join(base, 'index-generated.html'), 'wb') as f:
@ -311,7 +317,7 @@ def main(args=sys.argv):
description='RapydScript compiler and REPL. If passed input on stdin, it is compiled and written to stdout. Otherwise a REPL is started.') description='RapydScript compiler and REPL. If passed input on stdin, it is compiled and written to stdout. Otherwise a REPL is started.')
parser.add_argument('--version', action='version', parser.add_argument('--version', action='version',
version='Using RapydScript compiler version: '+ver) version='Using RapydScript compiler version: '+ver)
parser.add_argument('--show-js', action='store_true', help='Have the REPL output compiled javascript before executing it') parser.add_argument('--show-js', action='store_true', help='Have the REPL output the compiled javascript before executing it')
parser.add_argument('--libdir', help='Where to look for imported modules') parser.add_argument('--libdir', help='Where to look for imported modules')
parser.add_argument('--omit-baselib', action='store_true', default=False, help='Omit the RapydScript base library') parser.add_argument('--omit-baselib', action='store_true', default=False, help='Omit the RapydScript base library')
parser.add_argument('--no-private-scope', action='store_true', default=False, help='Do not wrap the output in its own private scope') parser.add_argument('--no-private-scope', action='store_true', default=False, help='Do not wrap the output in its own private scope')

View File

@ -14,6 +14,7 @@ from read_book.db import create_db
from read_book.view import View from read_book.view import View
RENDER_VERSION = __RENDER_VERSION__ RENDER_VERSION = __RENDER_VERSION__
MATHJAX_VERSION = "__MATHJAX_VERSION__"
class ReadUI: class ReadUI: