Changing template engine to Mustache. Updating Bootstrap. Creating mustache helpers. Changing plugins on the base template

This commit is contained in:
ahwelp
2023-01-24 20:27:58 +00:00
parent e063895ccb
commit b1eb0a7a56
15 changed files with 259 additions and 289 deletions
Executable → Regular
+87 -62
View File
@@ -2,92 +2,125 @@
namespace App\Core\Template; namespace App\Core\Template;
class Output { use Mustache_Engine as Mustache_Engine;
use Mustache_Loader_FilesystemLoader as Mustache_Loader_FilesystemLoader;
class Output
{
private static $_instance; private static $_instance;
private $view = false;
protected $values = Array();
private $_template = ''; private $_template = '';
private $_extension = ''; private $_extension = '';
private function __construct() { private $_engine;
$this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
$this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache'; private function __construct()
{
$this->_template = (defined('TEMPLATE_DEFAULT')) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
$this->_extension = (defined('TEMPLATE_FILETYPE')) ? TEMPLATE_FILETYPE : '.mustache';
$this->_engine = new Mustache_Engine(array(
'entity_flags' => ENT_QUOTES,
'partials_loader' => new Mustache_Loader_FilesystemLoader(DIR_APP),
'pragmas' => [Mustache_Engine::PRAGMA_FILTERS],
));
// ========================
// Helpers
//
// Format {{#icons}}xx{{/icons}} as a font awesome icon
$this->_engine->addHelper('icons', function ($icon) {
return "<i class='fa fa-" . trim($icon) . "' aria-hidden='true'></i>";
});
// Change the {{#strings}}string,module{{/strings}} for the requested localized string
$this->_engine->addHelper('string', function ($string) {
return \Lang::getString(...explode(',', trim($string)));
});
// ========================
// Filters
//
$this->_engine->addHelper('case', [
'lower' => function ($value) {
return strtolower((string) $value);
},
'upper' => function ($value) {
return strtoupper((string) $value);
}
]);
} }
private static function newObj() { private static function newObj()
{
if (!isset(self::$_instance)) { if (!isset(self::$_instance)) {
self::$_instance = new Output(); self::$_instance = new Output();
} }
return self::$_instance; return self::$_instance;
} }
public function getInstance() { public static function getInstance()
{
if (!isset(self::$_instance)) { if (!isset(self::$_instance)) {
return self::newObj(); return self::newObj();
} }
return self::$_instance; return self::$_instance;
} }
public function setTemplate($template = 'DefaultTemplate') { //
// ----------------------------------------
// Done with singletone and template boot
//
//
public static function setTemplate($template = 'DefaultTemplate')
{
self::getInstance()->_template = $template; self::getInstance()->_template = $template;
// self::getInstance()->_template = '';
return self::getInstance(); return self::getInstance();
} }
public static function renderView($name, $values = null, $location = null) { public static function render($view = '', $values = array())
if (!$location) { {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
}
self::getInstance()->setView($name, $values, $location)->render();
}
public static function setView($name = '', $values = Array(), $location = null) {
if($name == ''){ return self::getInstance(); }
$instance = self::getInstance();
$folder = '';
if (!$location) {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
}
$folder = $location;
$location .= $name;
if (strpos($instance->_extension, $location) == 0) {
$location .= $instance->_extension;
}
$instance->view = Array();
$instance->view['location'] = $location;
$instance->view['folder'] = $folder;
$instance->view['values'] = $values;
return self::getInstance();
}
public static function addValue($key, $value){
self::getInstance()->view['values'][$key] = $value;
}
public static function render() {
$instance = self::getInstance(); $instance = self::getInstance();
if(!is_file(__DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php') ){ $template = '';
if ($view != '') {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
if (is_file($location . $view . $instance->_extension)) {
$template = file_get_contents($location . $view . $instance->_extension);
}
}
if (is_ajax_request()) {
echo $instance->_engine->render($template, $values);
return;
}
if (!is_file(__DIR__ . "/classes/" . strtolower($instance->_template) . "/" . $instance->_template . '.php')) {
$instance->_template = 'DefaultTemplate'; $instance->_template = 'DefaultTemplate';
} }
include_once __DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php'; include_once __DIR__ . "/classes/" . strtolower($instance->_template) . "/" . $instance->_template . '.php';
$class = new $instance->_template;
$class->setView($instance->view)->render();
$wrapper = new $instance->_template;
$wrapper = $wrapper->render($template);
echo $instance->_engine->render($wrapper, $values);
} }
//
// ----------------------------------------
// Menu Stuff Here
//
//
public static function addMenu($route, $name, $icon = '', $attributes = [], $weight = 0){ public static function addMenu($route, $name, $icon = '', $attributes = [], $weight = 0){
global $SIDEBAR; global $SIDEBAR;
$SIDEBAR->add($route, $name, $icon, $attributes, $weight); $SIDEBAR->add($route, $name, $icon, $attributes, $weight);
@@ -103,8 +136,6 @@ class Output {
$SIDEBAR->add_on_new($key, $route, $name, $icon, $attributes, $weight); $SIDEBAR->add_on_new($key, $route, $name, $icon, $attributes, $weight);
} }
//========
public static function headAdd($route, $name){ public static function headAdd($route, $name){
global $DROPDOWN; global $DROPDOWN;
$DROPDOWN[] = ['route' => $route, 'name' => $name]; $DROPDOWN[] = ['route' => $route, 'name' => $name];
@@ -119,10 +150,4 @@ class Output {
global $DROPDOWN; global $DROPDOWN;
$DROPDOWN->add_on_new($key, $route, $name, $icon, $attributes, $weight); $DROPDOWN->add_on_new($key, $route, $name, $icon, $attributes, $weight);
} }
public static function icon($icon){
return "<i class='$icon' aria-hidden='true'></i>";
}
} }
Executable → Regular
+4 -1
View File
@@ -16,4 +16,7 @@ RouteCollection::get('*', function(){
//$DROPDOWN = new Menu( array("class" => 'dropdown-menu') ); //$DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
$DROPDOWN = []; $DROPDOWN = [];
}, -11)->doIgnore(); }, -12)->doIgnore();
RouteCollection::get('/template/[r:location]', '\App\Core\Template\Template@getTemplate');
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Core\Template;
class Template{
public function getTemplate($location){
$location = explode('-', $location);
if(array_search('../', $location)){
die;
}
echo file_get_contents(DIR_APP . $location[0] . '/' . $location[1] . '/views/' . $location[2] . '.mustache');
}
}
-128
View File
@@ -1,128 +0,0 @@
<?php
namespace App\Core\Template;
class Output {
private static $_instance;
private $view = false;
protected $values = Array();
private $_template = '';
private $_extension = '';
private function __construct() {
$this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
$this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
}
private static function newObj() {
if (!isset(self::$_instance)) {
self::$_instance = new Output();
}
return self::$_instance;
}
public function getInstance() {
if (!isset(self::$_instance)) {
return self::newObj();
}
return self::$_instance;
}
public function setTemplate($template = 'DefaultTemplate') {
self::getInstance()->_template = $template;
// self::getInstance()->_template = '';
return self::getInstance();
}
public static function renderView($name, $values = null, $location = null) {
if (!$location) {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
}
self::getInstance()->setView($name, $values, $location)->render();
}
public static function setView($name = '', $values = Array(), $location = null) {
if($name == ''){ return self::getInstance(); }
$instance = self::getInstance();
$folder = '';
if (!$location) {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
}
$folder = $location;
$location .= $name;
if (strpos($instance->_extension, $location) == 0) {
$location .= $instance->_extension;
}
$instance->view = Array();
$instance->view['location'] = $location;
$instance->view['folder'] = $folder;
$instance->view['values'] = $values;
return self::getInstance();
}
public static function addValue($key, $value){
self::getInstance()->view['values'][$key] = $value;
}
public static function render() {
$instance = self::getInstance();
if(!is_file(__DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php') ){
$instance->_template = 'DefaultTemplate';
}
include_once __DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php';
$class = new $instance->_template;
$class->setView($instance->view)->render();
}
public static function addMenu($route, $name, $icon = '', $attributes = [], $weight = 0){
global $SIDEBAR;
$SIDEBAR->add($route, $name, $icon, $attributes, $weight);
}
public static function addSubmenu($key, $name, $icon = '', $attributes = [], $weight = 0){
global $SIDEBAR;
$SIDEBAR->create_submenu($key, $name, $icon, $attributes , $weight);
}
public static function addOnSubmenu($key, $route, $name, $icon = '', $attributes = [], $weight = 0){
global $SIDEBAR;
$SIDEBAR->add_on_new($key, $route, $name, $icon, $attributes, $weight);
}
//========
public static function headAdd($route, $name){
global $DROPDOWN;
$DROPDOWN[] = ['route' => $route, 'name' => $name];
}
public static function addSubHeader($key, $name, $icon = '', $attributes = [], $weight = 0){
global $DROPDOWN;
$DROPDOWN->create_submenu($key, $name, $icon, $attributes , $weight);
}
public static function addOnSubHeader($key, $route, $name, $icon = '', $attributes = [], $weight = 0){
global $DROPDOWN;
$DROPDOWN->add_on_new($key, $route, $name, $icon, $attributes, $weight);
}
public static function icon($icon){
return "<i class='$icon' aria-hidden='true'></i>";
}
}
+33 -20
View File
@@ -6,10 +6,10 @@ class Dashboard extends RenderableTemplate {
public $content; public $content;
public function render() { public function render($content = '') {
global $DROPDOWN, $SIDEBAR; global $DROPDOWN, $SIDEBAR;
if (is_ajax_request()) { /*if (is_ajax_request()) {
if(is_file($this->getView()['location'])){ if(is_file($this->getView()['location'])){
$this->content = file_get_contents($this->getView()['location']); $this->content = file_get_contents($this->getView()['location']);
$this->implate(); $this->implate();
@@ -18,36 +18,54 @@ class Dashboard extends RenderableTemplate {
$this->implate(); $this->implate();
} }
return; return;
} }*/
//global $DROPDOWN, $SIDEBAR; //global $DROPDOWN, $SIDEBAR;
$head = ''; $head = '';
$head .= '<script src="/plugins/jquery/jquery.min.js"></script>'; $head .= '<script src="/plugins/jquery/dist/jquery.min.js"></script>';
$head .= '<script src="/plugins/mousetrap/mousetrap.min.js"></script>'; $head .= '<script src="/plugins/mousetrap/mousetrap.min.js"></script>';
$head .= '<script src="/plugins/jquery-mask-plugin/jquery.mask.min.js"></script>'; $head .= '<script src="/plugins/jquery-mask-plugin/dist/jquery.mask.min.js"></script>';
$head .= '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />'; $head .= '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />';
$head .= '<script src="/plugins/bootstrap/bootstrap.bundle.min.js"></script>'; $head .= '<script src="/plugins/bootstrap/bootstrap.bundle.min.js"></script>';
$head .= '<link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />'; $head .= '<script src="/plugins/remoteFill/remoteFill.js"></script>';
// Trumbowyg WYSIWYG
$head .= '<link href="/plugins/trumbowyg/ui/trumbowyg.min.css" rel="stylesheet" />';
$head .= '<script src="/plugins/trumbowyg/trumbowyg.min.js"></script>';
$head .= '<link href="/plugins/fontawesome/css/font-awesome.min.css" rel="stylesheet" />';
$head .= '<link href="/plugins/normalize-css/normalize.css" rel="stylesheet">';
$head .= '<link href="/dist/style.css" rel="stylesheet">'; $head .= '<link href="/dist/style.css" rel="stylesheet">';
$head .= '<link href="/dist/themes/black_and_white.css" rel="stylesheet">'; $head .= '<link href="/dist/themes/black_and_white.css" rel="stylesheet">';
$head .= '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">'; $head .= '<link href="/plugins/metismenu/dist/metisMenu.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/metisMenu/metisMenu.min.js"></script>'; $head .= '<script src="/plugins/metismenu/dist/metisMenu.min.js"></script>';
$head .= '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">'; $head .= '<link href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/datatables/dataTables.js"></script>'; $head .= '<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>';
$head .= '<link rel="stylesheet" href="/plugins/datatables.net-dt/css/jquery.dataTables.min.css">';
$head .= '<script src="/plugins/datatables.net/js/jquery.dataTables.min.js"></script>';
$head .= '<script src="/plugins/bootstrapToastWrapper/dist/bootstrapToastWrapper.js"></script>';
$head .= '<script src="/plugins/html5-qrcode/html5-qrcode.min.js"></script>';
$head .= '<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap5.min.js"></script>';
$head .= '<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap5.min.css">';
$head .= '<script src="/dist/libs.js" defer="true"></script>';
$head .= '<script src="/dist/validation.js" defer="true"></script>';
$foot = ''; $foot = '';
$foot .= '<script src="/dist/script.js"></script>'; $foot .= '<script src="/dist/script.js" defer="true"></script>';
$this->content = file_get_contents(__DIR__ . '/template.html'); $this->content = file_get_contents(__DIR__ . '/template.html');
@@ -60,19 +78,14 @@ class Dashboard extends RenderableTemplate {
foreach ($DROPDOWN as $item){ foreach ($DROPDOWN as $item){
$header .= "<a class='dropdown-item' href='".$item['route']."'>".$item['name']."</a>"; $header .= "<a class='dropdown-item' href='".$item['route']."'>".$item['name']."</a>";
} }
$this->content = str_replace("{{dropdown}}", $header, $this->content); $this->content = str_replace("{{dropdown}}", $header, $this->content);
$this->content = str_replace("{{head}}", $head, $this->content); $this->content = str_replace("{{head}}", $head, $this->content);
if(isset($this->getView()['location']) && is_file($this->getView()['location'])){
$this->content = str_replace('{{>content}}', $this->replaceSections(file_get_contents($this->getView()['location']), $this->_view['values']), $this->content);
}else{
$this->content = str_replace('{{>content}}', '', $this->content);
}
$this->content = str_replace("{{footer}}", $foot, $this->content); $this->content = str_replace("{{footer}}", $foot, $this->content);
$this->content = str_replace('{{content}}', $content, $this->content);
$this->implate(); return $this->content;
} }
+79 -60
View File
@@ -1,78 +1,97 @@
<html> <html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
{{head}}
</head>
<body> <head>
<div id="wrapper"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Sidebar --> <meta charset="utf-8">
<nav id="sidebar-wrapper"> {{head}}
<button class="form-control btn-danger menu-toggle menu-small">Fechar</button> </head>
<div class="logo" style="">
<img src='/media/logo_white.png' alt="logo" />
</div>
<div class="search-nav" style="">
<input class="form-control" type="text" placeholder="Busca"/>
</div>
{{elements}} <body>
<div id="wrapper">
<!-- Sidebar -->
<nav id="sidebar-wrapper">
<button class="form-control btn-danger menu-toggle menu-small">Fechar</button>
<div class="logo">
<img src='/media/logo_white.png' alt="logo" />
</div>
<ul id="side-second-menu" class="hidden nav"></ul> <div class="search-nav">
</nav> <input class="form-control" type="text" placeholder="Busca" />
<!-- /#sidebar-wrapper --> </div>
<!-- /#sidebar-wrapper -->
<!-- Page Content --> {{elements}}
<div id="main-page-wrapper">
<header class='navbar navbar-default navbar-fixed-top' style='min-height: 50px; background-color: #000;'> <ul id="side-second-menu" class="hidden nav"></ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- /#sidebar-wrapper -->
<ul class="nav navbar-nav navbar-left"> <!-- Page Content -->
<li class="tooltip-sidebar-toggle"> <div id="main-page-wrapper">
<a href="" class="menu-toggle">
<i class="fa fa-th-list" aria-hidden="true"></i>
</a>
</li>
</ul>
<ul class="nav navbar-top-links navbar-right"> <header class='navbar navbar-default navbar-fixed-top' style='min-height: 50px; background-color: #000;'>
<li class="nav-item dropdown no-arrow">
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-cog fa-fw"></i>
</a>
<div class="dropdown-menu dropdown-menu-right" >
{{dropdown}}
</div>
</li>
</ul>
</header> <ul class="nav navbar-nav navbar-left">
<li class="tooltip-sidebar-toggle">
<a href="" class="menu-toggle">
{{#icons}} th-list {{/icons}}
</a>
</li>
</ul>
<div id="progress" class="progress hidden" > <ul class="nav navbar-top-links navbar-right">
<div class="progress-bar progress-bar-striped progress-bar-animated active" style="width: 100%;"></div> <li class="nav-item dropdown no-arrow">
</div> <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fa fa-cog fa-fw"></i>
</a>
<div class="dropdown-menu dropdown-menu-right">
{{dropdown}}
</div>
</li>
</ul>
<!-- BreadCrumbs --> </header>
<div class='breadcrumb'>{{breadcrumb}}</div>
<!-- /BreadCrumbs -->
<div id="page-content-wrapper"> <div id="progress" class="progress hidden">
<div class="container-fluid" style="height: 1024px;"> <div class="progress-bar progress-bar-striped progress-bar-animated active" style="width: 100%;"></div>
</div>
<div class="row"> <!-- BreadCrumbs -->
<div id="content" class="col-lg-12"> <div class='breadcrumb'>{{> /core/breadcrumb/view/breadcrumb}}</div>
{{>content}} <!-- /BreadCrumbs -->
</div>
<div id="page-content-wrapper" style="margin-bottom: 60px;">
<div class="container-fluid">
<div class="row">
<div id="content" class="col-lg-12">
{{content}}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- /#page-content-wrapper -->
</div> </div>
<div id="modal" class="modal fade" role="dialog"> </div> </div>
{{footer}}
</body> <div id="toast-container" class="toast-container p-3 error" style="position: fixed; right: 0px; bottom: 0px;">
</html> </div>
<div id="modal" class="modal fade">
<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
{{footer}}
</body>
</html>
View File
View File
+6 -5
View File
@@ -8,12 +8,13 @@ class NullTemplate extends RenderableTemplate {
} }
public function render() { public function render($content = "") {
if (is_file($this->getView()['location'])) { $this->content = file_get_contents(__DIR__ . '/template.html');
$this->content = file_get_contents($this->getView()['location']);
$this->implate(); $this->content = str_replace('{{content}}', $content, $this->content);
}
return $this->content;
} }
@@ -0,0 +1,11 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
{{head}}
</head>
<body>
{{content}}
</body>
</html>
Executable → Regular
+21 -13
View File
@@ -1,23 +1,31 @@
{ {
"name": "ghost/urfat-bro", "name": "inforsistemas/urfat-bro",
"description": "The other framework", "description": "The other framework",
"type": "project", "type": "project",
"repositories": [{ "repositories": {
"type": "composer", "repo-name": {
"url": "https://satis.inforsistemas-devel1.com.br" "type": "vcs",
}], "url": "http://192.168.0.9"
},
"0": {
"type": "composer",
"url": "http://192.168.0.9"
}
},
"authors": [ "authors": [
{ {
"name": "ahwelp", "name": "Artur Welp",
"email": "ahwelp@ahwelp.com" "email": "artur@inforsistemas.com.br"
} }
], ],
"require": { "require": {
"urfat/menus": "dev-master", "inforsistemas/menus": "dev-master",
"urfat/templates": "dev-master", "inforsistemas/templates": "dev-master",
"urfat/orm": "dev-master", "inforsistemas/orm": "dev-master",
"urfat/rr": "dev-master", "inforsistemas/rr": "dev-master",
"urfat/routes": "dev-master", "inforsistemas/routes": "dev-master",
"urfat/schema": "dev-master" "inforsistemas/schema": "dev-master",
"inforsistemas/mustache": "^2.14",
"phpmailer/phpmailer": "^6.7"
} }
} }
View File
View File
Vendored Executable → Regular
View File
Vendored Executable → Regular
View File