Updating templating system
This commit is contained in:
		
							parent
							
								
									39b01c5280
								
							
						
					
					
						commit
						5125ad3eba
					
				@ -1,7 +1,5 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					from core import templatestaticdir
 | 
				
			||||||
# template import
 | 
					 | 
				
			||||||
import templates.basic_bootstrap.main   as basic_bootstrap
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# pages directory
 | 
					# pages directory
 | 
				
			||||||
page = {
 | 
					page = {
 | 
				
			||||||
@ -21,11 +19,12 @@ dirconfig = {
 | 
				
			|||||||
        'tools.staticdir.on'    : True ,
 | 
					        'tools.staticdir.on'    : True ,
 | 
				
			||||||
        'tools.staticdir.dir'   : './static/css' ,
 | 
					        'tools.staticdir.dir'   : './static/css' ,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    '/js' :
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        'tools.staticdir.on'    : True ,
 | 
				
			||||||
 | 
					        'tools.staticdir.dir'   : './static/js' ,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add(template):
 | 
					# template staticdir: dirconfig  dirtemplate
 | 
				
			||||||
    for row in template:
 | 
					templatestaticdir.add(dirconfig, "templates")
 | 
				
			||||||
        dirconfig[ row['name'] ] = row['value']
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# template staticdir
 | 
					 | 
				
			||||||
add(basic_bootstrap.static)
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,7 @@
 | 
				
			|||||||
GV_base_url = "http://localhost:81"
 | 
					baseurl = "http://localhost:81"
 | 
				
			||||||
GV_title    = "CostaPy"
 | 
					title    = "CostaPy"
 | 
				
			||||||
GV_copyright    = "Dita Aji Pratama"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
GV_menu = {
 | 
					menu = {
 | 
				
			||||||
    "public": {
 | 
					    "public": {
 | 
				
			||||||
        "topnav": [
 | 
					        "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():
 | 
					class handler():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def index(self, **kwargs):
 | 
					    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)
 | 
					        return public_home.main().html(kwargs)
 | 
				
			||||||
    index.exposed = True
 | 
					    index.exposed = True
 | 
				
			||||||
 | 
				
			|||||||
@ -3,35 +3,25 @@ import	config.globalvar	as globalvar
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class main:
 | 
					class main:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
 		pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def html(self, params):
 | 
					    def html(self, params):
 | 
				
			||||||
 | 
					        return Template(params["mako"]["website"]['template']).render(
 | 
				
			||||||
		interface_template	= params["mako_website"]['template'		]
 | 
					            title	= globalvar.title,
 | 
				
			||||||
		topnav				= params["mako_website"]['topnav'		]
 | 
					            baseurl	= globalvar.baseurl,
 | 
				
			||||||
		footer				= params["mako_website"]['footer'		]
 | 
					            topnav	= Template(params["mako"]["website"]['topnav']).render(
 | 
				
			||||||
		container			= params["mako_website"]['container'	]
 | 
					                title		= globalvar.title,
 | 
				
			||||||
 | 
					                baseurl		= globalvar.baseurl,
 | 
				
			||||||
		name				= "World"
 | 
					                menu		= globalvar.menu['public']['topnav'],
 | 
				
			||||||
 | 
					                user_roles	= ["guest"],
 | 
				
			||||||
		user_roles			= ["guest"]
 | 
					                active_page	= "Home"
 | 
				
			||||||
		active_page			= "Home"
 | 
					            ),
 | 
				
			||||||
 | 
					            footer	= Template(params["mako"]["website"]['footer']).render(
 | 
				
			||||||
		return Template(interface_template).render(
 | 
					                copyright	= "Dita Aji Pratama",
 | 
				
			||||||
			GV_title	= globalvar.GV_title,
 | 
					            ),
 | 
				
			||||||
			GV_base_url	= globalvar.GV_base_url,
 | 
					            container	= Template(params["mako"]["website"]['container']).render(
 | 
				
			||||||
			topnav		= Template(topnav).render(
 | 
					                baseurl		= globalvar.baseurl,
 | 
				
			||||||
				GV_title	= globalvar.GV_title,
 | 
					                greeting	= f"Hello world, welcome to {globalvar.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
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,3 @@
 | 
				
			|||||||
<footer class="mt-auto bg-dark text-light p-3 text-center">
 | 
					<footer class="mt-auto bg-dark text-light p-3 text-center">
 | 
				
			||||||
    © 2022 ${copyright_holder}
 | 
					    © 2022 ${copyright}
 | 
				
			||||||
</footer>
 | 
					</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">
 | 
					<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">
 | 
					  <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>
 | 
					    <span class="navbar-toggler-icon"></span>
 | 
				
			||||||
  </button>
 | 
					  </button>
 | 
				
			||||||
@ -1,26 +1,25 @@
 | 
				
			|||||||
from core   import html
 | 
					from core   import html
 | 
				
			||||||
from config import directory
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static = [
 | 
					static = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        'name':'/basic_bootstrap/lib',
 | 
					        'name':'/bare/lib',
 | 
				
			||||||
        'value':{
 | 
					        'value':{
 | 
				
			||||||
            'tools.staticdir.on'    : True ,
 | 
					            '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':{
 | 
					        'value':{
 | 
				
			||||||
            'tools.staticdir.on'    : True ,
 | 
					            'tools.staticdir.on'    : True ,
 | 
				
			||||||
            'tools.staticdir.dir'   : './templates/basic_bootstrap/static/css' ,
 | 
					            'tools.staticdir.dir'   : './templates/bare/static/css' ,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(dir, page):
 | 
					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)
 | 
					    html_page       = html.main.get_html(dir)
 | 
				
			||||||
    params_list = {
 | 
					    params_list = {
 | 
				
			||||||
        "template"  : html_template ["template.html"    ]   ,
 | 
					        "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