Updating templating system
This commit is contained in:
parent
39b01c5280
commit
5125ad3eba
@ -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")
|
||||
|
@ -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": [
|
||||
{
|
||||
|
9
core/templatestaticdir.py
Normal file
9
core/templatestaticdir.py
Normal file
@ -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']
|
@ -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
|
||||
|
@ -7,31 +7,21 @@ class main:
|
||||
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"]
|
||||
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"
|
||||
|
||||
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,
|
||||
footer = Template(params["mako"]["website"]['footer']).render(
|
||||
copyright = "Dita Aji Pratama",
|
||||
),
|
||||
container = Template(container).render(
|
||||
GV_base_url = globalvar.GV_base_url,
|
||||
greeting = "Hello " + name + ", " + "Welcome to " + globalvar.GV_title
|
||||
container = Template(params["mako"]["website"]['container']).render(
|
||||
baseurl = globalvar.baseurl,
|
||||
greeting = f"Hello world, welcome to {globalvar.title}"
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,3 @@
|
||||
<footer class="mt-auto bg-dark text-light p-3 text-center">
|
||||
© 2022 ${copyright_holder}
|
||||
© 2022 ${copyright}
|
||||
</footer>
|
20
templates/bare/html/template.html
Normal file
20
templates/bare/html/template.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>${title}</title>
|
||||
<script src="${baseurl}/bare/lib/jquery/jquery-3.7.0.min.js"></script>
|
||||
<link href="${baseurl}/bare/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<script src="${baseurl}/bare/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${baseurl}/bare/css/style.css">
|
||||
</head>
|
||||
<body class="d-flex flex-column" style="min-height:100vh;">
|
||||
${topnav}
|
||||
<div class="mb-5">
|
||||
${container}
|
||||
</div>
|
||||
${footer}
|
||||
</body>
|
||||
</html>
|
@ -1,5 +1,5 @@
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
||||
<a class="navbar-brand" href="/">${GV_title}</a>
|
||||
<a class="navbar-brand" href="${baseurl}">${title}</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
@ -1,26 +1,25 @@
|
||||
from core import html
|
||||
from config import directory
|
||||
|
||||
static = [
|
||||
{
|
||||
'name':'/basic_bootstrap/lib',
|
||||
'name':'/bare/lib',
|
||||
'value':{
|
||||
'tools.staticdir.on' : True ,
|
||||
'tools.staticdir.dir' : './templates/basic_bootstrap/static/lib' ,
|
||||
'tools.staticdir.dir' : './templates/bare/static/lib' ,
|
||||
}
|
||||
},
|
||||
{
|
||||
'name':'/basic_bootstrap/css',
|
||||
'name':'/bare/css',
|
||||
'value':{
|
||||
'tools.staticdir.on' : True ,
|
||||
'tools.staticdir.dir' : './templates/basic_bootstrap/static/css' ,
|
||||
'tools.staticdir.dir' : './templates/bare/static/css' ,
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def main(dir, page):
|
||||
|
||||
html_template = html.main.get_html("templates/basic_bootstrap/html")
|
||||
html_template = html.main.get_html("templates/bare/html")
|
||||
html_page = html.main.get_html(dir)
|
||||
params_list = {
|
||||
"template" : html_template ["template.html" ] ,
|
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>${GV_title}</title>
|
||||
<script src="${GV_base_url}/basic_bootstrap/lib/jquery/jquery-3.7.0.min.js"></script>
|
||||
<link href="${GV_base_url}/basic_bootstrap/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<script src="${GV_base_url}/basic_bootstrap/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${GV_base_url}/basic_bootstrap/css/style.css">
|
||||
</head>
|
||||
<body class="d-flex flex-column" style="min-height:100vh;">
|
||||
${topnav}
|
||||
<div class="mb-5">
|
||||
${container}
|
||||
</div>
|
||||
${footer}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user