Last active
April 12, 2017 16:05
-
-
Save BideoWego/05359dd88b731c6bfca3672ea6e9124a to your computer and use it in GitHub Desktop.
Express view helpers loader. Loads all modules in folder and registers all functions on every module under `Helpers.registered`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FlashHelper = {}; | |
FlashHelper.bootstrapAlertClassFor = function(key) { | |
return { | |
"error": "danger", | |
"alert": "danger", | |
"notice": "info" | |
}[key] || key; | |
}; | |
module.exports = FlashHelper; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var express = require('express'); | |
var basename = path.basename(__filename); | |
var Helpers = {}; | |
Helpers.registered = {}; | |
Helpers.register = function(key, cb) { | |
this.registered[key] = cb; | |
}; | |
// Register all helper files | |
var files = fs.readdirSync(__dirname); | |
files.forEach((filename) => { | |
if (filename !== basename) { | |
var helperModule = require(`./${ filename }`); | |
for (var key in helperModule) { | |
var value = helperModule[key]; | |
Helpers.register(key, value); | |
} | |
} | |
}); | |
module.exports = Helpers; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UtilsHelper = {}; | |
UtilsHelper.concat = function(...args) { | |
return args.slice(0, -1).join(''); | |
}; | |
UtilsHelper.join = function(str, ...args) { | |
return args.slice(0, -1).join(str); | |
}; | |
UtilsHelper.json = function(obj) { | |
return JSON.stringify(obj, null, 2); | |
}; | |
module.exports = UtilsHelper; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment