Skip to content

Commit

Permalink
Merge pull request #255 from yuvipanda/own-custom
Browse files Browse the repository at this point in the history
Use our own jinja2 template loader
  • Loading branch information
manics committed Mar 17, 2022
2 parents 442b6cd + 0e00333 commit 6c0602b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
27 changes: 10 additions & 17 deletions nbgitpuller/handlers.py
Expand Up @@ -13,6 +13,11 @@
from .version import __version__


jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), 'templates')
),
)

class SyncHandler(IPythonHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -128,19 +133,6 @@ def pull():


class UIHandler(IPythonHandler):
def initialize(self):
super().initialize()
# FIXME: Is this really the best way to use jinja2 here?
# I can't seem to get the jinja2 env in the base handler to
# actually load templates from arbitrary paths ugh.
jinja2_env = self.settings['jinja2_env']
jinja2_env.loader = jinja2.ChoiceLoader([
jinja2_env.loader,
jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), 'templates')
)
])

@web.authenticated
async def get(self):
app_env = os.getenv('NBGITPULLER_APP', default='notebook')
Expand Down Expand Up @@ -169,10 +161,11 @@ async def get(self):
path = 'tree/' + path

self.write(
self.render_template(
'status.html',
repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__
))
jinja_env.get_template('status.html').render(
repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__,
**self.template_namespace
)
)
await self.flush()


Expand Down
12 changes: 5 additions & 7 deletions nbgitpuller/templates/page.html
Expand Up @@ -5,9 +5,7 @@
<meta charset="utf-8">
<title>{% block title %}Jupyter Server{% endblock %}</title>
{% block favicon %}<link id="favicon" rel="shortcut icon" type="image/x-icon" href="{{ static_url("favicon.ico") }}">{% endblock %}
<link rel="stylesheet" href="{{static_url("style/bootstrap.min.css") }}" />
<link rel="stylesheet" href="{{static_url("style/bootstrap-theme.min.css") }}" />
<link rel="stylesheet" href="{{static_url("style/index.css") }}" />
<link rel="stylesheet" href="{{static_url("style/style.min.css") }}" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Expand All @@ -23,15 +21,15 @@

<noscript>
<div id='noscript'>
{% trans %}Jupyter Server requires JavaScript.{% endtrans %}<br>
{% trans %}Please enable it to proceed. {% endtrans %}
Jupyter Server requires JavaScript.<br>
Please enable it to proceed.
</div>
</noscript>

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

Expand Down

0 comments on commit 6c0602b

Please sign in to comment.