Skip to content

Commit

Permalink
Renamed project to grasshopper.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Jul 8, 2010
1 parent 77fc38f commit 6bd67d9
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
32 changes: 16 additions & 16 deletions README.md
@@ -1,26 +1,26 @@
MVC.js
======
Grasshopper
==========

A simple MVC framework for web applications built on [node.JS](http://nodejs.org/). Follow the [instructions to install node.JS](http://nodejs.org/#download). Join the [mailing list](http://groups.google.com/group/mvcjs) for further help and feedback.
A simple MVC framework for web applications built on [node.JS](http://nodejs.org/). Follow the [instructions to install node.JS](http://nodejs.org/#download). Join the [mailing list](http://groups.google.com/group/grasshopperjs) for further help and feedback.

This framework is licensed under the terms of [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

Hello World
-----------

1. Clone the repository using `git clone git://github.com/tuxychandru/mvc.js.git`.
2. Create a directory for your application and copy the `lib` directory from the cloned repository to it.
1. Clone the repository using `git clone git://github.com/tuxychandru/grasshopper.git`.
2. Create a directory for your application and copy or symlink the `lib` directory from the cloned repository to it.
3. Create a file named `hello.js` in your application's directory with the following content.

require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/', function() {
gh.get('/', function() {
this.renderText('Hello World!');
});

mvc.serve(8080);
gh.serve(8080);

4. From your applications directory invoke the command `node hello.js`.
5. Point your browser at http://localhost:8080.
Expand Down Expand Up @@ -52,26 +52,26 @@ Arguments passed as part of the URL can be obtained with an additional parameter

require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/greetings/{name}', function(args) {
gh.get('/greetings/{name}', function(args) {
this.model['name'] = args.name;
this.render('greeting');
});

mvc.serve(8080);
gh.serve(8080);

4. From your applications directory invoke the command `node template.js`.
5. Point your browser at http://localhost:8080/greetings/ABC.

Dependency Injection
--------------------

Hashes containing the necessary dependencies can be added to the `this` context of your controller functions, using the `mvc.addToContext()` function. You can either specify all the hashes to be included in a single invocation or in multiple invocations. For example,
Hashes containing the necessary dependencies can be added to the `this` context of your controller functions, using the `gh.addToContext()` function. You can either specify all the hashes to be included in a single invocation or in multiple invocations. For example,

require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

var dependencies = {
dataService: {
Expand All @@ -80,13 +80,13 @@ Hashes containing the necessary dependencies can be added to the `this` context
}
}
};
mvc.addToContext(dependencies);
gh.addToContext(dependencies);

mvc.get('/', function() {
gh.get('/', function() {
this.renderText('There are ' + this.dataService.getStock() + ' units in stock!');
});

mvc.serve(8080);
gh.serve(8080);

To Do
-----
Expand Down
18 changes: 9 additions & 9 deletions examples/REST/cities.js
@@ -1,6 +1,6 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');
var renderer = require('renderer');

function InMemoryCityProvider() {
Expand Down Expand Up @@ -34,15 +34,15 @@ function InMemoryCityProvider() {
}
}

mvc.get('/', function() {
gh.get('/', function() {
this.redirect('/cities');
});

mvc.get('/cities', function() {
gh.get('/cities', function() {
this.renderText(JSON.stringify({cities: this.cityProvider.findAll()}));
});

mvc.get('/cities/{id}', function(args) {
gh.get('/cities/{id}', function(args) {
var city = this.cityProvider.findById(args.id);

if(city) {
Expand All @@ -52,7 +52,7 @@ mvc.get('/cities/{id}', function(args) {
}
});

mvc.post('/cities', function() {
gh.post('/cities', function() {
var city = {
name: this.params.name,
population: this.params.population
Expand All @@ -63,7 +63,7 @@ mvc.post('/cities', function() {
this.renderText(JSON.stringify(city));
});

mvc.put('/cities/{id}', function(args) {
gh.put('/cities/{id}', function(args) {
var city = this.cityProvider.findById(args.id);
if(city) {
city.name = this.params.name;
Expand All @@ -77,7 +77,7 @@ mvc.put('/cities/{id}', function(args) {
}
});

mvc.del('/cities/{id}', function(args) {
gh.del('/cities/{id}', function(args) {
var city = this.cityProvider.findById(args.id);
if(city) {
this.cityProvider.remove(city);
Expand All @@ -93,5 +93,5 @@ renderer.configure({
defaultViewExtn: 'json'
});

mvc.addToContext({cityProvider: new InMemoryCityProvider()});
mvc.serve(8080);
gh.addToContext({cityProvider: new InMemoryCityProvider()});
gh.serve(8080);
10 changes: 5 additions & 5 deletions examples/cookies/cookies.js
@@ -1,15 +1,15 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/', function() {
gh.get('/', function() {
this.model['cookies'] = this.requestCookies;
this.render('index');
});

mvc.post('/set_cookie', function() {
this.addCookie(new mvc.Cookie(this.params['name'], this.params['value']));
gh.post('/set_cookie', function() {
this.addCookie(new gh.Cookie(this.params['name'], this.params['value']));
this.redirect('/');
});

mvc.serve(8080);
gh.serve(8080);
8 changes: 4 additions & 4 deletions examples/di/di.js
@@ -1,6 +1,6 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

var dependencies = {
dataService: {
Expand All @@ -9,11 +9,11 @@ var dependencies = {
}
}
};
mvc.addToContext(dependencies);
gh.addToContext(dependencies);

mvc.get('/', function() {
gh.get('/', function() {
this.renderText('There are ' + this.dataService.getStock() + ' units in stock!');
});

mvc.serve(8080);
gh.serve(8080);

14 changes: 7 additions & 7 deletions examples/filter/filter.js
@@ -1,8 +1,8 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.addFilters(/\/secure/, function(nextFilter) {
gh.addFilters(/\/secure/, function(nextFilter) {
var self = this;
this.getSessionValue('user', function(err, user) {
if(!err && user) {
Expand All @@ -13,7 +13,7 @@ mvc.addFilters(/\/secure/, function(nextFilter) {
});
});

mvc.get('/secure_welcome', function() {
gh.get('/secure_welcome', function() {
this.disableCache();
var self = this;
this.getSessionValue('user', function(err, user) {
Expand All @@ -22,7 +22,7 @@ mvc.get('/secure_welcome', function() {
});
});

mvc.get('/', function() {
gh.get('/', function() {
this.disableCache();
var self = this;
this.getSessionValue('user', function(err, user) {
Expand All @@ -34,18 +34,18 @@ mvc.get('/', function() {
});
});

mvc.post('/login', function() {
gh.post('/login', function() {
var self = this;
this.setSessionValue('user', this.params['name'], function() {
self.redirect('/');
});
});

mvc.get('/logout', function() {
gh.get('/logout', function() {
var self = this;
this.endSession(function() {
self.redirect('/');
});
});

mvc.serve(8080);
gh.serve(8080);
6 changes: 3 additions & 3 deletions examples/hello_world/hello.js
@@ -1,9 +1,9 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/', function() {
gh.get('/', function() {
this.renderText('Hello World!');
});

mvc.serve(8080);
gh.serve(8080);
10 changes: 5 additions & 5 deletions examples/session/login.js
@@ -1,8 +1,8 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/', function() {
gh.get('/', function() {
var self = this;
this.getSessionValue('user', function(err, user) {
self.disableCache();
Expand All @@ -15,18 +15,18 @@ mvc.get('/', function() {
});
});

mvc.post('/login', function() {
gh.post('/login', function() {
var self = this;
this.setSessionValue('user', this.params['name'], function() {
self.redirect('/');
});
});

mvc.get('/logout', function() {
gh.get('/logout', function() {
var self = this;
this.endSession(function() {
self.redirect('/');
});
});

mvc.serve(8080);
gh.serve(8080);
6 changes: 3 additions & 3 deletions examples/url_arg_template/template.js
@@ -1,10 +1,10 @@
require.paths.unshift('./lib');

var mvc = require('mvc');
var gh = require('grasshopper');

mvc.get('/greetings/{name}', function(args) {
gh.get('/greetings/{name}', function(args) {
this.model['name'] = args.name;
this.render('greeting');
});

mvc.serve(8080);
gh.serve(8080);
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/mvc.js → lib/grasshopper.js
Expand Up @@ -65,7 +65,7 @@ exports.serve = function(port) {
});

server.listen(port);
console.log('Server running at http://127.0.0.1:' + port + '/');
console.log('Hopping at http://127.0.0.1:' + port + '/. Use Ctrl+C to stop.');
}

// Class: Cookie
Expand Down
8 changes: 4 additions & 4 deletions lib/renderer.js
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var template = require('./mvcTemplate'),
var template = require('./ghTemplate'),
mime = require('./mime'),
uuid = require('./uuid'),
session = require('./session'),
mvc = require('./mvc'),
gh = require('./grasshopper'),
fs = require('fs'),
url = require('url'),
crypto = require('crypto');
Expand Down Expand Up @@ -68,7 +68,7 @@ function RequestContext(request, response, params) {
var cookies = cookieLine.split('; ');
for(var i = 0; i < cookies.length; i++) {
var cookieParts = cookies[i].split('=');
if(cookieParts[0] == 'MVCSESSION') {
if(cookieParts[0] == 'GHSESSION') {
this.sessionId = decodeURIComponent(cookieParts[1]);
} else {
this.requestCookies[cookieParts[0]] = decodeURIComponent(cookieParts[1]);
Expand Down Expand Up @@ -221,7 +221,7 @@ RequestContext.prototype.beginSession = function(callback) {
session.getSessionStore().beginSession(sessionId, function(err) {
if(!err) {
this.sessionId = sessionId;
self.addCookie(new mvc.Cookie('MVCSESSION', sessionId));
self.addCookie(new gh.Cookie('GHSESSION', sessionId));
}
callback(err);
});
Expand Down

0 comments on commit 6bd67d9

Please sign in to comment.