Skip to content

Commit cf2edc8

Browse files
author
Martii
committed
Miscellaneous controller cleanup
* Remove controllers `.gitignore` as we don't use nodejitsu anymore * White space adjustment * Mods won't be editing scripts and user profiles so remove those TODO's * Comment typo * One reorder from general to specific Originally applies to #262 ... not part of #262 (comment)
1 parent 6545ec2 commit cf2edc8

File tree

6 files changed

+66
-73
lines changed

6 files changed

+66
-73
lines changed

controllers/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

controllers/_template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
* NOTE: This file is used as a general guideline to creating a new controller file.
5-
* As the project progressing there may some changes to it.
5+
* As the project progresses there may some changes to it.
66
*
77
* Please remember to omit this comment block when creating a new controller file.
88
*/

controllers/document.js

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var git = require('git-rev');
1717
//--- Controller inclusions
1818

1919
//--- Library inclusions
20+
// var documentLib = require('../libs/document');
21+
2022
var modelParser = require('../libs/modelParser');
2123

2224
var renderMd = require('../libs/markdown').renderMd;
@@ -71,66 +73,62 @@ exports.view = function (aReq, aRes, aNext) {
7173
//--- Tasks
7274

7375
// Read the requested md file contents
74-
tasks.push(
75-
function (aCallback) {
76-
fs.readFile(documentPath + '/' + document + '.md', 'utf8', function (aErr, aData) {
77-
var lines = null;
78-
var matches = null;
79-
var heading = null;
80-
var content = null;
81-
82-
if (aErr) {
83-
aCallback({ statusCode: 404, statusMessage: 'Error retrieving page' });
84-
return;
85-
}
86-
87-
// Check if first line is h2 and use for title/heading if present
88-
lines = aData.split('\n');
89-
matches = lines[0].match(/^##\s(.*)$/);
90-
if (matches) {
91-
heading = lines.shift().replace(/^##\s+/, "");
92-
} else {
93-
heading = document;
94-
}
95-
content = lines.join('\n');
96-
97-
// Page metadata
98-
pageMetadata(options, [heading, 'About']);
99-
100-
options.pageHeading = heading;
101-
options.pageData = renderMd(content);
102-
103-
aCallback(null);
104-
});
105-
}
106-
);
76+
tasks.push(function (aCallback) {
77+
fs.readFile(documentPath + '/' + document + '.md', 'utf8', function (aErr, aData) {
78+
var lines = null;
79+
var matches = null;
80+
var heading = null;
81+
var content = null;
82+
83+
if (aErr) {
84+
aCallback({ statusCode: 404, statusMessage: 'Error retrieving page' });
85+
return;
86+
}
87+
88+
// Check if first line is h2 and use for title/heading if present
89+
lines = aData.split('\n');
90+
matches = lines[0].match(/^##\s(.*)$/);
91+
if (matches) {
92+
heading = lines.shift().replace(/^##\s+/, "");
93+
} else {
94+
heading = document;
95+
}
96+
content = lines.join('\n');
97+
98+
// Page metadata
99+
pageMetadata(options, [heading, 'About']);
100+
101+
options.pageHeading = heading;
102+
options.pageData = renderMd(content);
103+
104+
aCallback(null);
105+
});
106+
});
107107

108108
// Read file listing
109-
tasks.push(
110-
function (aCallback) {
111-
fs.readdir(documentPath, function (aErr, aFileList) {
112-
var file = null;
113-
114-
if (aErr || !aFileList) {
115-
aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' });
116-
return;
117-
}
118-
119-
// Dynamically create a file listing of the pages
120-
options.fileList = [];
121-
for (file in aFileList) {
122-
if (/\.md$/.test(aFileList[file])) {
123-
options.fileList.push({
124-
href: aFileList[file].replace(/\.md$/, ''),
125-
textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ')
126-
});
127-
}
109+
tasks.push(function (aCallback) {
110+
fs.readdir(documentPath, function (aErr, aFileList) {
111+
var file = null;
112+
113+
if (aErr || !aFileList) {
114+
aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' });
115+
return;
116+
}
117+
118+
// Dynamically create a file listing of the pages
119+
options.fileList = [];
120+
for (file in aFileList) {
121+
if (/\.md$/.test(aFileList[file])) {
122+
options.fileList.push({
123+
href: aFileList[file].replace(/\.md$/, ''),
124+
textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ')
125+
});
128126
}
127+
}
129128

130-
aCallback(null);
131-
});
132-
}
133-
);
129+
aCallback(null);
130+
});
131+
});
134132
}
135133
else {
136134
// Page metadata
@@ -169,16 +167,13 @@ exports.view = function (aReq, aRes, aNext) {
169167
//--- Tasks
170168

171169
// Read git short hash HEAD for current tree
172-
tasks.push(
173-
174-
function (aCallback) {
175-
git.short(function (aStr) {
176-
options.git.short = aStr;
170+
tasks.push(function (aCallback) {
171+
git.short(function (aStr) {
172+
options.git.short = aStr;
177173

178-
aCallback(null);
179-
});
180-
}
181-
);
174+
aCallback(null);
175+
});
176+
});
182177

183178
// Read git branch name of current tree
184179
tasks.push(

controllers/flag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ var scriptStorage = require('./scriptStorage');
2121

2222
//--- Library inclusions
2323
var flagLib = require('../libs/flag');
24+
2425
var statusCodePage = require('../libs/templateHelpers').statusCodePage;
2526

2627
//--- Configuration inclusions
2728

2829
//---
2930

30-
3131
// Controller to flag and unflag content
3232
exports.flag = function (aReq, aRes, aNext) {
3333
var form = null;

controllers/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var pageMetadata = require('../libs/templateHelpers').pageMetadata;
3838

3939
//--- Configuration inclusions
4040
var htmlWhitelistLink = require('../libs/htmlWhitelistLink.json');
41+
4142
var removeReasons = require('../views/includes/scriptModals.json').removeReasons;
4243

4344
//---
@@ -299,7 +300,6 @@ var setupScriptSidePanel = function (aOptions) {
299300

300301
// Mod
301302
if (authedUser && authedUser.isMod) {
302-
//aOptions.authorTools = {}; // TODO: Support moderator edits on scripts?
303303
aOptions.modTools = {};
304304

305305
if (removeReasons) {

controllers/user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ var User = require('../models/user').User;
2222
var Discussion = require('../models/discussion').Discussion;
2323

2424
//--- Controller inclusions
25+
var scriptStorage = require('./scriptStorage');
26+
2527
var categories = require('./discussion').categories;
2628
var getFlaggedListForContent = require('./flag').getFlaggedListForContent;
27-
var scriptStorage = require('./scriptStorage');
2829

2930
//--- Library inclusions
30-
//var userLib = require('../libs/user');
31+
// var userLib = require('../libs/user');
3132

3233
var helpers = require('../libs/helpers');
3334

@@ -150,7 +151,6 @@ var setupUserSidePanel = function (aOptions) {
150151

151152
// Mod
152153
if (authedUser && authedUser.isMod && (authedUser.role < user.role || aOptions.isYou)) {
153-
//aOptions.userTools = {}; // TODO: Support moderator edits of user profiles?
154154
aOptions.modTools = {};
155155

156156
if (removeReasons) {

0 commit comments

Comments
 (0)