mastercontroller 1.1.16 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MasterAction.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- // version 1.0.16
2
+ // version 1.0.17
3
3
 
4
4
  var master = require('./MasterControl');
5
5
  var fileserver = require('fs');
@@ -24,7 +24,7 @@ class MasterAction{
24
24
 
25
25
  // location starts from the view folder. Ex: partialViews/fileName.html
26
26
  returnPartialView(location, data){
27
- var actionUrl = master.router.currentRoute.root + "app/views/" + location;
27
+ var actionUrl = master.router.currentRoute.root + "/app/views/" + location;
28
28
  var getAction = fileserver.readFileSync(actionUrl, 'utf8');
29
29
  if(typeof(templateFunc) === "function"){
30
30
  return templateFunc(getAction, data);
@@ -96,7 +96,7 @@ class MasterAction{
96
96
  this.params = tools.combineObjects(data, this.params);
97
97
  var func = master.viewList;
98
98
  this.params = tools.combineObjects(this.params, func);
99
- var actionUrl = (location === undefined) ? master.router.currentRoute.root + "app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html" : master.router.currentRoute.root + location;
99
+ var actionUrl = (location === undefined) ? master.router.currentRoute.root + "/app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html" : master.router.currentRoute.root + location;
100
100
  var actionView = fileserver.readFileSync(actionUrl, 'utf8');
101
101
  if(typeof(templateFunc) === "function"){
102
102
  masterView = templateFunc(actionView, data);
@@ -127,7 +127,7 @@ class MasterAction{
127
127
  this.params = tools.combineObjects(data, this.params);
128
128
  var func = master.viewList;
129
129
  this.params = tools.combineObjects(this.params, func);
130
- var viewUrl = (location === undefined || location === "" || location === null) ? master.router.currentRoute.root + "app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html": master.router.currentRoute.root + "app/" + location;
130
+ var viewUrl = (location === undefined || location === "" || location === null) ? master.router.currentRoute.root + "/app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html": master.router.currentRoute.root + "/app/" + location;
131
131
  var viewFile = fileserver.readFileSync(viewUrl,'utf8');
132
132
  if(typeof(templateFunc) === "function"){
133
133
  childView = templateFunc(viewFile, this.params);
@@ -137,7 +137,7 @@ class MasterAction{
137
137
  }
138
138
 
139
139
  this.params.yield = childView;
140
- var masterFile = fileserver.readFileSync(master.router.currentRoute.root + "app/views/layouts/master.html", 'utf8');
140
+ var masterFile = fileserver.readFileSync(master.router.currentRoute.root + "/app/views/layouts/master.html", 'utf8');
141
141
  if(typeof(templateFunc) === "function"){
142
142
  masterView = templateFunc(masterFile, this.params);
143
143
  }
package/MasterControl.js CHANGED
@@ -8,6 +8,7 @@ var https = require('https');
8
8
  var fs = require('fs');
9
9
  var url = require('url');
10
10
  var path = require('path');
11
+ var globSearch = require("glob");
11
12
 
12
13
 
13
14
  class MasterControl {
@@ -146,6 +147,22 @@ class MasterControl {
146
147
  }
147
148
  }
148
149
 
150
+ component(folderLocation, innerFolder){
151
+
152
+ var rootFolderLocation = `${this.root}/${folderLocation}/${innerFolder}`;
153
+ var search = `${rootFolderLocation}/**/*config.js`;
154
+ var files = globSearch.sync(search, rootFolderLocation);
155
+ require(files[0]);
156
+ var searchRoutes = `${rootFolderLocation}/**/*routes.js`;
157
+ var routeFiles = globSearch.sync(searchRoutes, rootFolderLocation);
158
+ var route = routeFiles[0];
159
+ var routeObject = {
160
+ isComponent : true,
161
+ root : rootFolderLocation
162
+ }
163
+ this.router.setup(routeObject);
164
+ require(route);
165
+ }
149
166
 
150
167
 
151
168
  // adds all the server settings needed
@@ -240,6 +257,18 @@ class MasterControl {
240
257
  start(server){
241
258
  this.server = server;
242
259
  }
260
+
261
+ startMVC(foldername){
262
+ var rootFolderLocation = `${this.root}/${foldername}`;
263
+ var search = `${rootFolderLocation}/**/*routes.js`;
264
+ var files = globSearch.sync(search, rootFolderLocation);
265
+ var route = {
266
+ isComponent : false,
267
+ root : `${this.root}`
268
+ }
269
+ this.router.setup(route);
270
+ require(files[0]);
271
+ }
243
272
 
244
273
 
245
274
  // builds and calls all the required tools to have master running completely
package/MasterHtml.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- // version 1.0.16
2
+ // version 1.0.17
3
3
 
4
4
  var master = require('./MasterControl');
5
5
  var temp = require('./MasterTemplate');
@@ -37,24 +37,24 @@ class html {
37
37
  // render all your link tags styles given the folder location
38
38
  renderStyles(folderName, typeArray){
39
39
  var styles = [];
40
- var styleFolder = `${master.router.currentRoute.root}app/assets/stylesheets/`;
41
- var styleLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 3, "/") }app/assets/stylesheets/`;
42
-
43
- if(master.router.currentRoute.isComponent === false){
44
- styleLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 1, "/") }app/assets/stylesheets/`;
40
+ var styleFolder = `/app/assets/stylesheets/`;
41
+ var rootLocation = master.router.currentRoute.root;
42
+ if(master.router.currentRoute.isComponent === true){
43
+ rootLocation = tools.getBackSlashBySection(master.router.currentRoute.root, 2, "/");
44
+ styleFolder = `${rootLocation}${styleFolder}`;
45
45
  }
46
46
  var type = typeArray === undefined ? ["css"] : typeArray;
47
47
 
48
48
  if(folderName){
49
- styleFolder = styleFolder + folderName + "/";
50
- styleLocation = styleLocation + folderName+ "/";
49
+ styleFolder = `${styleFolder}${folderName}/`;
51
50
  }
52
51
  if (fs.existsSync(styleFolder)) {
53
- fs.readdirSync(styleFolder).forEach(function(file){
52
+ fs.readdirSync(styleFolder).forEach(function(file){
54
53
 
55
54
  var fileExtension = file.replace(/^.*\./, '');
56
55
  if(type.indexOf(fileExtension) >= 0){
57
- styles.push(`<link rel="stylesheet" type="text/${type}" href="/${styleLocation}${file}">`);
56
+ var fileLocatoon = `${styleFolder}${file}`
57
+ styles.push(`<link rel="stylesheet" type="text/${type}" href="/${fileLocatoon}">`);
58
58
  }
59
59
  });
60
60
  }
@@ -74,24 +74,25 @@ class html {
74
74
  renderScripts(folderName, typeArray){
75
75
 
76
76
  var scripts = [];
77
- var jsFolder =`${master.router.currentRoute.root}app/assets/javascripts/`;
78
- var jsLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 3, "/")}app/assets/javascripts/`;
79
- if(master.router.currentRoute.isComponent === false){
80
- jsLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 1, "/")}app/assets/javascripts/`;
77
+ var jsFolder =`/app/assets/javascripts/`;
78
+ var rootLocation = master.router.currentRoute.root;
79
+ if(master.router.currentRoute.isComponent === true){
80
+ rootLocation = tools.getBackSlashBySection(master.router.currentRoute.root, 2, "/");
81
+ jsFolder = `${rootLocation}${jsFolder}`;
81
82
  }
82
83
 
83
84
  var type = typeArray === undefined ? ["js"] : typeArray;
84
85
 
85
- if(folderName){
86
- jsFolder = jsFolder + folderName + "/";
87
- jsLocation = jsLocation + folderName + "/";
86
+ if(folderName){
87
+ jsFolder = `${jsFolder}${folderName}/`;
88
88
  }
89
89
 
90
90
  if (fs.existsSync(jsFolder)) {
91
91
  fs.readdirSync(jsFolder).forEach(function(file){
92
92
  var fileExtension = file.replace(/^.*\./, '');
93
93
  if(type.indexOf(fileExtension) >= 0){
94
- scripts.push(`<script src="/${jsLocation}${file}"></script>`);
94
+ var fileLocatoon = `${jsFolder}${file}`
95
+ scripts.push(`<script src="/${fileLocatoon}"></script>`);
95
96
  }
96
97
  });
97
98
  }
@@ -109,35 +110,41 @@ class html {
109
110
  }
110
111
 
111
112
  // renders js using location
112
- renderJS(name, folder){
113
- if(name === ""){
114
- return '';
113
+ renderJS(folderName, name){
114
+ if(folderName === undefined && name === undefined){
115
+ return "";
115
116
  }
116
117
  else{
117
- var jsLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 3, "/")}app/assets/javascripts/`;
118
- if(folder){
119
- jsLocation = jsLocation + folder + "/" + name;
120
- }else{
121
- jsLocation = jsLocation + name;
118
+ var rootLocation = master.router.currentRoute.root;
119
+ var jsFolder = `/app/assets/javascripts/`;
120
+ if(master.router.currentRoute.isComponent === true){
121
+ rootLocation = tools.getBackSlashBySection(master.router.currentRoute.root, 2, "/");
122
+ jsFolder = `${rootLocation}${jsFolder}`;
122
123
  }
123
- return `<script type="text/javascript" src="/${jsLocation}"></script>`;
124
+ if(folderName){
125
+ jsFolder = `${jsFolder}${folderName}/${name}`;
126
+ }
127
+ return `<script type="text/javascript" src="/${jsFolder}"></script>`;
124
128
  }
125
129
  }
126
130
 
127
131
  // render css directly on the page suing location name
128
- renderCss(name, folder){
129
- if(name === ""){
132
+ renderCss(folderName, name){
133
+ if(folderName === undefined && name === undefined){
130
134
  return "";
131
135
  }
132
136
  else{
133
- var styleLocation = `${tools.getBackSlashBySection(master.router.currentRoute.root, 3, "/")}app/assets/stylesheets/`;
137
+ var styleFolder = `/app/assets/stylesheets/`;
138
+ var rootLocation = master.router.currentRoute.root;
139
+ if(master.router.currentRoute.isComponent === true){
140
+ rootLocation = tools.getBackSlashBySection(master.router.currentRoute.root, 2, "/");
141
+ styleFolder = `${rootLocation}${styleFolder}`;
142
+ }
134
143
 
135
- if(folder){
136
- styleLocation = styleLocation + folder + "/" + name;
137
- }else{
138
- styleLocation = styleLocation + name;
144
+ if(folderName){
145
+ styleFolder = `${styleFolder}${folderName}/${name}`;
139
146
  }
140
- return `<link rel="stylesheet" type="text/css" href="/${styleLocation}">`;
147
+ return `<link rel="stylesheet" type="text/css" href="/${styleFolder}">`;
141
148
  }
142
149
  }
143
150
 
package/MasterRouter.js CHANGED
@@ -1,10 +1,11 @@
1
- // version 1.0.18
1
+ // version 1.0.20
2
2
 
3
3
  var master = require('./MasterControl');
4
4
  var tools = require('./MasterTools');
5
5
  const EventEmitter = require("events");
6
6
  var currentRoute = {};
7
- const path = require('path')
7
+ const path = require('path');
8
+ const { root } = require('./MasterControl');
8
9
 
9
10
  var normalizePaths = function(requestPath, routePath, requestParams){
10
11
  var obj = {
@@ -95,38 +96,9 @@ var loadScopedListClasses = function(){
95
96
  class MasterRouter {
96
97
  currentRouteName = null
97
98
  _routes = {}
98
- __rootLocation = "";
99
-
100
- loadRoutes(mimeList){
101
- this.init(mimeList);
102
- }
103
-
104
- addMimeList(mimeList){
105
- this._addMimeList(mimeList);
106
- }
107
-
108
- init(root){
109
- var rootPath = path.join(root, '../');
110
- this.__rootLocation = rootPath;
111
- require( rootPath + "/routes");
112
- }
113
-
99
+
114
100
  start(){
115
101
  var $that = this;
116
- var rootLocation = path.join(this.__rootLocation, '../');
117
- var componentExist = false;
118
- if(rootLocation.includes("components")){
119
- componentExist = true;
120
- }
121
- this.currentRouteName = tools.makeWordId(4);
122
-
123
- if(this._routes[this.currentRouteName] === undefined){
124
- this._routes[this.currentRouteName] = {
125
- root : rootLocation,
126
- isComponent : componentExist,
127
- routes : []
128
- };
129
- }
130
102
  return {
131
103
  route : function(path, toPath, type, constraint){ // function to add to list of routes
132
104
 
@@ -207,6 +179,26 @@ class MasterRouter {
207
179
  }
208
180
  }
209
181
 
182
+ loadRoutes(mimeList){
183
+ this.init(mimeList);
184
+ }
185
+
186
+ addMimeList(mimeList){
187
+ this._addMimeList(mimeList);
188
+ }
189
+
190
+ setup(route){
191
+ this.currentRouteName = tools.makeWordId(4);
192
+
193
+ if(this._routes[this.currentRouteName] === undefined){
194
+ this._routes[this.currentRouteName] = {
195
+ root : route.root,
196
+ isComponent : route.isComponent,
197
+ routes : []
198
+ };
199
+ }
200
+ }
201
+
210
202
  get currentRoute(){
211
203
  return currentRoute;
212
204
  }
package/package.json CHANGED
@@ -3,7 +3,8 @@
3
3
  "qs" : "^6.11.0",
4
4
  "formidable": "^2.0.1",
5
5
  "cookie": "^0.5.0",
6
- "winston": "^3.8.2"
6
+ "winston": "^3.8.2",
7
+ "glob" :"^8.0.3"
7
8
  },
8
9
  "description": "A class library that makes using the Master Framework a breeze",
9
10
  "homepage": "https://github.com/Tailor/MasterController#readme",
@@ -17,5 +18,5 @@
17
18
  "scripts": {
18
19
  "test": "echo \"Error: no test specified\" && exit 1"
19
20
  },
20
- "version": "1.1.16"
21
+ "version": "1.1.18"
21
22
  }