Skip to content

Commit

Permalink
feat: Updating to new moustache variables
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGue committed Nov 15, 2020
1 parent f52b8ac commit 535be1a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
30 changes: 15 additions & 15 deletions src/backend/configurations/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ production:
listenOnHttps: false
enableHTTPBasicAuth: true
default_render:
view: {{{DEFAULT_VIEW}}}{{^DEFAULT_VIEW}}/index/view.html{{{/DEFAULT_VIEW}}
model: {{{DEFAULT_MODEL}}}{{^DEFAULT_MODEL}}/index/model.json{{{/DEFAULT_MODEL}}
controller: {{{DEFAULT_CONTROLLER}}}{{^DEFAULT_CONTROLLER}}/index/controller.js{{{/DEFAULT_CONTROLLER}}
view: $_[DEFAULT_VIEW]$_[^DEFAULT_VIEW]/index/view.html$_[/DEFAULT_VIEW]
model: $_[DEFAULT_MODEL]$_[^DEFAULT_MODEL]/index/model.json$_[/DEFAULT_MODEL]
controller: $_[DEFAULT_CONTROLLER]$_[^DEFAULT_CONTROLLER]/index/controller.js$_[/DEFAULT_CONTROLLER]
log:
level: info
file: './logs/pro-logs.log' #Where log file will be saved. Date will be concatenated before the name.
maxSize: 10000000 #(10MB) Maximum file log size, if one file reaches it, a new file is created.
maxFiles: 30 # Max Files that can be created per day reaching the maxSize.
auth:
user: {{{LOGIN_USER}}}{{^LOGIN_USER}}governify-admin{{{/LOGIN_USER}}
password: {{{LOGIN_PASSWORD}}}{{^LOGIN_PASSWORD}}governify-project{{{/LOGIN_PASSWORD}}
user: $_[LOGIN_USER]$_[^LOGIN_USER]governify-admin$_[/LOGIN_USER]
password: $_[LOGIN_PASSWORD]$_[^LOGIN_PASSWORD]governify-project$_[/LOGIN_PASSWORD]

development:
server:
Expand All @@ -34,12 +34,12 @@ development:
listenOnHttps: false
enableHTTPBasicAuth: true
default_render:
view: {{{DEFAULT_VIEW}}}{{^DEFAULT_VIEW}}/index/view.html{{{/DEFAULT_VIEW}}
model: {{{DEFAULT_MODEL}}}{{^DEFAULT_MODEL}}/index/model.json{{{/DEFAULT_MODEL}}
controller: {{{DEFAULT_CONTROLLER}}}{{^DEFAULT_CONTROLLER}}/index/controller.js{{{/DEFAULT_CONTROLLER}}
view: $_[DEFAULT_VIEW]$_[^DEFAULT_VIEW]/index/view.html$_[/DEFAULT_VIEW]
model: $_[DEFAULT_MODEL]$_[^DEFAULT_MODEL]/index/model.json$_[/DEFAULT_MODEL]
controller: $_[DEFAULT_CONTROLLER]$_[^DEFAULT_CONTROLLER]/index/controller.js$_[/DEFAULT_CONTROLLER]
auth:
user: {{{LOGIN_USER}}}{{^LOGIN_USER}}governify-admin{{{/LOGIN_USER}}
password: {{{LOGIN_PASSWORD}}}{{^LOGIN_PASSWORD}}governify-project{{{/LOGIN_PASSWORD}}
user: $_[LOGIN_USER]$_[^LOGIN_USER]governify-admin$_[/LOGIN_USER]
password: $_[LOGIN_PASSWORD]$_[^LOGIN_PASSWORD]governify-project$_[/LOGIN_PASSWORD]

log:
level: debug
Expand All @@ -59,13 +59,13 @@ testing:
listenOnHttps: false
enableHTTPBasicAuth: false
default_render:
view: {{{DEFAULT_VIEW}}}{{^DEFAULT_VIEW}}/index/view.html{{{/DEFAULT_VIEW}}
model: {{{DEFAULT_MODEL}}}{{^DEFAULT_MODEL}}/index/model.json{{{/DEFAULT_MODEL}}
controller: {{{DEFAULT_CONTROLLER}}}{{^DEFAULT_CONTROLLER}}/index/controller.js{{{/DEFAULT_CONTROLLER}}
view: $_[DEFAULT_VIEW]$_[^DEFAULT_VIEW]/index/view.html$_[/DEFAULT_VIEW]
model: $_[DEFAULT_MODEL]$_[^DEFAULT_MODEL]/index/model.json$_[/DEFAULT_MODEL]
controller: $_[DEFAULT_CONTROLLER]$_[^DEFAULT_CONTROLLER]/index/controller.js$_[/DEFAULT_CONTROLLER]

auth:
user: {{{LOGIN_USER}}}{{^LOGIN_USER}}governify-admin{{{/LOGIN_USER}}
password: {{{LOGIN_PASSWORD}}}{{^LOGIN_PASSWORD}}governify-project{{{/LOGIN_PASSWORD}}
user: $_[LOGIN_USER]$_[^LOGIN_USER]governify-admin$_[/LOGIN_USER]
password: $_[LOGIN_PASSWORD]$_[^LOGIN_PASSWORD]governify-project$_[/LOGIN_PASSWORD]
log:
file: './logs/test-logs.log' #Where log file will be saved. Date will be concatenated before the name.
maxSize: 10000000 #(10MB) Maximum file log size, if one file reaches it, a new file is created.
Expand Down
4 changes: 3 additions & 1 deletion src/backend/configurations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const jsyaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
const mustache = require("mustache");
mustache.escape = function (text) { return text; };

/*
* Export functions and Objects
Expand All @@ -50,7 +51,8 @@ function _addConfiguration(uri, encoding) {
configStringTemplate = fs.readFileSync(path.join(__dirname, uri), encoding);
}

configString = mustache.render(configStringTemplate, process.env);

configString = mustache.render(configStringTemplate, process.env, {}, ['$_[', ']']);

var newConfigurations = jsyaml.safeLoad(configString)[process.env.NODE_ENV ? process.env.NODE_ENV : 'development'];

Expand Down
23 changes: 16 additions & 7 deletions src/backend/model.mustache → src/backend/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

<link rel='shortcut icon' href='./utils/img/favicon.ico'>

<!-- CSS only -->
<!-- Bootstrap5.0
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/css/bootstrap.min.css" integrity="sha384-DhY6onE6f3zzKbjUPRc2hOzGAdEf4/Dz+WJwBvEYL/lkkIsI3ihufq9hk9K4lVoK" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper.js -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/js/bootstrap.bundle.min.js" integrity="sha384-BOsAfwzjNJHrJ8cZidOg56tcQWfp6y72vEJ8xQ9w6Quywb24iOsW913URv1IS4GD" crossorigin="anonymous"></script>
<script type='text/javascript' src='./utils/js/jquery/dist/jquery.min.js'></script>
-->


<!-- Bootstrap3.0 -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'
integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u' crossorigin='anonymous'>
<script type='text/javascript' src='./utils/js/jquery/dist/jquery.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'
integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa'
crossorigin='anonymous'></script>
<!-- Bootstrap3.0 -->



<script type='text/javascript' src='./utils/js/angular/angular.js'></script>

Expand Down Expand Up @@ -94,10 +103,10 @@
.module('renderApp')
.controller('renderController', function ($scope, $http, $location, $state, $stateParams, $templateRequest, $sce, $compile, $q) {
console.log('Render Controller Initialized');
$compile($('#my-element').html(`{{{ FILE_VIEW }}}`).contents())($scope);
$scope.model = {{{ FILE_MODEL }}};
{{{ FILE_CONTROLLER }}}
$compile($('#my-element').html(`$_[FILE_VIEW]`).contents())($scope);
$scope.model = $_[FILE_MODEL];
$_[FILE_CONTROLLER]

});
</script>
</body>
Expand Down
5 changes: 3 additions & 2 deletions src/backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fs = require('fs');
const axios = require('axios')
const jsyaml = require('js-yaml')
const mustache = require("mustache");
mustache.escape = function (text) { return text; };
const config = require('./configurations')

const logger = require("./logger");
Expand Down Expand Up @@ -96,8 +97,8 @@ router.get("/render", async function (req, res) {
FILE_VIEW: fileView
}
logger.info("Displaying render");
var htmlTemplate = fs.readFileSync('./src/backend/model.mustache', 'utf8');
var htmlRendered = mustache.render(htmlTemplate, files)
var htmlTemplate = fs.readFileSync('./src/backend/layout.html', 'utf8');
var htmlRendered = mustache.render(htmlTemplate, files, {}, ['$_[', ']']);
res.send(htmlRendered);
} catch (err) {
logger.warning('Error getting files: ' + err)
Expand Down

0 comments on commit 535be1a

Please sign in to comment.