Created
September 30, 2011 20:25
-
-
Save ibrow/1254879 to your computer and use it in GitHub Desktop.
Experimenting with Middle End
This file contains 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
/** | |
* Simple module for greeting people | |
**/ | |
var Tidy = require('./tidy'); | |
var Greetings = function() { } | |
Greetings.prototype.hello = function(who) { | |
who = Tidy.trim(who); | |
return this.hello(who); | |
} | |
module.exports = Greetings; |
This file contains 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
/** | |
* Client Side script, creating the "Middle End" | |
**/ | |
var require = function(module) { | |
document.write('<script type="text/javascript" src="'+module+'.js"></script>'); | |
} | |
var module = { | |
exports: undefined | |
}; |
This file contains 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
<html> | |
<head><title>Testing the Middle End</title> | |
<script type="text/javascript" src="middleware.js"></script> | |
<script type="text/javascript"> | |
require("greetings"); | |
</script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var greetings = new Greetings(); | |
document.write("<p>"+greetings.hello(' HTML ')+"!</p>"); | |
</script> | |
</body> | |
</html> |
This file contains 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
/** | |
* NodeJS server side script for experimenting with the Middle End | |
**/ | |
var Greetings = require('./greetings'); | |
var greetings = new Greetings(); | |
console.log(greetings.hello(' Node ')+"!"); |
This file contains 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
/** | |
* Simple module to demonstrate sanitization | |
**/ | |
var Tidy = { | |
whitespace: '\\r\\n\\t\\s', | |
trim: function(str) { | |
var whitespace = '\\r\\n\\t\\s'; | |
str = str.replace(new RegExp('^['+this.whitespace+']+|['+this.whitespace+']+$', 'g'), '') | |
return str; | |
} | |
} | |
module.exports = Tidy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment