Skip to content

Commit 4a64388

Browse files
committed
use JinjaMixin
1 parent 269fc01 commit 4a64388

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

examples/simple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Try with the above links to check that only Extension 2 is responding (Extension
135135

136136
Run `jupyter simple-ext11 --generate-config && vi ~/.jupyter/jupyter_config.py`.
137137

138-
> --generate-config returns an exception `"The ExtensionApp has not ServerApp "`
138+
> TODO `--generate-config` returns an exception `"The ExtensionApp has not ServerApp "`
139139
140140
The generated configuration should contains the following.
141141

examples/simple/simple_ext1/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import os, jinja2
22
from traitlets import Unicode
3-
from jupyter_server.extension.application import ExtensionApp
3+
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
44
from .handlers import (DefaultHandler, RedirectHandler,
55
ParameterHandler, TemplateHandler, TypescriptHandler, ErrorHandler)
66

77
DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
88
DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates")
99

10-
class SimpleApp1(ExtensionApp):
10+
class SimpleApp1(ExtensionAppJinjaMixin, ExtensionApp):
1111

1212
# The name of the extension.
1313
extension_name = "simple_ext1"

examples/simple/simple_ext1/handlers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from jupyter_server.extension.handler import ExtensionHandler
1+
from jupyter_server.extension.handler import ExtensionHandler, ExtensionHandlerJinjaMixin
22

33
class DefaultHandler(ExtensionHandler):
44
def get(self):
@@ -22,10 +22,7 @@ def get(self, matched_part=None, *args, **kwargs):
2222
self.write('<p>var1: {}</p>'.format(var1))
2323
self.write('<p>components: {}</p>'.format(components))
2424

25-
class BaseTemplateHandler(ExtensionHandler):
26-
def get_template(self, path):
27-
"""Return the jinja template object for a given name"""
28-
return self.settings['{}_jinja2_env'.format(self.extension_name)].get_template(path)
25+
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandler): pass
2926

3027
class TypescriptHandler(BaseTemplateHandler):
3128
def get(self):

examples/simple/simple_ext11/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SimpleApp11(SimpleApp1):
4747

4848
@observe('ignore_js')
4949
def _update_ignore_js(self, change):
50-
"""TODO The observe does not work"""
50+
"""TODO Does the observe work?"""
5151
self.log.info('ignore_js has just changed: {}'.format(change))
5252

5353
@property

examples/simple/simple_ext2/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os, jinja2
22
from traitlets import Unicode
3-
from jupyter_server.extension.application import ExtensionApp
3+
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
44
from .handlers import ParameterHandler, TemplateHandler, IndexHandler, ErrorHandler
55

66
DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
77
DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates")
88

9-
class SimpleApp2(ExtensionApp):
9+
class SimpleApp2(ExtensionAppJinjaMixin, ExtensionApp):
1010

1111
# The name of the extension.
1212
extension_name = "simple_ext2"

examples/simple/simple_ext2/handlers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from jupyter_server.extension.handler import ExtensionHandler
1+
from jupyter_server.extension.handler import ExtensionHandler, ExtensionHandlerJinjaMixin
22

33
class ParameterHandler(ExtensionHandler):
44
def get(self, matched_part=None, *args, **kwargs):
@@ -9,10 +9,7 @@ def get(self, matched_part=None, *args, **kwargs):
99
self.write('<p>var1: {}</p>'.format(var1))
1010
self.write('<p>components: {}</p>'.format(components))
1111

12-
class BaseTemplateHandler(ExtensionHandler):
13-
def get_template(self, name):
14-
"""Return the jinja template object for a given name"""
15-
return self.settings['simple_ext2_jinja2_env'].get_template(name)
12+
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandler): pass
1613

1714
class IndexHandler(BaseTemplateHandler):
1815
def get(self):

0 commit comments

Comments
 (0)