Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use our own jinja2 template loader #255

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions nbgitpuller/handlers.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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