Skip to content

Commit

Permalink
add engine version number to footer, http headers and spec files #129
Browse files Browse the repository at this point in the history
  • Loading branch information
robhrt7 committed May 14, 2015
1 parent b45de31 commit 359805c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
10 changes: 9 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var express = require('express');
var colors = require('colors');
var fs = require('fs');
var fs = require('fs-extra');
var loadOptions = require('./core/loadOptions');
var commander = require('commander');
var bodyParser = require('body-parser');
Expand Down Expand Up @@ -36,6 +36,8 @@ global.pathToApp = __dirname.replace(/^\w:\\/, function (match) {
return match.toLowerCase();
});

global.engineVersion = fs.readJsonSync(global.pathToApp + '/package.json', {throws: false}).version;

// Default logger
var logger = require('./core/logger');
var log = logger.log;
Expand All @@ -48,6 +50,12 @@ if (commander.port) global.opts.core.common.port = parseInt(commander.port);

/* App config */

// Version
app.use(function (req, res, next) {
res.header('X-powered-by', 'SourceJS ' + global.engineVersion);
next();
});

// Optimization
global.app.use(require('compression')());

Expand Down
4 changes: 4 additions & 0 deletions assets/css/project/footer.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
line-height: 2;
}

.source_footer_version {
color: @color-aux2;
}

/* /Footer
---------------------------------------------------------------------------------- */
4 changes: 4 additions & 0 deletions assets/css/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
@color-aux : #999;
@gray: @color-aux;

// aux level2
@color-aux2 : #696969;
@dark-gray: @color-aux2;

// utility
@color-utility: #f1f2f3;
@light-gray: @color-utility;
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/footer.inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>Catalog</h2>
</ul>
</div>
<div class="source_footer_copy">
Copyright © 2013-2015 <a href="http://sourcejs.com" class="source_a_l">Sourcejs.com</a>
Copyright © 2013-2015 <a href="http://sourcejs.com" class="source_a_l">Sourcejs.com</a> <span class="source_footer_version">(v.<%- engineVersion %>)</span>
</div>
</div>
</footer>
33 changes: 15 additions & 18 deletions core/headerFooter.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
'use strict';

var fs = require('fs');
var path = require('path');
var pathToApp = path.dirname(require.main.filename);
var ejs = require('ejs');

exports.getHeaderAndFooter = function () {
var defaultTemplatePath = pathToApp + "/assets/templates/";
var userTemplatePath = global.app.get('user') + "/assets/templates/";
var headerFile = "header.inc.html";
var footerFile = "footer.inc.html";
var defaultTemplatePath = global.pathToApp + '/assets/templates/';
var userTemplatePath = global.app.get('user') + '/assets/templates/';
var headerFile = 'header.inc.html';
var footerFile = 'footer.inc.html';

var data = {};
var output = {};

if(fs.existsSync(userTemplatePath + headerFile)) {
data.header = ejs.render(fs.readFileSync(userTemplatePath + headerFile, "utf-8"));
} else {
data.header = ejs.render(fs.readFileSync(defaultTemplatePath + headerFile, "utf-8"));
}
var userHeaderTplPath = userTemplatePath + headerFile;
var headerTplPath = fs.existsSync(userHeaderTplPath) ? userHeaderTplPath : defaultTemplatePath + headerFile;

if(fs.existsSync(userTemplatePath + footerFile)) {
data.footer = ejs.render(fs.readFileSync(userTemplatePath + footerFile, "utf-8"));
} else {
data.footer = ejs.render(fs.readFileSync(defaultTemplatePath + footerFile, "utf-8"));
}
var userFooterTplPath = userTemplatePath + footerFile;
var footerTplPath = fs.existsSync(userFooterTplPath) ? userFooterTplPath : defaultTemplatePath + footerFile;

return data;
output.header = ejs.render(fs.readFileSync(headerTplPath, 'utf-8'));
output.footer = ejs.render(fs.readFileSync(footerTplPath, 'utf-8'), {
engineVersion: global.engineVersion
});

return output;
};
4 changes: 3 additions & 1 deletion core/middleware/wrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var fs = require('fs');
var fs = require('fs-extra');
var ejs = require('ejs');
var jsdom = require('jsdom');
var path = require('path');
Expand Down Expand Up @@ -103,6 +103,8 @@ exports.process = function (req, res, next) {
// render page and send it as response
req.specData.renderedHtml = ejs.render(template, templateJSON);

req.specData.renderedHtml += '<!-- SourceJS version: ' + global.engineVersion + ' -->';

next();
}
);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"lodash": "^2.4.1",
"log4js": "~0.6.20",
"marked": "^0.3.2",
"node-fs-extra": "^0.8.1",
"path": "^0.4.9",
"phantomjs": "1.9.7-15",
"pretty-hrtime": "^1.0.0",
Expand Down

0 comments on commit 359805c

Please sign in to comment.