Skip to content

Commit 6c0602b

Browse files
authored
Merge pull request #255 from yuvipanda/own-custom
Use our own jinja2 template loader
2 parents 442b6cd + 0e00333 commit 6c0602b

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

nbgitpuller/handlers.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from .version import __version__
1414

1515

16+
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(
17+
os.path.join(os.path.dirname(__file__), 'templates')
18+
),
19+
)
20+
1621
class SyncHandler(IPythonHandler):
1722
def __init__(self, *args, **kwargs):
1823
super().__init__(*args, **kwargs)
@@ -128,19 +133,6 @@ def pull():
128133

129134

130135
class UIHandler(IPythonHandler):
131-
def initialize(self):
132-
super().initialize()
133-
# FIXME: Is this really the best way to use jinja2 here?
134-
# I can't seem to get the jinja2 env in the base handler to
135-
# actually load templates from arbitrary paths ugh.
136-
jinja2_env = self.settings['jinja2_env']
137-
jinja2_env.loader = jinja2.ChoiceLoader([
138-
jinja2_env.loader,
139-
jinja2.FileSystemLoader(
140-
os.path.join(os.path.dirname(__file__), 'templates')
141-
)
142-
])
143-
144136
@web.authenticated
145137
async def get(self):
146138
app_env = os.getenv('NBGITPULLER_APP', default='notebook')
@@ -169,10 +161,11 @@ async def get(self):
169161
path = 'tree/' + path
170162

171163
self.write(
172-
self.render_template(
173-
'status.html',
174-
repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__
175-
))
164+
jinja_env.get_template('status.html').render(
165+
repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__,
166+
**self.template_namespace
167+
)
168+
)
176169
await self.flush()
177170

178171

nbgitpuller/templates/page.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
<meta charset="utf-8">
66
<title>{% block title %}Jupyter Server{% endblock %}</title>
77
{% block favicon %}<link id="favicon" rel="shortcut icon" type="image/x-icon" href="{{ static_url("favicon.ico") }}">{% endblock %}
8-
<link rel="stylesheet" href="{{static_url("style/bootstrap.min.css") }}" />
9-
<link rel="stylesheet" href="{{static_url("style/bootstrap-theme.min.css") }}" />
10-
<link rel="stylesheet" href="{{static_url("style/index.css") }}" />
8+
<link rel="stylesheet" href="{{static_url("style/style.min.css") }}" />
119
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
1210
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1311

@@ -23,15 +21,15 @@
2321

2422
<noscript>
2523
<div id='noscript'>
26-
{% trans %}Jupyter Server requires JavaScript.{% endtrans %}<br>
27-
{% trans %}Please enable it to proceed. {% endtrans %}
24+
Jupyter Server requires JavaScript.<br>
25+
Please enable it to proceed.
2826
</div>
2927
</noscript>
3028

31-
<div id="header" role="navigation" aria-label="{% trans %}Top Menu{% endtrans %}">
29+
<div id="header" role="navigation" aria-label="Top Menu">
3230
<div id="header-container" class="container">
3331
<div id="jupyter_server" class="nav navbar-brand"><a href="{{default_url}}
34-
{%- if logged_in and token -%}?token={{token}}{%- endif -%}" title='{% trans %}dashboard{% endtrans %}'>
32+
{%- if logged_in and token -%}?token={{token}}{%- endif -%}" title='dashboard'>
3533
{% block logo %}<img src='{{static_url("logo/logo.png") }}' alt='Jupyter Server' />{% endblock %}
3634
</a></div>
3735

0 commit comments

Comments
 (0)