From 30ba7c3047520fd2ef086feb036fc729f707c3a3 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sat, 15 Jun 2019 21:34:06 -0300 Subject: [PATCH] Skelet for dev framework. --- .gitignore | 4 +- config.dist.json | 3 + controller/common/home.js | 22 +++ index.html | 25 ++++ phacil.js | 213 ++++++++++++++++++++++++++++++ view/default/common/home.mustache | 3 + 6 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 config.dist.json create mode 100644 controller/common/home.js create mode 100644 index.html create mode 100644 phacil.js create mode 100644 view/default/common/home.mustache diff --git a/.gitignore b/.gitignore index 32f473f..70e5062 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,8 @@ fabric.properties .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -563,3 +564,4 @@ dwsync.xml dw_php_codehinting.config *.mno +config.json \ No newline at end of file diff --git a/config.dist.json b/config.dist.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/config.dist.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/controller/common/home.js b/controller/common/home.js new file mode 100644 index 0000000..9deef3c --- /dev/null +++ b/controller/common/home.js @@ -0,0 +1,22 @@ +class ControllerCommonHome extends Controller { + index() { + console.log('mama'); + + console.log($('body').append('

TESTE

')); + + //console.log(this.registry); + + //console.log(this.registry.get('database').teste()); + console.log(this.database.teste()); + + this.data['header'] = "TESTE"; + + console.log(this.config.has("URL")); + + this.out(); + } + + uma(){ + console.log("UUUUU"); + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..a510b15 --- /dev/null +++ b/index.html @@ -0,0 +1,25 @@ + + + + + Title + + + + + + + + + + \ No newline at end of file diff --git a/phacil.js b/phacil.js new file mode 100644 index 0000000..6392fde --- /dev/null +++ b/phacil.js @@ -0,0 +1,213 @@ +class Phacil { + + constructor(){ + this.error = []; + this.rota = ""; + + this.registry = new Registry(); + console.log(this.error); + + this.linkBehavior(); + + + + } + + get(key) { + return this.registry.get(key); + } + + set(key, value) { + this.registry.set(key, value); + } + + + linkBehavior() { + $('a[intern]').click(function (e) { + e.preventDefault(); + + + }); + } + + route(rota = 'common/home') { + + let parts = rota.split("/"); + + let nameClass; + + this.rota = rota; + + let file = 'controller/'+parts[0]+'/'+parts[1]+'.js'; + + $('head').append(''); + + let folder = parts[0].toLowerCase().replace(/\b[a-z]/g, function(letter) { + return letter.toUpperCase(); + }); + + let archive = parts[1].toLowerCase().replace(/\b[a-z]/g, function(letter) { + return letter.toUpperCase(); + }); + + if(parts.length == 2) { + nameClass = "Controller"+folder+archive; + + var myObject = eval("new " + nameClass + "()"); + myObject.index(); + + } else if(parts.length == 3) { + nameClass = "Controller"+folder+archive; + + var myObject = eval("new " + nameClass + "()"); + + var myClass = eval("myObject." + parts[2] + "()"); + + //myClass; + } + + } + +} + +class Controller { + constructor(registry = null){ + this.registry = (registry != null) ? registry : phacil.registry; + + this.data = {}; + + Object.assign(this, this.registry.retorno()); + + this.replace(); + } + + get(key) { + return this.registry.get(key); + } + + set(key, value) { + this.registry.set(key, value); + } + + redirect(url) { + window.location.replace(url); + } + + replace(){ + $('replace').each(function (index, value) { + console.log(value); + let elemento = $(value); + let route = elemento.attr('route'); + elemento.replaceWith('

hdhd

'); + }) + } + + render(){ + + } + + loadMustache(templatePath) { + let template; + let dados = this.data; + + let templateURL = 'view/default/common/home.mustache'; + + let rendered; + + $.ajax({ + url: templateURL, + method: "get", + async: false, + success: function (data) { + template = data; + Mustache.parse(template); // optional, speeds up future uses + rendered = Mustache.render(template, dados); + + }, + error: function () { + console.log('Error: impossible to load '+templatePath); + } + }); + + return (rendered); + + } + + out(){ + this.loadMustache(); + + this.replace(); + } + +} + +class Registry { + constructor(){ + this.data = []; + } + get(key) { + //console.log(this.data[key]); + return this.data[key] ; + } + + set(key, value) { + + this.data[key] = value; + } + + has(key) { + return (this.data[key]); + } + + retorno (){ + return this.data; + } +} + +class DB { + teste(){ + console.log("cargaDB"); + return true; + } +} + +class config { + constructor(json = null){ + + let jsonData = (json != null) ? json : null; + + if(json == null){ + $.ajax({ + url: 'config.json', + method: "get", + async: false, + dataType: 'json', + success: function (json) { + jsonData = json; + + }, + error: function () { + console.log('Error: impossible to load config file'); + } + }); + } + + console.log(jsonData); + + this.data = jsonData; + } + + get(key){ + return this.data[key]; + + } + + set(key, value) { + + this.data[key] = value; + } + + has(key) { + return (this.data[key].length > 0) ? true : false; + } +} \ No newline at end of file diff --git a/view/default/common/home.mustache b/view/default/common/home.mustache new file mode 100644 index 0000000..77079e3 --- /dev/null +++ b/view/default/common/home.mustache @@ -0,0 +1,3 @@ +{{header}} + + \ No newline at end of file