diff --git a/cms/__init__.py b/cms/__init__.py
index 8c5a781..751a666 100644
--- a/cms/__init__.py
+++ b/cms/__init__.py
@@ -3,7 +3,7 @@ import os
import pandas as pd
import transport
import copy
-from jinja2 import Environment, BaseLoader
+from jinja2 import Environment, BaseLoader, FileSystemLoader
import importlib
import importlib.util
@@ -61,6 +61,10 @@ class components :
#return ' '.join(['
'.replace(':id',id),_html,'
'])
_html = ' '.join([''.replace(':id',id),_html,'
'])
appContext = Environment(loader=BaseLoader()).from_string(_html)
+ #
+ # If the rendering of the HTML happens here we should plugin custom functions (at the very least)
+ #
+
return appContext.render(**_args)
# return _html
@staticmethod
@@ -119,4 +123,17 @@ class components :
_uri = "/".join(["api",_key,_name])
_map[_uri] = _pointer
return _map
-
\ No newline at end of file
+ @staticmethod
+ def context(_config):
+ """
+ adding custom variables functions to Jinja2, this function should be called after plugins are loaded
+ """
+ _plugins = _config['plugins']
+ # if not location:
+ # env = Environment(loader=BaseLoader())
+ # else:
+ location = _config['layout']['root']
+ # env = Environment(loader=FileSystemLoader(location))
+ env = Environment(loader=BaseLoader())
+ # env.globals['routes'] = _config['plugins']
+ return env
\ No newline at end of file
diff --git a/index.py b/index.py
index 2d34c18..ed26196 100644
--- a/index.py
+++ b/index.py
@@ -11,7 +11,8 @@ import sys
import os
import json
import copy
-
+import io
+import base64
from jinja2 import Environment, BaseLoader
@@ -27,16 +28,18 @@ def favicon():
@_app.route("/")
def _index ():
global _config
- _args = {}
+ _args = {'system':_config['system'],'routes':_config['plugins']}
try:
- _args = {'system':_config['system']}
+
_args['layout'] = _config['layout']
# _args = dict(_args,**_config['layout'])
# _args = copy.copy(_config)
uri = os.sep.join([_config['layout']['root'], _config['layout']['index']])
- _html = cms.components.html(uri,'index')
- e = Environment(loader=BaseLoader()).from_string(_html)
- _args['index'] = e.render(**_args)
+ _html = cms.components.html(uri,'index',_args)
+ _args['index'] = _html
+ # e = Environment(loader=BaseLoader()).from_string(_html)
+ # e = cms.components.context(_config).from_string(_html)
+ # _args['index'] = e.render(**_args)
_index_page = "index.html"
except Exception as e:
print ()
@@ -44,7 +47,7 @@ def _index ():
_index_page = "404.html"
_args['uri'] = request.base_url
pass
-
+
return render_template(_index_page,**_args)
@_app.route('/id/')
@@ -94,6 +97,25 @@ def _getproxy(module,name) :
return _data,_code
+@_app.route("/api//" , methods=['POST'])
+def _post (module,name):
+ global _config
+ uri = '/'.join(['api',module,name])
+
+ _args = request.json
+ code = 404
+
+ _info = ""
+ if uri in _config['plugins'] and _args:
+ _pointer = _config['plugins'][uri]
+ _info = _pointer(_args)
+ if _info:
+ code = 200
+
+ _info =io.BytesIO(_info)
+
+ _info = base64.encodebytes(_info.getvalue()).decode('ascii')
+ return _info,code
@_app.route('/version')
def _version ():
global _config
@@ -110,7 +132,7 @@ def cms_page():
_html = cms.components.html(_uri,_id)
e = Environment(loader=BaseLoader()).from_string(_html)
# _data = {} #cms.components.data(_config)
- _args = {'system':_config['system']}
+ _args = {'system':_config['system'],'routes':_config['plugins']}
_html = ( e.render(**_args))
return _html,200
@@ -149,8 +171,11 @@ if __name__ == '__main__' :
# Let us load the plugins if any are available
if 'plugins' in _config :
_map = cms.components.plugins(_config)
- if _map :
- _config['plugins'] = _map
+ if _map :
+ _config['plugins'] = _map
+ #
+ # register the functions with Jinja2
+ cms.components.context(_config)
_args = _config['system']['app']
_app.run(**_args)
else:
diff --git a/templates/content.html b/templates/content.html
index 2066cae..4f92f1d 100644
--- a/templates/content.html
+++ b/templates/content.html
@@ -1,7 +1,9 @@
-{{index|safe}}
+
{%for _name in layout.menu %}
{%endfor%}
+
+{{index|safe}}
\ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
index 8350737..4fee6f4 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -36,7 +36,7 @@ Vanderbilt University Medical Center
-
+