diff --git a/mapshader/flask_app.py b/mapshader/flask_app.py
index 0237e56..f987ce2 100644
--- a/mapshader/flask_app.py
+++ b/mapshader/flask_app.py
@@ -7,7 +7,7 @@
from bokeh.tile_providers import STAMEN_TONER_BACKGROUND
from bokeh.tile_providers import get_provider
-from jinja2 import Template
+from jinja2 import Environment, FileSystemLoader
from bokeh.resources import INLINE
@@ -28,8 +28,9 @@
from mapshader.sources import MapSource
-from mapshader.utils import psutil_fetching, psutils_html
+from mapshader.utils import psutil_fetching
+jinja2_env = Environment(loader=FileSystemLoader("mapshader/templates/"))
def flask_to_tile(source: MapSource, z=0, x=0, y=0):
@@ -122,116 +123,22 @@ def build_previewer(service: MapService):
def service_page(service: MapService):
plot = build_previewer(service)
script, div = components(dict(preview=plot))
-
- template = Template(
- '''
-
-
-
-
-
- {{service.name}}
- {{ resources }}
- {{ script }}
-
-
-
- {{ psutils_html }}
-
-
-
- {% for key in div.keys() %}
- {{ div[key] }}
- {% endfor %}
-
-
-
-
-
- '''
- )
+ template = jinja2_env.get_template("service_page.html")
resources = INLINE.render()
html = template.render(resources=resources,
script=script,
service=service,
len=len,
- div=div,
- psutils_html=psutils_html())
+ div=div)
return html
def index_page(services):
- links = []
- for s in services:
- links.append(f'{s.name}')
-
- html = ''
- html += ''
- html += ''
- html += ''.join(links)
- html += '
'
- html += ''
- html += ''
+ template = jinja2_env.get_template('index_page.html')
- return html
+ return template.render(services=services)
def configure_app(app: Flask, user_source_filepath=None, contains=None):
diff --git a/mapshader/templates/index_page.html b/mapshader/templates/index_page.html
new file mode 100644
index 0000000..4932920
--- /dev/null
+++ b/mapshader/templates/index_page.html
@@ -0,0 +1,10 @@
+
+
+ {% include 'psutils.html' %}
+
+ {%- for s in services %}
+ - {{s.name}}
+ {% endfor %}
+
+
+
diff --git a/mapshader/templates/psutils.html b/mapshader/templates/psutils.html
new file mode 100644
index 0000000..f4b70be
--- /dev/null
+++ b/mapshader/templates/psutils.html
@@ -0,0 +1,134 @@
+
+
+
diff --git a/mapshader/templates/service_page.html b/mapshader/templates/service_page.html
new file mode 100644
index 0000000..815e0e9
--- /dev/null
+++ b/mapshader/templates/service_page.html
@@ -0,0 +1,73 @@
+
+
+
+
+
+ {{service.name}}
+ {{ resources }} {{ script }}
+
+
+
+ {% include "psutils.html" %}
+
+
+
+
+ {% for key in div.keys() %} {{ div[key] }} {% endfor %}
+
+
+
+
+
diff --git a/mapshader/utils.py b/mapshader/utils.py
index 7f69c57..ddee6de 100644
--- a/mapshader/utils.py
+++ b/mapshader/utils.py
@@ -65,141 +65,3 @@ def psutil_fetching():
}
return log
-
-def psutils_html():
- return '''
-
-
-
- '''