Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (82 sloc) 4.611 kb
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
1 Grasshopper
2 ==========
75da031 Chandra Sekar S Initial check-in.
authored
3
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
4 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.
77fc38f Chandra Sekar S Updated license terms.
authored
5
6 This framework is licensed under the terms of [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
75da031 Chandra Sekar S Initial check-in.
authored
7
efeac49 Chandra Sekar S Prepared for 0.1.0 release.
authored
8 Features
9 --------
10
11 * Integrated support for dependency injection.
12 * Filters for intercepting requests.
9c5cb35 Chandra Sekar S Prepared for 0.2.0.
authored
13 * Supports i18n out of the box.
14 * Handles updation and validation of models from forms.
5ff1723 Chandra Sekar S Updated README.
authored
15 * Supports on the fly Gzip compression of responses.
16 * Static files can also be pre-compressed to save compression on each request.
d752821 Chandra Sekar S Support for flash messages.
authored
17 * Supports flash messages.
18 * Allows adding view helpers to enable smarter views.
efeac49 Chandra Sekar S Prepared for 0.1.0 release.
authored
19 * Layout and "include" support for views.
20 * Automatic selection of view file based on request's extension.
c198954 Chandra Sekar S Updated README.
authored
21 * Support for HTTPS with automatic redirection.
8b7d689 Chandra Sekar S Updated README.
authored
22 * Supports Basic and Digest authentication.
efeac49 Chandra Sekar S Prepared for 0.1.0 release.
authored
23 * Session management with support for custom session storage.
24 * Simple API to create and consume cookies.
25 * Fast file uploads using [node-formidable](http://github.com/felixge/node-formidable).
f49ecc1 Chandra Sekar S Updated README.
authored
26 * Configurable form post and upload sizes.
efeac49 Chandra Sekar S Prepared for 0.1.0 release.
authored
27 * Makes sending files as response attachments using 'Content-Disposition' simple.
28 * Supports partial download of static files.
16b50c2 Chandra Sekar S Updated README.
authored
29 * Supports `if-modified-since`, `if-none-match` and `if-range` headers.
efeac49 Chandra Sekar S Prepared for 0.1.0 release.
authored
30 * Plenty of documentation through [examples](http://github.com/tuxychandru/grasshopper/tree/master/examples/) (Wiki will be updated with more tutorials).
31
75da031 Chandra Sekar S Initial check-in.
authored
32 Hello World
33 -----------
34
97347e3 Chandra Sekar S Removed sudo from npm commands.
authored
35 1. [Install npm](http://github.com/isaacs/npm#readme).
36 2. Install grasshopper - `npm install grasshopper`.
391f50c Chandra Sekar S Added npm configuration.
authored
37 3. Create a directory for your application.
38 4. Create a file named `hello.js` in your application's directory with the following content.
75da031 Chandra Sekar S Initial check-in.
authored
39
391f50c Chandra Sekar S Added npm configuration.
authored
40 var gh = require('grasshopper');
ba3edd1 Chandra Sekar S Added methods for defining HTTP method instead using string prefix.
authored
41
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
42 gh.get('/', function() {
ba3edd1 Chandra Sekar S Added methods for defining HTTP method instead using string prefix.
authored
43 this.renderText('Hello World!');
44 });
75da031 Chandra Sekar S Initial check-in.
authored
45
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
46 gh.serve(8080);
75da031 Chandra Sekar S Initial check-in.
authored
47
391f50c Chandra Sekar S Added npm configuration.
authored
48 5. From your applications directory invoke the command `node hello.js`.
49 6. Point your browser at http://localhost:8080.
75da031 Chandra Sekar S Initial check-in.
authored
50
51 Arguments in URL and Template Files
52 -----------------------------------
53
54 Arguments passed as part of the URL can be obtained with an additional parameter in the controller function, to which a hash of arguments defined between `{}` in your route and their values would be passed.
55
0506c83 Chandra Sekar S Implemented a more flexible template engine.
authored
56 **********
278f4cc Chandra Sekar S Added support for view helpers and inclusion of other templates.
authored
57 ### Template File Format (GHP - GrassHopper Pages)
0506c83 Chandra Sekar S Implemented a more flexible template engine.
authored
58
59 1. Text inside `<% and %>` are evaluated as Javacript code.
5ff1723 Chandra Sekar S Updated README.
authored
60 2. Text inside `<%= and %>` are evaluated as Javascript code and its result is included into the output after escaping HTML.
61 3. Text inside `<%h and %>` are evaluated as Javascript code and its result is included into the output without any modification.
0506c83 Chandra Sekar S Implemented a more flexible template engine.
authored
62 ***********
63
75da031 Chandra Sekar S Initial check-in.
authored
64 1. Create a file named `greeting.html` in your application's directory with the following content. This would act as your template file.
65
66 <html>
67 <head>
68 <title>Template Sample</title>
69 </head>
70 <body>
0506c83 Chandra Sekar S Implemented a more flexible template engine.
authored
71 <h1>Welcome, <%= name %>!</h1>
75da031 Chandra Sekar S Initial check-in.
authored
72 </body>
73 </html>
74
06ab16a Chandra Sekar S Moved model into the request context.
authored
75 2. Create a file named `template.js` in your application's directory with the following content. The 'model' property of 'this' must be setup with the data items used in the template. The `render` function must be invoked with the name of a template file (without extension). The extension of the template file to use is determined by the extention of the request URL (`.html`, if none specified).
75da031 Chandra Sekar S Initial check-in.
authored
76
391f50c Chandra Sekar S Added npm configuration.
authored
77 var gh = require('grasshopper');
75da031 Chandra Sekar S Initial check-in.
authored
78
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
79 gh.get('/greetings/{name}', function(args) {
06ab16a Chandra Sekar S Moved model into the request context.
authored
80 this.model['name'] = args.name;
81 this.render('greeting');
ba3edd1 Chandra Sekar S Added methods for defining HTTP method instead using string prefix.
authored
82 });
83
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
84 gh.serve(8080);
75da031 Chandra Sekar S Initial check-in.
authored
85
86 4. From your applications directory invoke the command `node template.js`.
87 5. Point your browser at http://localhost:8080/greetings/ABC.
4cc2835 Chandra Sekar S Added note on missing features in README.
authored
88
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
89 Dependency Injection
90 --------------------
91
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
92 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,
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
93
391f50c Chandra Sekar S Added npm configuration.
authored
94 var gh = require('grasshopper');
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
95
96 var dependencies = {
97 dataService: {
98 getStock: function() {
99 return 100;
100 }
101 }
ba3edd1 Chandra Sekar S Added methods for defining HTTP method instead using string prefix.
authored
102 };
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
103 gh.addToContext(dependencies);
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
104
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
105 gh.get('/', function() {
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
106 this.renderText('There are ' + this.dataService.getStock() + ' units in stock!');
ba3edd1 Chandra Sekar S Added methods for defining HTTP method instead using string prefix.
authored
107 });
b688736 Chandra Sekar S Added support for injecting dependencies into the this context of contro...
authored
108
6bd67d9 Chandra Sekar S Renamed project to grasshopper.
authored
109 gh.serve(8080);
Something went wrong with that request. Please try again.