diff --git a/config/directory.py b/config/directory.py index cf7e7c3..550c47a 100644 --- a/config/directory.py +++ b/config/directory.py @@ -1,7 +1,5 @@ import os - -# template import -import templates.basic_bootstrap.main as basic_bootstrap +from core import templatestaticdir # pages directory page = { @@ -21,11 +19,12 @@ dirconfig = { 'tools.staticdir.on' : True , 'tools.staticdir.dir' : './static/css' , }, + '/js' : + { + 'tools.staticdir.on' : True , + 'tools.staticdir.dir' : './static/js' , + }, } -def add(template): - for row in template: - dirconfig[ row['name'] ] = row['value'] - -# template staticdir -add(basic_bootstrap.static) +# template staticdir: dirconfig dirtemplate +templatestaticdir.add(dirconfig, "templates") diff --git a/config/globalvar.py b/config/globalvar.py index fb6a5c0..c46ffbe 100755 --- a/config/globalvar.py +++ b/config/globalvar.py @@ -1,8 +1,7 @@ -GV_base_url = "http://localhost:81" -GV_title = "CostaPy" -GV_copyright = "Dita Aji Pratama" +baseurl = "http://localhost:81" +title = "CostaPy" -GV_menu = { +menu = { "public": { "topnav": [ { diff --git a/core/templatestaticdir.py b/core/templatestaticdir.py new file mode 100644 index 0000000..9327389 --- /dev/null +++ b/core/templatestaticdir.py @@ -0,0 +1,9 @@ +import os + +def add(dirconfig, template_directory): + template_directory = "templates" + template_list = [d for d in os.listdir(template_directory) if os.path.isdir(os.path.join(template_directory, d))] + for template_name in template_list: + template_module = __import__(f"{template_directory}.{template_name}.main", fromlist=["static"]) + for static in getattr(template_module, "static", []): + dirconfig[ static['name'] ] = static['value'] diff --git a/handler.py b/handler.py index 025f94c..a0cb5f5 100755 --- a/handler.py +++ b/handler.py @@ -10,6 +10,8 @@ import modules.public.home as public_home class handler(): def index(self, **kwargs): - kwargs["mako_website"] = basic_bootstrap.main(directory.page["public"], "home") + kwargs["mako"] = { + "website" : bare.main(directory.page["public"], "home") + } return public_home.main().html(kwargs) index.exposed = True diff --git a/modules/public/home.py b/modules/public/home.py index c4a7389..51a4639 100644 --- a/modules/public/home.py +++ b/modules/public/home.py @@ -3,35 +3,25 @@ import config.globalvar as globalvar class main: - def __init__(self): - pass + def __init__(self): + pass - def html(self, params): - - interface_template = params["mako_website"]['template' ] - topnav = params["mako_website"]['topnav' ] - footer = params["mako_website"]['footer' ] - container = params["mako_website"]['container' ] - - name = "World" - - user_roles = ["guest"] - active_page = "Home" - - return Template(interface_template).render( - GV_title = globalvar.GV_title, - GV_base_url = globalvar.GV_base_url, - topnav = Template(topnav).render( - GV_title = globalvar.GV_title, - menu = globalvar.GV_menu['public']['topnav'], - user_roles = user_roles, - active_page = active_page - ), - footer = Template(footer).render( - copyright_holder = globalvar.GV_copyright, - ), - container = Template(container).render( - GV_base_url = globalvar.GV_base_url, - greeting = "Hello " + name + ", " + "Welcome to " + globalvar.GV_title - ) + def html(self, params): + return Template(params["mako"]["website"]['template']).render( + title = globalvar.title, + baseurl = globalvar.baseurl, + topnav = Template(params["mako"]["website"]['topnav']).render( + title = globalvar.title, + baseurl = globalvar.baseurl, + menu = globalvar.menu['public']['topnav'], + user_roles = ["guest"], + active_page = "Home" + ), + footer = Template(params["mako"]["website"]['footer']).render( + copyright = "Dita Aji Pratama", + ), + container = Template(params["mako"]["website"]['container']).render( + baseurl = globalvar.baseurl, + greeting = f"Hello world, welcome to {globalvar.title}" + ) ) diff --git a/templates/basic_bootstrap/html/footer.html b/templates/bare/html/footer.html similarity index 68% rename from templates/basic_bootstrap/html/footer.html rename to templates/bare/html/footer.html index d26197a..0cc51ae 100644 --- a/templates/basic_bootstrap/html/footer.html +++ b/templates/bare/html/footer.html @@ -1,3 +1,3 @@ diff --git a/templates/bare/html/template.html b/templates/bare/html/template.html new file mode 100644 index 0000000..f433c3b --- /dev/null +++ b/templates/bare/html/template.html @@ -0,0 +1,20 @@ + + +
+ + + +