Skip to content
This repository
Newer
Older
100644 275 lines (196 sloc) 7.305 kb
310fcb93 »
2010-08-08 Updated README, simplified title.
1 ## Geddy web framework for Node.js
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
2 - - -
3
4 ### Goals
5
1fc7dbf8 »
2010-06-24 Simplfied goals in README.
6 * Easy to use
7 * Modular
8 * Fast
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
9
10 Geddy should make things easy for the most basic applications,
11 but still let you get under the hood and tinker if you want.
12
13 ### Features
14
15 * Powerful, flexible router
16 * Easy resource-based routing
17 * App and resource generators
18 * Content-negotiation
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
19 * Session support (in-memory, cookie, CouchDB)
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
20 * Templating (EJS), partials support
21 * Fully non-blocking
22
23 ### License
24
25 Apache License, Version 2
26
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
27 ### Prerequisites
3b12a23d »
2010-05-03 Added mailing list info.
28
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
29 Geddy requires version 0.4.x or higher of Node.js, and the
30 [Jake](https://github.com/mde/jake) JavaScript build-tool.
3b2b7c6b »
2010-05-03 Added mailing list and IRC info.
31
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
32 ### Installing
fa6a6ec7 »
2010-04-06 Added note about prereqs and building.
33
34 To get Geddy from GitHub and install it:
35
36 git clone git://github.com/mde/geddy.git
37 cd geddy
38 make && sudo make install
39
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
40 ### Routes
41
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
42 Routes are similar to Merb or Rails routes.
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
43
44 **Basic routes**
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
45
46 router.match('/moving/pictures/:id').to(
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
47 {controller: 'Moving', action: 'pictures'});
f00e1d5a »
2010-03-30 Proofreading.
48
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
49 router.match('/farewells/:farewelltype/kings/:kingid').to(
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
50 {controller: 'Farewells', action: 'kings'});
f00e1d5a »
2010-03-30 Proofreading.
51
52 //Can also match specific HTTP methods only
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
53 router.match('/xandadu', 'get').to(
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
54 {controller: 'Xandadu', action: 'specialHandler'});
55
56 **Resource-based routes**
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
57
58 router.resource('hemispheres');
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
59
60 ### Creating a Geddy app
61
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
62 You can use Geddy to create an app. Run `geddy app [app-name]` to
63 create an app. Then Run `geddy` inside the app-directory to start
64 the server.
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
65
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
66 mde@localhost:~/work$ geddy app bytor
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
67 Created app bytor.
68 mde@localhost:~/work$ cd bytor
69 mde@localhost:~/work/bytor$ geddy
3b5e098c »
2010-05-11 Changed default port to 4000.
70 Server running at http://127.0.0.1:4000/
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
71
3b5e098c »
2010-05-11 Changed default port to 4000.
72 Go to http://localhost:4000/, and you should see:
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
73
531d4d4b »
2010-04-01 Hacking in basic cookie and session support.
74 Attention all planets of the Solar Federation
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
75
76 ### Adding resources
77
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
78 Use `geddy resource` in your app directory to add a
f00e1d5a »
2010-03-30 Proofreading.
79 resource. The route will be set up automatically for you.
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
80
487669e4 »
2010-05-02 Updated README to describe model stubs and pluralization with geddy-g…
81 mde@localhost:~/work/bytor$ geddy-gen resource snow_dog
82 [ADDED] ./app/models/snow_dog.js
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
83 [ADDED] ./app/controllers/snow_dogs.js
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
84 resources snow_dogs route added to ./config/router.js
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
85 Created view templates.
86
87 Restart Geddy, and you'll see the new route working. Hit your
3b5e098c »
2010-05-11 Changed default port to 4000.
88 new route -- for example, http://localhost:4000/snow_dogs.json,
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
89 and you should see something like this:
90
91 {"method":"index","params":{"extension":"json"}}
92
e0dc47a2 »
2011-11-17 Updated README with 0.2 changes.
93 The geddy generator utility also handles fancy pluralization
94 between model and controller. Specify your resource-name as a
95 singular naun, and the generator will do the right thing --
96 changing 'person' to 'people,' etc.
487669e4 »
2010-05-02 Updated README to describe model stubs and pluralization with geddy-g…
97
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
98 ### App layout
99
100 After adding a resource, a Geddy app is laid out like this:
101
102 mde@localhost:~/work/bytor$ find .
103 .
104 ./config
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
105 ./config/config.js
106 ./config/router.js
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
107 ./app
108 ./app/controllers
109 ./app/controllers/snow_dogs.js
110 ./app/controllers/main.js
111 ./app/controllers/application.js
112 ./app/views
113 ./app/views/snow_dogs
114 ./app/views/snow_dogs/show.html.ejs
115 ./app/views/snow_dogs/add.html.ejs
116 ./app/views/snow_dogs/index.html.ejs
117 ./public
118
119 ### Resources and controllers
120
121 Geddy's resource-based routes create url/request-method mappings
122 for easy CRUD operations like this:
123
f9185418 »
2010-05-04 No really, update the README with the extension stuff.
124 GET */snow_dogs[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
125 (SnowDogs controller, index action)
126
f9185418 »
2010-05-04 No really, update the README with the extension stuff.
127 GET */snow_dogs/add[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
128 (SnowDogs controller, add action, for any new-resource template
129 -- "new" is not usable as a JavaScript action name)
130
b563a1c8 »
2010-05-04 Make the doc regarding RESTful routes clearly include the file extens…
131 POST */snow_dogs[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
132 (SnowDogs controller, create action)
133
b563a1c8 »
2010-05-04 Make the doc regarding RESTful routes clearly include the file extens…
134 GET */snow_dogs/:id[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
135 (SnowDogs controller, show action)
136
b5d810c7 »
2010-06-05 Bumped Node version number, removed semicolon hack for edit path in r…
137 GET */snow_dogs/:id/edit[.extension]<br/>
2b96485f »
2010-05-05 Added support for create/update routing, for _method param override.
138 (SnowDogs controller, edit action)
139
b563a1c8 »
2010-05-04 Make the doc regarding RESTful routes clearly include the file extens…
140 PUT */snow_dogs/:id[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
141 (SnowDogs controller, update action)
142
b563a1c8 »
2010-05-04 Make the doc regarding RESTful routes clearly include the file extens…
143 DELETE */snow_dogs/:id[.extension]<br/>
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
144 (SnowDogs controller, remove action)
145
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
146 A simple controller that just responds with any
147 form-post/query-string params looks like this:
148
149 var SnowDogs = function () {
150 this.respondsWith = ['text', 'json', 'html'];
151
152 this.index = function (params) {
153 this.respond({params: params});
154 };
155
156 this.add = function (params) {
157 this.respond({params: params});
158 };
159
160 this.create = function (params) {
161 this.respond({params: params});
162 };
163
164 this.show = function (params) {
165 this.respond({params: params});
166 };
167
168 this.update = function (params) {
169 this.respond({params: params});
170 };
171
172 this.remove = function (params) {
173 this.respond({params: params});
174 };
175
176 };
177
178 exports.SnowDogs = SnowDogs;
179
180
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
181 ## Content-negotiation
182
a0f33a20 »
2011-11-17 README updates.
183 Geddy can perform content-negotiation, and respond with with the
184 correct format based on the requested filename-extension.
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
185
a0f33a20 »
2011-11-17 README updates.
186 If you have a JSON-serializable JavaScript object you want to
187 return in JSON format, pass your JavaScript object to the
4e858348 »
2010-03-30 More info about resource routes, content-negotiation.
188 `respond` method in the action on that controller.
189
190 this.respondsWith = ['text', 'json'];
191
192 this.show = function (params) {
193 // (Fetch some item by params.id)
194 item = {foo: 'FOO', bar: 1, baz: false};
195 this.respond(item);
196 };
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
197
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
198 ## Models and validations
199
a0f33a20 »
2011-11-17 README updates.
200 Geddy has a simple way of defining models, with a full-featured
201 set of data validations. The syntax is very similar to models in
202 Ruby's ActiveRecord or DataMapper.
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
203
204 Here is an example of a model with some validations:
205
206 var User = function () {
7f15377c »
2010-05-22 Updated docs, tests, template to use new lowercase names for datatypes.
207 this.property('login', 'string', {required: true});
208 this.property('password', 'string', {required: true});
209 this.property('lastName', 'string');
210 this.property('firstName', 'string');
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
211
212 this.validatesPresent('login');
213 this.validatesFormat('login', /[a-z]+/, {message: 'Subdivisions!'});
214 this.validatesLength('login', {min: 3});
215 this.validatesConfirmed('password', 'confirmPassword');
4df79a59 »
2010-06-16 Fixed overzealous search-and-replace.
216 this.validatesWithFunction('password', function (s) {
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
217 // Something that returns true or false
218 return s.length > 0;
219 });
220
221 // Can define methods for instances like this
222 this.someMethod = function () {
223 // Do some stuff
224 };
225 };
226
227 // Can also define them on the prototype
228 User.prototype.someOtherMethod = function () {
229 // Do some other stuff
230 };
231
4aefaa9d »
2011-11-18 Load up models on app-startup.
232 User = geddy.model.registerModel('User', User);
2c7a18d8 »
2010-04-24 Updated with info about controllers and models/validations.
233
234 Creating an instance of one of these models is easy:
235
236 var params = {
237 login: 'alex',
238 password: 'lerxst',
239 lastName: 'Lifeson',
240 firstName: 'Alex'
241 };
242 var user = User.create(params);
243
244 Data-validation happens on the call to `create`, and any
245 validation errors show up inside an `errors` property on
246 the instance, keyed by field name. Instances have a `valid`
247 method that returns a Boolean indicating whether the instance
248 is valid.
249
250 // Leaving out the required password field
251 var params = {
252 login: 'alex',
253 };
254 var user = User.create(params);
255
256 // Prints 'false'
257 sys.puts(user.valid());
258 // Prints 'Field "password" is required'
259 sys.puts(user.errors.password);
260
3fd1410a »
2011-11-24 Update README with info on running tests.
261 ## Running the tests
262
263 In the geddy project directory, run `jake test`. The tests simply
1c07cece »
2011-11-24 Restored model-tests.
264 use NodeJS's `assert` library, which throws an error on failure.
3fd1410a »
2011-11-24 Update README with info on running tests.
265 If there are no errors, the tests all ran successfully.
266
5e5438c2 »
2011-11-17 Added API docs link to README.
267 ## API Docs
268
269 API docs [can be found here](http://mde.github.com/geddy/doc/).
270
88b6bb09 »
2010-03-30 Updated README with overview info and markdown formatting.
271 - - -
272 Geddy Web-app development framework copyright 2112
273 mde@fleegix.org.
274
Something went wrong with that request. Please try again.