Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fix doctest and rename more 'scripts' to 'script'
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Campbell committed Nov 24, 2020
1 parent 55449d8 commit eed14d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/sage/plot/plot3d/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ cdef class Graphics3d(SageObject):
js_options['axesLabels'] = False

from sage.repl.rich_output import get_display_manager
scripts = get_display_manager().threejs_scripts(options['online'])
scripts = get_display_manager().threejs_script(options['online'])
styles = ''
extra_html = ''

Expand Down
13 changes: 6 additions & 7 deletions src/sage/repl/rich_output/backend_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,27 +583,26 @@ def displayhook(self, plain_text, rich_output):
else:
raise TypeError('rich_output type not supported')

def threejs_offline_scripts(self):
def threejs_offline_script(self):
"""
Three.js scripts for the IPython notebook
Three.js script for the IPython notebook
OUTPUT:
String containing script tags
String containing script tag
EXAMPLES::
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: backend.threejs_offline_scripts()
sage: backend.threejs_offline_script()
'...<script src="/nbextensions/threejs/build/three.min...<\\/script>...'
"""
from sage.repl.rich_output import get_display_manager
CDN_scripts = get_display_manager().threejs_scripts(online=True)
CDN_script = get_display_manager().threejs_script(online=True)
return """
<script src="/nbextensions/threejs/build/three.min.js"></script>
<script src="/nbextensions/threejs/examples/js/controls/OrbitControls.js"></script>
<script>
if ( !window.THREE ) document.write('{}');
</script>
""".format(CDN_scripts.replace('</script>', r'<\/script>').replace('\n', ' \\\n'))
""".format(CDN_script.replace('</script>', r'<\/script>').replace('\n', ' \\\n'))
21 changes: 10 additions & 11 deletions src/sage/repl/rich_output/display_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,30 +716,30 @@ def graphics_from_save(self, save_function, save_kwds,
buf = OutputBuffer.from_file(filename)
return output_container(buf)

def threejs_scripts(self, online):
def threejs_script(self, online):
"""
Return Three.js script tags for the current backend.
Return Three.js script tag for the current backend.
INPUT:
- ``online`` -- Boolean determining script usage context
OUTPUT:
String containing script tags
String containing script tag
.. NOTE::
This base method handles ``online=True`` case only, serving CDN
script tags. Location of scripts for offline usage is
script tag. Location of script for offline usage is
backend-specific.
EXAMPLES::
sage: from sage.repl.rich_output import get_display_manager
sage: get_display_manager().threejs_scripts(online=True)
'...<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@...'
sage: get_display_manager().threejs_scripts(online=False)
sage: get_display_manager().threejs_script(online=True)
'...<script src="https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@...'
sage: get_display_manager().threejs_script(online=False)
Traceback (most recent call last):
...
ValueError: current backend does not support
Expand All @@ -749,11 +749,10 @@ def threejs_scripts(self, online):
import sage.env
import re
import os
with open(os.path.join(sage.env.THREEJS_DIR, 'build', 'three.min.js')) as f:
text = f.read().replace('\n','')
version = re.search(r'REVISION="(\d+)"', text).group(1)
with open(os.path.join(sage.env.THREEJS_DIR, 'version')) as f:
version = f.read().strip()
return """
<script src="https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@r{0}/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@{0}/build/three.min.js"></script>
""".format(version)
try:
return self._backend.threejs_offline_script()
Expand Down

0 comments on commit eed14d3

Please sign in to comment.