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
+78 -53
View File
@@ -2,92 +2,125 @@
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 $view = false;
protected $values = Array();
private $_template = '';
private $_extension = '';
private function __construct() {
private $_engine;
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)) {
self::$_instance = new Output();
}
return self::$_instance;
}
public function getInstance() {
public static function getInstance()
{
if (!isset(self::$_instance)) {
return self::newObj();
}
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 = '';
return self::getInstance();
}
public static function renderView($name, $values = null, $location = null) {
if (!$location) {
public static function render($view = '', $values = array())
{
$instance = self::getInstance();
$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);
}
}
self::getInstance()->setView($name, $values, $location)->render();
if (is_ajax_request()) {
echo $instance->_engine->render($template, $values);
return;
}
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();
$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){
global $SIDEBAR;
$SIDEBAR->add($route, $name, $icon, $attributes, $weight);
@@ -103,8 +136,6 @@ class Output {
$SIDEBAR->add_on_new($key, $route, $name, $icon, $attributes, $weight);
}
//========
public static function headAdd($route, $name){
global $DROPDOWN;
$DROPDOWN[] = ['route' => $route, 'name' => $name];
@@ -119,10 +150,4 @@ class Output {
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>";
}
}
Executable → Regular
+4 -1
View File
@@ -16,4 +16,7 @@ RouteCollection::get('*', function(){
//$DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
$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 function render() {
public function render($content = '') {
global $DROPDOWN, $SIDEBAR;
if (is_ajax_request()) {
/*if (is_ajax_request()) {
if(is_file($this->getView()['location'])){
$this->content = file_get_contents($this->getView()['location']);
$this->implate();
@@ -18,36 +18,54 @@ class Dashboard extends RenderableTemplate {
$this->implate();
}
return;
}
}*/
//global $DROPDOWN, $SIDEBAR;
$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/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 .= '<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/themes/black_and_white.css" rel="stylesheet">';
$head .= '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/metisMenu/metisMenu.min.js"></script>';
$head .= '<link href="/plugins/metismenu/dist/metisMenu.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/metismenu/dist/metisMenu.min.js"></script>';
$head .= '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">';
$head .= '<script src="/plugins/datatables/dataTables.js"></script>';
$head .= '<link href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" rel="stylesheet">';
$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 .= '<script src="/dist/script.js"></script>';
$foot .= '<script src="/dist/script.js" defer="true"></script>';
$this->content = file_get_contents(__DIR__ . '/template.html');
@@ -60,19 +78,14 @@ class Dashboard extends RenderableTemplate {
foreach ($DROPDOWN as $item){
$header .= "<a class='dropdown-item' href='".$item['route']."'>".$item['name']."</a>";
}
$this->content = str_replace("{{dropdown}}", $header, $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('{{content}}', $content, $this->content);
$this->implate();
return $this->content;
}
+30 -11
View File
@@ -1,4 +1,5 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
@@ -10,11 +11,11 @@
<!-- Sidebar -->
<nav id="sidebar-wrapper">
<button class="form-control btn-danger menu-toggle menu-small">Fechar</button>
<div class="logo" style="">
<div class="logo">
<img src='/media/logo_white.png' alt="logo" />
</div>
<div class="search-nav" style="">
<div class="search-nav">
<input class="form-control" type="text" placeholder="Busca" />
</div>
@@ -33,14 +34,15 @@
<ul class="nav navbar-nav navbar-left">
<li class="tooltip-sidebar-toggle">
<a href="" class="menu-toggle">
<i class="fa fa-th-list" aria-hidden="true"></i>
{{#icons}} th-list {{/icons}}
</a>
</li>
</ul>
<ul class="nav navbar-top-links navbar-right">
<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">
<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">
@@ -56,23 +58,40 @@
</div>
<!-- BreadCrumbs -->
<div class='breadcrumb'>{{breadcrumb}}</div>
<div class='breadcrumb'>{{> /core/breadcrumb/view/breadcrumb}}</div>
<!-- /BreadCrumbs -->
<div id="page-content-wrapper">
<div class="container-fluid" style="height: 1024px;">
<div id="page-content-wrapper" style="margin-bottom: 60px;">
<div class="container-fluid">
<div class="row">
<div id="content" class="col-lg-12">
{{>content}}
{{content}}
</div>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<div id="modal" class="modal fade" role="dialog"> </div>
<div id="toast-container" class="toast-container p-3 error" style="position: fixed; right: 0px; bottom: 0px;">
</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($this->getView()['location']);
$this->implate();
}
$this->content = file_get_contents(__DIR__ . '/template.html');
$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
+20 -12
View File
@@ -1,23 +1,31 @@
{
"name": "ghost/urfat-bro",
"name": "inforsistemas/urfat-bro",
"description": "The other framework",
"type": "project",
"repositories": [{
"repositories": {
"repo-name": {
"type": "vcs",
"url": "http://192.168.0.9"
},
"0": {
"type": "composer",
"url": "https://satis.inforsistemas-devel1.com.br"
}],
"url": "http://192.168.0.9"
}
},
"authors": [
{
"name": "ahwelp",
"email": "ahwelp@ahwelp.com"
"name": "Artur Welp",
"email": "artur@inforsistemas.com.br"
}
],
"require": {
"urfat/menus": "dev-master",
"urfat/templates": "dev-master",
"urfat/orm": "dev-master",
"urfat/rr": "dev-master",
"urfat/routes": "dev-master",
"urfat/schema": "dev-master"
"inforsistemas/menus": "dev-master",
"inforsistemas/templates": "dev-master",
"inforsistemas/orm": "dev-master",
"inforsistemas/rr": "dev-master",
"inforsistemas/routes": "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