Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' into serverportfailure

  • Loading branch information...
commit 7f93697608fba239ae1fe2f598bbfeaa6019c0bb 2 parents e2f0753 + 8b543db
Miguel Madero authored

Showing 185 changed files with 24,752 additions and 212 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +33 12 bin/cli.js
  3. +12 0 changelog.md
  4. +5 2 deps/templato/lib/engines/ejs.js
  5. +5 2 deps/templato/lib/engines/handlebars.js
  6. +5 2 deps/templato/lib/engines/jade.js
  7. +4 2 deps/templato/lib/engines/mustache.js
  8. +72 0 docs/1-architecture.md
  9. +110 0 docs/2-router.md
  10. +208 0 docs/3-controllers.md
  11. +422 0 docs/4-models.md
  12. +317 0 docs/5-templates.md
  13. +83 0 docs/6-CLI.md
  14. +3 3 examples/todo_app/app/controllers/todos.js
  15. +1 5 examples/todo_app/config/init.js
  16. +0 60 examples/todo_app/lib/model_adapters/todo.js
  17. +6 14 examples/todo_app_coffee/app/controllers/todos.coffee
  18. +0 5 examples/todo_app_coffee/app/models/todo.coffee
  19. +3 6 examples/todo_app_coffee/config/development.coffee
  20. +15 0 examples/todo_app_coffee/config/development.coffee.mongo
  21. +0 5 examples/todo_app_coffee/config/init.coffee
  22. +1 1  lib/app.js
  23. +1 1  lib/config.js
  24. +0 31 lib/i18n/index.js
  25. +3 5 lib/init/i18n.js
  26. 0  {site → site-old}/css/bootstrap.css
  27. 0  {site → site-old}/css/bootstrap.min.css
  28. 0  {site → site-old}/css/bootstrap.min.responsive.css
  29. 0  {site → site-old}/css/bootstrap.responsive
  30. 0  {site → site-old}/docs.html
  31. 0  {site → site-old}/features.html
  32. 0  {site → site-old}/img/glyphicons-halflings-white.png
  33. 0  {site → site-old}/img/glyphicons-halflings.png
  34. 0  {site → site-old}/index.html
  35. 0  {site → site-old}/js/bootstrap.js
  36. 0  {site → site-old}/js/bootstrap.min.js
  37. 0  {site → site-old}/js/google-code-prettify/lang-apollo.js
  38. 0  {site → site-old}/js/google-code-prettify/lang-clj.js
  39. 0  {site → site-old}/js/google-code-prettify/lang-css.js
  40. 0  {site → site-old}/js/google-code-prettify/lang-go.js
  41. 0  {site → site-old}/js/google-code-prettify/lang-hs.js
  42. 0  {site → site-old}/js/google-code-prettify/lang-lisp.js
  43. 0  {site → site-old}/js/google-code-prettify/lang-lua.js
  44. 0  {site → site-old}/js/google-code-prettify/lang-ml.js
  45. 0  {site → site-old}/js/google-code-prettify/lang-n.js
  46. 0  {site → site-old}/js/google-code-prettify/lang-proto.js
  47. 0  {site → site-old}/js/google-code-prettify/lang-scala.js
  48. 0  {site → site-old}/js/google-code-prettify/lang-sql.js
  49. 0  {site → site-old}/js/google-code-prettify/lang-tex.js
  50. 0  {site → site-old}/js/google-code-prettify/lang-vb.js
  51. 0  {site → site-old}/js/google-code-prettify/lang-vhdl.js
  52. 0  {site → site-old}/js/google-code-prettify/lang-wiki.js
  53. 0  {site → site-old}/js/google-code-prettify/lang-xq.js
  54. 0  {site → site-old}/js/google-code-prettify/lang-yaml.js
  55. 0  {site → site-old}/js/google-code-prettify/prettify.css
  56. 0  {site → site-old}/js/google-code-prettify/prettify.js
  57. 0  {site → site-old}/tutorial.html
  58. +25 0 site/app/controllers/application.js
  59. +211 0 site/app/controllers/main.js
  60. +68 0 site/app/views/layouts/application.html.jade
  61. +13 0 site/app/views/main/changelog.html.jade
  62. +54 0 site/app/views/main/community.html.jade
  63. +19 0 site/app/views/main/documentation.html.jade
  64. +38 0 site/app/views/main/faq.html.jade
  65. +3 0  site/app/views/main/index.html.jade
  66. +11 0 site/app/views/main/tutorial.html.jade
  67. +31 0 site/config/development.js
  68. +9 0 site/config/environment.js
  69. +15 0 site/config/init.js
  70. +32 0 site/config/production.js
  71. +29 0 site/config/router.js
  72. +1 0  site/node_modules/.bin/jade
  73. +1 0  site/node_modules/.bin/marked
  74. +14 0 site/node_modules/jade/.npmignore
  75. +22 0 site/node_modules/jade/LICENSE
  76. +1,299 0 site/node_modules/jade/Readme.md
  77. +168 0 site/node_modules/jade/bin/jade
  78. +4 0 site/node_modules/jade/index.js
  79. +3,586 0 site/node_modules/jade/jade.js
  80. +510 0 site/node_modules/jade/jade.md
  81. +2 0  site/node_modules/jade/jade.min.js
  82. +654 0 site/node_modules/jade/lib/compiler.js
  83. +18 0 site/node_modules/jade/lib/doctypes.js
  84. +97 0 site/node_modules/jade/lib/filters.js
  85. +28 0 site/node_modules/jade/lib/inline-tags.js
  86. +253 0 site/node_modules/jade/lib/jade.js
  87. +774 0 site/node_modules/jade/lib/lexer.js
  88. +77 0 site/node_modules/jade/lib/nodes/attrs.js
  89. +33 0 site/node_modules/jade/lib/nodes/block-comment.js
  90. +122 0 site/node_modules/jade/lib/nodes/block.js
  91. +43 0 site/node_modules/jade/lib/nodes/case.js
  92. +35 0 site/node_modules/jade/lib/nodes/code.js
  93. +32 0 site/node_modules/jade/lib/nodes/comment.js
  94. +29 0 site/node_modules/jade/lib/nodes/doctype.js
  95. +35 0 site/node_modules/jade/lib/nodes/each.js
  96. +35 0 site/node_modules/jade/lib/nodes/filter.js
  97. +20 0 site/node_modules/jade/lib/nodes/index.js
  98. +32 0 site/node_modules/jade/lib/nodes/literal.js
  99. +36 0 site/node_modules/jade/lib/nodes/mixin.js
  100. +25 0 site/node_modules/jade/lib/nodes/node.js
  101. +95 0 site/node_modules/jade/lib/nodes/tag.js
  102. +36 0 site/node_modules/jade/lib/nodes/text.js
  103. +715 0 site/node_modules/jade/lib/parser.js
  104. +174 0 site/node_modules/jade/lib/runtime.js
  105. +19 0 site/node_modules/jade/lib/self-closing.js
  106. +64 0 site/node_modules/jade/lib/utils.js
  107. +4 0 site/node_modules/jade/node_modules/commander/.npmignore
  108. +4 0 site/node_modules/jade/node_modules/commander/.travis.yml
  109. +107 0 site/node_modules/jade/node_modules/commander/History.md
  110. +7 0 site/node_modules/jade/node_modules/commander/Makefile
  111. +262 0 site/node_modules/jade/node_modules/commander/Readme.md
  112. +2 0  site/node_modules/jade/node_modules/commander/index.js
  113. +1,026 0 site/node_modules/jade/node_modules/commander/lib/commander.js
  114. +34 0 site/node_modules/jade/node_modules/commander/package.json
  115. +2 0  site/node_modules/jade/node_modules/mkdirp/.npmignore
  116. +4 0 site/node_modules/jade/node_modules/mkdirp/.travis.yml
  117. +21 0 site/node_modules/jade/node_modules/mkdirp/LICENSE
  118. +61 0 site/node_modules/jade/node_modules/mkdirp/README.markdown
  119. +6 0 site/node_modules/jade/node_modules/mkdirp/examples/pow.js
  120. +82 0 site/node_modules/jade/node_modules/mkdirp/index.js
  121. +32 0 site/node_modules/jade/node_modules/mkdirp/package.json
  122. +38 0 site/node_modules/jade/node_modules/mkdirp/test/chmod.js
  123. +37 0 site/node_modules/jade/node_modules/mkdirp/test/clobber.js
  124. +28 0 site/node_modules/jade/node_modules/mkdirp/test/mkdirp.js
  125. +32 0 site/node_modules/jade/node_modules/mkdirp/test/perm.js
  126. +39 0 site/node_modules/jade/node_modules/mkdirp/test/perm_sync.js
  127. +41 0 site/node_modules/jade/node_modules/mkdirp/test/race.js
  128. +32 0 site/node_modules/jade/node_modules/mkdirp/test/rel.js
  129. +25 0 site/node_modules/jade/node_modules/mkdirp/test/return.js
  130. +24 0 site/node_modules/jade/node_modules/mkdirp/test/return_sync.js
  131. +18 0 site/node_modules/jade/node_modules/mkdirp/test/root.js
  132. +32 0 site/node_modules/jade/node_modules/mkdirp/test/sync.js
  133. +28 0 site/node_modules/jade/node_modules/mkdirp/test/umask.js
  134. +32 0 site/node_modules/jade/node_modules/mkdirp/test/umask_sync.js
  135. +47 0 site/node_modules/jade/package.json
  136. +179 0 site/node_modules/jade/runtime.js
  137. +1 0  site/node_modules/jade/runtime.min.js
  138. +7 0 site/node_modules/jade/test.jade
  139. +5 0 site/node_modules/jade/testing/head.jade
  140. +1 0  site/node_modules/jade/testing/index.jade
  141. +14 0 site/node_modules/jade/testing/index.js
  142. +10 0 site/node_modules/jade/testing/layout.jade
  143. +7 0 site/node_modules/jade/testing/user.jade
  144. +27 0 site/node_modules/jade/testing/user.js
  145. +2 0  site/node_modules/marked/.npmignore
  146. +19 0 site/node_modules/marked/LICENSE
  147. +9 0 site/node_modules/marked/Makefile
  148. +125 0 site/node_modules/marked/README.md
  149. +127 0 site/node_modules/marked/bin/marked
  150. +1 0  site/node_modules/marked/index.js
  151. +791 0 site/node_modules/marked/lib/marked.js
  152. +49 0 site/node_modules/marked/man/marked.1
  153. +40 0 site/node_modules/marked/package.json
  154. +5,774 0 site/public/css/bootstrap.css
  155. +9 0 site/public/css/bootstrap.min.css
  156. +1,058 0 site/public/css/bootstrap.responsive.css
  157. +9 0 site/public/css/bootstrap.responsive.min.css
  158. +507 0 site/public/css/style.css
  159. BIN  site/public/favicon.ico
  160. BIN  site/public/img/changelog-dark-72.png
  161. BIN  site/public/img/changelog-light-72.png
  162. BIN  site/public/img/community-dark-72.png
  163. BIN  site/public/img/community-light-72.png
  164. BIN  site/public/img/docs-dark-72.png
  165. BIN  site/public/img/docs-light-72.png
  166. BIN  site/public/img/faq-dark-72.png
  167. BIN  site/public/img/faq-light-72.png
  168. BIN  site/public/img/glyphicons-halflings-white.png
  169. BIN  site/public/img/glyphicons-halflings.png
  170. BIN  site/public/img/home-dark-72.png
  171. BIN  site/public/img/home-light-72.png
  172. BIN  site/public/img/tuts-dark-72.png
  173. BIN  site/public/img/tuts-light-72.png
  174. BIN  site/public/img/whitey.png
  175. +2,027 0 site/public/js/bootstrap.js
  176. +6 0 site/public/js/bootstrap.min.js
  177. +2 0  site/public/js/jquery.min.js
  178. +94 0 site/public/js/site.js
  179. +84 47 templates/Jakefile
  180. +6 0 templates/base/Jakefile.ejs
  181. +1 1  templates/base/public/js/jquery.min.js
  182. +3 4 templates/resource/model.ejs
  183. +12 0 templates/resource/test.ejs
  184. +3 4 templates/scaffold/model.ejs
  185. +680 0 tutorial.md
1  .gitignore
@@ -11,6 +11,7 @@ node_modules
11 11 tmtags
12 12 *.DS_Store
13 13 examples/*/log/*
  14 +site/log/*
14 15 .log
15 16 npm-debug.log
16 17 doc/
45 bin/cli.js
@@ -21,6 +21,9 @@ var cwd = process.cwd()
21 21 , filepath
22 22 , die
23 23 , jake
  24 + , jakeArgs
  25 + , jakeProgram
  26 + , jakeLoader
24 27 , start;
25 28
26 29 // Usage dialog
@@ -126,9 +129,11 @@ if (cmds.length) {
126 129 cmd = '';
127 130
128 131 // Some commands take only one arg
129   - if (!(cmds[0] == 'secret' ||
  132 + if (!(cmds[0] == 'jake' ||
  133 + cmds[0] == 'secret' ||
130 134 cmds[0] == 'db:init' ||
131   - cmds[0] == 'console') && !cmds[1]) {
  135 + cmds[0] == 'console')
  136 + && !cmds[1]) {
132 137 throw new Error(cmds[0] + ' command requires another argument.');
133 138 }
134 139
@@ -148,6 +153,10 @@ if (cmds.length) {
148 153
149 154 // Add Jake argument based on commands
150 155 switch (cmds[0]) {
  156 + case 'jake':
  157 + cmd = 'jake';
  158 + jakeArgs = cmds.slice(1);
  159 + break;
151 160 case 'console':
152 161 // Create DBs
153 162 cmd += 'console:start[' + (cmds[1] || 'development') + ']';
@@ -189,13 +198,26 @@ if (cmds.length) {
189 198 }
190 199
191 200 jake = require('jake');
192   - jake.program.init({
193   - quiet: !opts.debug
194   - , trace: true
195   - });
196   - jake.loader.loadFile(filepath);
197   - jake.program.setTaskNames([cmd]);
198   - jake.program.run();
  201 + jakeProgram = jake.program;
  202 + jakeLoader = jake.loader;
  203 + // Load Geddy's bundled Jakefile
  204 + jakeLoader.loadFile(filepath);
  205 + if (cmd == 'jake') {
  206 + jakeProgram.parseArgs(jakeArgs);
  207 + // Load Jakefile and jakelibdir files for app
  208 + jakeLoader.loadFile(jakeProgram.opts.jakefile);
  209 + jakeLoader.loadDirectory(jakeProgram.opts.jakelibdir);
  210 + // Prepend env:init to load Geddy env
  211 + jakeProgram.taskNames.unshift('env:init');
  212 + }
  213 + else {
  214 + jakeProgram.init({
  215 + quiet: !opts.debug
  216 + , trace: true
  217 + });
  218 + jakeProgram.setTaskNames([cmd]);
  219 + }
  220 + jakeProgram.run();
199 221 }
200 222 // Just `geddy` -- start the server
201 223 else {
@@ -204,8 +226,7 @@ else {
204 226 if (err) {
205 227 die(usage);
206 228 }
207   - else {
208   - start();
209   - }
  229 +
  230 + start();
210 231 });
211 232 }
12 changelog.md
Source Rendered
... ... @@ -0,0 +1,12 @@
  1 +### 0.5.0
  2 ++ removed models from geddy core
  3 ++ removed utilities from geddy core
  4 ++ removed router from geddy core
  5 ++ added [model](https://github.com/mde/model) as a dependency
  6 ++ added [utilities](https://github.com/mde/utilities) as a dependency
  7 ++ added [barista](https://github.com/kieran/barista) as a dependency
  8 ++ added the `geddy console` command
  9 ++ added the `geddy exec` command
  10 ++ added a ton of tests
  11 ++ a ton of minor bug fixes
  12 ++ created a new website
7 deps/templato/lib/engines/ejs.js
... ... @@ -1,8 +1,11 @@
1   -var TemplatoEJS = (function() {
  1 +var path = require('path')
  2 + , TemplatoEJS;
  3 +
  4 +TemplatoEJS = (function() {
2 5
3 6 function TemplatoEJS() {
4 7 try {
5   - this.engine = this.engine || require('ejs');
  8 + this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'ejs'));
6 9 } catch(err) {
7 10 throw "To use EJS you will need to install it: [sudo] npm install [-g] ejs";
8 11 }
7 deps/templato/lib/engines/handlebars.js
... ... @@ -1,8 +1,11 @@
1   -var TemplatoHandlebars = (function() {
  1 +var path = require('path')
  2 + , TemplatoHandlebars;
  3 +
  4 +TemplatoHandlebars = (function() {
2 5
3 6 function TemplatoHandlebars() {
4 7 try {
5   - this.engine = this.engine || require('handlebars');
  8 + this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'handlebars'));
6 9 } catch(err) {
7 10 throw "To use Handlebars you will need to install it: [sudo] npm install [-g] handlebars";
8 11 }
7 deps/templato/lib/engines/jade.js
... ... @@ -1,8 +1,11 @@
1   -var TemplatoJade = (function() {
  1 +var path = require('path')
  2 + , TemplatoJade;
  3 +
  4 +TemplatoJade = (function() {
2 5
3 6 function TemplatoJade() {
4 7 try {
5   - this.engine = this.engine || require('jade');
  8 + this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'jade'));
6 9 } catch(err) {
7 10 throw "To use Jade you will need to install it: [sudo] npm install [-g] jade";
8 11 }
6 deps/templato/lib/engines/mustache.js
... ... @@ -1,10 +1,12 @@
1 1 require('../../color');
  2 +var path = require('path')
  3 + , TemplatoMustache;
2 4
3   -var TemplatoMustache = (function() {
  5 +TemplatoMustache = (function() {
4 6
5 7 function TemplatoMustache() {
6 8 try {
7   - this.engine = this.engine || require('handlebars');
  9 + this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'mustache'));
8 10 } catch(err) {
9 11 throw [
10 12 "To use Handlebars you will need to install it: [sudo] npm install [-g] handlebars"
72 docs/1-architecture.md
Source Rendered
... ... @@ -0,0 +1,72 @@
  1 +Geddy is built on the same MVC principles that many popular frameworks are based on. Every Geddy app has it's models, controllers, and views as well as config files and routes.
  2 +
  3 +* * *
  4 +
  5 +#### structure
  6 +
  7 +```
  8 +├── app
  9 +│   ├── controllers
  10 +│   │   ├── application.js
  11 +│   │   └── main.js
  12 +│   ├── helpers
  13 +│   ├── models
  14 +│   └── views
  15 +│   ├── layouts
  16 +│   │   └── application.html.jade
  17 +│   └── main
  18 +│   └── index.html.jade
  19 +├── config
  20 + ├── development.js
  21 + ├── environment.js
  22 + ├── init.js
  23 + ├── production.js
  24 + └── router.js
  25 +├── lib
  26 +├── log
  27 +├── node_modules
  28 +└── public
  29 +```
  30 +
  31 +* * *
  32 +
  33 +#### config
  34 +`geddy.config`
  35 +
  36 +Geddy has built in configuration management. Global config options should go in your ‘config/environments.js` file. Likewise, your production and development config options should go in their respective files
  37 +
  38 +If you want to start up your app in a specific environment, use the `-e` option:
  39 +
  40 +```
  41 +$ geddy -e production
  42 +```
  43 +
  44 +* * *
  45 +
  46 +#### logger
  47 +`geddy.log[level]`
  48 +
  49 +Geddy automatically logs requests to an access log, and you can log anything you'd like to stdout or a file. It supports 9 different log levels from debug to emergency.
  50 +
  51 +##### levels
  52 +- `access`: outputs to the access log and stdout
  53 +- `debug`: debug level logging
  54 +- `info`: info level logging
  55 +- `notice`: notice level logging
  56 +- `warning`: warning level logging
  57 +- `error`: error level logging, prints to stdout and stderr
  58 +- `critical`: critical level logging
  59 +- `alert`: alert level logging
  60 +- `emergency`: emergency level logging
  61 +
  62 +##### examples
  63 +```
  64 +geddy.log.debug(‘someting to debug`)
  65 +// prints `something to debug` to the console
  66 +
  67 +
  68 +geddy.log.error(‘something went wrong’)
  69 +// prints ‘something went wrong’ to stderr and the console
  70 +```
  71 +
  72 +* * *
110 docs/2-router.md
Source Rendered
... ... @@ -0,0 +1,110 @@
  1 +Geddy uses [Barista](http://github.com/kieran/barista) as it's router. Its API is very similar to rails routes. Both general purpose resource based routes and individually defined routes are possible.
  2 +
  3 +* * *
  4 +
  5 +#### .match
  6 +`router.match( path [, method] )`
  7 +
  8 +defines the url to match to a controller action.
  9 +
  10 +##### path
  11 +- `path [string]`: the url to match to an action
  12 +
  13 +##### method
  14 +- `method [string]`: the http method to match
  15 +
  16 +##### examples
  17 +```
  18 +router.match(‘/‘).to(‘Main.index’);
  19 +// will route any request to ‘/‘ to the Main controller’s index action
  20 +
  21 +
  22 +router.match( '/products/:id', 'GET' ).to( 'products.show' )
  23 +// will route ‘/products/5’ to Products.show()
  24 +// and set the id paramer to be 5
  25 +
  26 +
  27 +router.match( '/profiles/:username', 'GET' ).to( 'users.show' )
  28 +// will route ‘/products/dan’ to Users.show()
  29 +// and set the username paramer to be dan
  30 +
  31 +
  32 +router.match( '/products/:id(.:format)', 'GET' ).to( 'products.show' )
  33 +// things enclosed in parentheses are optional
  34 +```
  35 +
  36 +* * *
  37 +
  38 +#### .to
  39 +`router.match( path ).to( action )`
  40 +
  41 +defines the action to map the path to.
  42 +
  43 +##### action
  44 +- `action [string]`: a controller name plus an action name as a string
  45 +- `action [object]`: an object that defines a controller and action property
  46 +
  47 +##### examples
  48 +```
  49 +router.match(‘/‘).to(‘Main.index’);
  50 +// will route any request to ‘/‘ to the Main controller’s index action
  51 +
  52 +
  53 +router.match(‘/‘).to({controller: ‘Main’, action: ‘index’});
  54 +// will route any request to ‘/‘ to the Main controller’s index action
  55 +```
  56 +
  57 +* * *
  58 +
  59 +#### .get
  60 +`router.get( path )`
  61 +
  62 +Equivalent to `router.match( path, 'GET' )`
  63 +
  64 +* * *
  65 +
  66 +#### .post
  67 +`router.post( path )`
  68 +
  69 +Equivalent to `router.match( path, ‘POST’ )`
  70 +
  71 +* * *
  72 +
  73 +#### .put
  74 +`router.put( path )`
  75 +
  76 +Equivalent to `router.match( path, ‘PUT’ )`
  77 +
  78 +* * *
  79 +
  80 +#### .del
  81 +`router.del( path )`
  82 +
  83 +Equivalent to `router.match( path, ‘DELETE’ )`
  84 +
  85 +* * *
  86 +
  87 +#### .resource
  88 +`router.resource( controller )`
  89 +
  90 +generates standard resource routes for a controller name
  91 +
  92 +##### controller
  93 +- `controller [string]`: the camelCased controller name that needs resourceful routes
  94 +
  95 +##### examples
  96 +```
  97 +router.resource( 'products' )
  98 +
  99 +// is equivalent to:
  100 +
  101 +router.get( '/products(.:format)' ).to( 'products.index' )
  102 +router.get( '/products/add(.:format)' ).to( 'products.add' )
  103 +router.get( '/products/:id(.:format)' ).to('products.show' )
  104 +router.get('/products/:id/edit(.:format)' ).to( 'products.edit' )
  105 +router.post('/products(.:format)' ).to( 'products.create' )
  106 +router.put('/products/:id(.:format)' ).to( 'products.update' )
  107 +router.del('/products/:id(.:format)' ).to( 'products.destroy' )
  108 +```
  109 +
  110 +* * *
208 docs/3-controllers.md
Source Rendered
... ... @@ -0,0 +1,208 @@
  1 +Controllers define the different actions that your users can interact with.
  2 +
  3 +* * *
  4 +
  5 +#### .request
  6 +`this.request`
  7 +
  8 +The raw `http.ServerRequest` object for this request/response cycle.
  9 +
  10 +* * *
  11 +
  12 +#### .respnose
  13 +`this.response`
  14 +
  15 +The raw `http.ServerResponse` object for this request/response cycle.
  16 +
  17 +* * *
  18 +
  19 +#### .params
  20 +`this.params`
  21 +
  22 +The parsed params for the request. `params` is also passed as an argument to the action, it was added as an instance field for convenience.
  23 +
  24 +* * *
  25 +
  26 +#### .cookies
  27 +`this.cookies`
  28 +
  29 +Cookies collection from the request
  30 +
  31 +* * *
  32 +
  33 +#### .name
  34 +`this.name`
  35 +
  36 +The name of the controller constructor function, in CamelCase with uppercase initial letter.
  37 +
  38 +* * *
  39 +
  40 +#### .respondsWith
  41 +`this.respondsWith`
  42 +
  43 +Content-type the controller can respond with.
  44 +
  45 +##### example
  46 +```
  47 +this.respondsWith = [‘txt’,’json’,’html’];
  48 +```
  49 +
  50 +* * *
  51 +
  52 +#### .before
  53 +`before(filter, [options])`
  54 +
  55 +Adds an action to be performed before a response is rendered.
  56 +
  57 +##### filter
  58 +- `filter [function]` Action to add to the afterFilter list.
  59 +
  60 +##### options
  61 +- `except [array]` List of actions where the before-filter should not be performed.
  62 +- `only [array]` List of actions where the before-filter should only be performed.
  63 +
  64 +##### examples
  65 +```
  66 +this.before(someFunction);
  67 +// runs someFunction before the response is rendered
  68 +
  69 +
  70 +this.before(someFunction, {except: [‘index’, ‘home’]});
  71 +// won’t run someFunction if this is the index or home action
  72 +
  73 +
  74 +this.before(someFunction, {only: [‘add’, ‘update’, ‘remove’]}
  75 +// will only run someFunction if this is the add, update, or remove action
  76 +```
  77 +
  78 +* * *
  79 +
  80 +#### .after
  81 +`after(filter, [options])`
  82 +
  83 +Adds an action to be performed after a response is rendered.
  84 +
  85 +##### filter
  86 +- `filter [function]` Action to be performed
  87 +
  88 +##### options
  89 +- `except [array]` List of actions where the after-filter should not be performed.
  90 +- `only [array]` List of actions where the after-filter should only be performed.
  91 +
  92 +##### examples
  93 +```
  94 +this.after(someFunction);
  95 +// runs someFunction after the response is rendered
  96 +
  97 +
  98 +this.after(someFunction, {except: [‘index’, ‘home’]});
  99 +// won’t run someFunction if this is the index or home action
  100 +
  101 +
  102 +this.after(someFunction, {only: [‘add’, ‘update’, ‘remove’]}
  103 +// will only run someFunction if this is the add, update, or remove action
  104 +```
  105 +
  106 +* * *
  107 +
  108 +#### .protectFromForgery
  109 +`protectFromForgery()`
  110 +
  111 +Prevents cross site requests from completing.
  112 +
  113 +* * *
  114 +
  115 +#### .redirect
  116 +`redirect(to)`
  117 +
  118 +##### to [string]
  119 +- if `to` is a string, it will redirect to the url in that string
  120 +
  121 +##### to [object]
  122 +- `controller [string]`: a controller name
  123 +- `action [string]`: an action name
  124 +- `format [string]`: the file extension
  125 +
  126 +Sends a 302 redirect to the client, based on either a simple string-URL, or a controller/action/format combination.
  127 +
  128 +##### examples
  129 +```
  130 +this.redirect(‘/users/1’);
  131 +// will redirect the browser to /users/1
  132 +
  133 +
  134 +this.redirect({controller: ‘users’, action: ‘show’, id: 1});
  135 +// will redirect the browser to /users/1
  136 +```
  137 +
  138 +* * *
  139 +
  140 +#### .error
  141 +`error(err)`
  142 +
  143 +Respond to a request with an appropriate HTTP error-code. If a status-code is set on the error object, uses that as the error's status-code. Otherwise, responds with a 500 for the status-code.
  144 +
  145 +##### err
  146 +- `statusCode [number]` the code to send to the client
  147 +- `msg [string]` the message to send to the client
  148 +
  149 +##### examples
  150 +```
  151 +this.error()
  152 +// sends a 500
  153 +
  154 +
  155 +this.error({statusCode: 501})
  156 +// sends a 501
  157 +```
  158 +
  159 +* * *
  160 +
  161 +#### .transfer
  162 +```
  163 +transfer(action)
  164 +```
  165 +
  166 +Transfer a request from its original action to a new one. The entire request cycle is repeated, including before-filters.
  167 +
  168 +##### action
  169 +- `action [string]`: name of the new action designated to handle the request.
  170 +- `action [object]`: The new action designated to handle the request.
  171 +
  172 +* * *
  173 +
  174 +#### .respond
  175 +```
  176 +respond(data, options)
  177 +```
  178 +
  179 +Performs content-negotiation, and renders a response.
  180 +
  181 +##### data
  182 +- `data [object]`: an object with properties to send to the view
  183 +
  184 +##### options
  185 +- `layout [string]`: the path to the layout file to use
  186 +- `layout [false]`: a flag to not use a layout file
  187 +- `format [string]`: the format to render
  188 +- `template [string]`: The path (without file extensions) to the template to use to render this response
  189 +
  190 +##### examples
  191 +```
  192 +this.respond(params);
  193 +// send the params object to the view, then send the response
  194 +
  195 +
  196 +this.respond({posts: posts});
  197 +// send the passed in object to the view, then send the response
  198 +
  199 +
  200 +this.respond(params, {template: ‘path/to/template’});
  201 +// send params to path/to/template, render it, then send the response
  202 +
  203 +
  204 +this.respond(params, {format: ‘json’});
  205 +// send the params object as the response in json format
  206 +```
  207 +
  208 +* * *
422 docs/4-models.md
Source Rendered
... ... @@ -0,0 +1,422 @@
  1 +Geddy uses the [Model](http://github.com/mde/model) module for it's model layer. It's an abstract ORM that is compatible with many different types of databases, from Postgres to in memory, and MongoDB ro Riak.
  2 +
  3 +* * *
  4 +
  5 +#### definition
  6 +Model uses a pretty simple syntax for defining a model. (It should look familiar to anyone who has used an ORM like ActiveRecord, DataMapper, Django's models, or SQLAlchemy.)
  7 +
  8 +* * *
  9 +
  10 +#### .defineProperties
  11 +`defineProperties( properties )`
  12 +
  13 +defines the properties for your model.
  14 +
  15 +##### properties
  16 +- `properties [object]`: an object keyed by name of properties to define
  17 +
  18 +##### example
  19 +```
  20 +var User = function () {
  21 + this.defineProperties({
  22 + login: {type: 'string', required: true}
  23 + , password: {type: 'string', required: true}
  24 + , lastName: {type: 'string'}
  25 + , firstName: {type: 'string'}
  26 + });
  27 +}
  28 +```
  29 +
  30 +* * *
  31 +
  32 +#### .property
  33 +`property( name, type, options )`
  34 +
  35 +defines a single property
  36 +
  37 +##### name
  38 +- `name [string]`: the name of the property
  39 +
  40 +##### type
  41 +- `type [string]`: the type of the property
  42 + - `’string’`
  43 + - `’text’`
  44 + - `’number’`
  45 + - `’int’`
  46 + - `’boolean’`
  47 + - `’object’`
  48 + - `’array’`
  49 + - `’datetime’`
  50 + - `’date’`
  51 + - `’time’`
  52 +
  53 +##### options
  54 +- `required [boolean]`: sets the property to be required
  55 +
  56 +##### examples
  57 +```
  58 +this.property('login', 'string', {required: true});
  59 +this.property('password', 'string', {required: true});
  60 +this.property(‘joined’, ‘datetime);
  61 +this.property(‘premium’, ’boolean);
  62 +```
  63 +
  64 +* * *
  65 +
  66 +#### .validatesPresent
  67 +`validatesPresent( property )`
  68 +
  69 +Sets up a validation to make sure that the property is present.
  70 +
  71 +##### property
  72 +- `property [string]`: the name of the property to validate
  73 +
  74 +##### example
  75 +```
  76 +this.validatesPresent('login');
  77 +// makes sure that the login property is present
  78 +```
  79 +
  80 +* * *
  81 +
  82 +#### .validatesFormat
  83 +`validatesFormat( property, regex, options )`
  84 +
  85 +Sets up a validation to make sure that the property is formatted correctly.
  86 +
  87 +##### property
  88 +- `property [string]`: the name of the property to validate
  89 +
  90 +##### regex
  91 +- `regex [regex]`: a regular expression that the property value must pass
  92 +
  93 +##### options
  94 +- `message [string]`: a message to give the use if the validation fails
  95 +
  96 +##### example
  97 +```
  98 +this.validatesFormat('login', /[a-z]+/, {message: ‘cannot contain numbers’});
  99 +// makes sure that the login property does not contain numbers
  100 +```
  101 +
  102 +* * *
  103 +
  104 +#### .validatesLength
  105 +`validatesLength( property, options )`
  106 +
  107 +Sets up a validation to make sure that the property meets certain lenght requirements.
  108 +
  109 +##### property
  110 +- `property [string]`: the name of the property to validate
  111 +
  112 +##### options
  113 +- `min [number]`: the minimum length of the property
  114 +- `max [number]`: the maximum length of the property
  115 +
  116 +##### example
  117 +```
  118 +this.validatesLength(‘login', {min: ‘3’});
  119 +// makes sure that the login property is at least 3 characters long
  120 +
  121 +
  122 +this.validatesLength(‘login', {min: ‘20’});
  123 +// makes sure that the login property is not longer than 20 characters
  124 +```
  125 +
  126 +* * *
  127 +
  128 +#### .validatesConfirmed
  129 +`validatesConfirmed( property, param )`
  130 +
  131 +Sets up a validation to make sure that the property has been confirmed.
  132 +
  133 +##### property
  134 +- `property [string]`: the name of the property to validate
  135 +
  136 +##### param
  137 +- `param [string]`: the param required to match
  138 +
  139 +##### example
  140 +```
  141 +this.validatesConfirmed('password', 'confirmPassword');
  142 +// confirms that password and confirmPassword are equal
  143 +```
  144 +
  145 +* * *
  146 +
  147 +#### .validatesWithFunction
  148 +`validatesWithFunction( property, fn )`
  149 +
  150 +Sets up a validation to make sure that the property has been confirmed.
  151 +
  152 +##### property
  153 +- `property [string]`: the name of the property to validate
  154 +
  155 +##### fn
  156 +- `fn [function]`: a function which, when passed the value of the property, will return true or false
  157 +
  158 +##### example
  159 +```
  160 +this.validatesWithFunction('password', function (val) {
  161 + // Something that returns true or false
  162 + return val.length > 0;
  163 +});
  164 +// uses the function to see if th length of password is greater than 0
  165 +```
  166 +
  167 +* * *
  168 +
  169 +#### .hasOne
  170 +`hasOne( model )`
  171 +
  172 +Sets up a has one relationship between this model and another.
  173 +
  174 +##### model
  175 +- `model [string]`: the name of the model that this model has one of.
  176 +
  177 +##### example
  178 +```
  179 +this.hasOne('Profile');
  180 +// sets up a has one relationship
  181 +// user -> has one -> profile
  182 +```
  183 +
  184 +* * *
  185 +
  186 +#### .hasMany
  187 +`hasMany( model )`
  188 +
  189 +Sets up a has many relationship between this model and another.
  190 +
  191 +##### model
  192 +- `model [string]`: the pluralized name of the model that this model has many of.
  193 +
  194 +##### example
  195 +```
  196 +this.hasMany(‘Friends’);
  197 +// sets up a has many relationship
  198 +// user -> has many -> friends
  199 +```
  200 +
  201 +* * *
  202 +
  203 +#### .adapter
  204 +`this.adapter`
  205 +
  206 +Defines the database adapter for this model
  207 +
  208 +##### examples
  209 +```
  210 +this.adapter = ‘mongo’;
  211 +// makes this model use mongo for it’s database
  212 +
  213 +
  214 +this.adapter = ‘riak’
  215 +
  216 +
  217 +this.adapter = ‘postgres’
  218 +
  219 +
  220 +this.adapter = ‘memory’
  221 +```
  222 +
  223 +* * *
  224 +
  225 +#### instance
  226 +
  227 +Instance methods can be defined in the model definition as well.
  228 +
  229 +##### example
  230 +```
  231 +var User = function () {
  232 +...
  233 + this.someMethod = function () {
  234 + // Do some stuff
  235 + };
  236 + // sets up a someMethod method on each instance of this model
  237 +...
  238 +};
  239 +```
  240 +
  241 +* * *
  242 +
  243 +#### .isValid
  244 +`isValid()`
  245 +
  246 +Returns true if the model instance passes all validations, otherwise it returns false.
  247 +
  248 +##### example
  249 +```
  250 +user.isValid()
  251 +```
  252 +
  253 +* * *
  254 +
  255 +#### .save
  256 +`save( fn )`
  257 +
  258 +Saves the instance to the database.
  259 +
  260 +##### fn
  261 +- `fn [function]`: the function to be called when saving is complete
  262 +
  263 +##### example
  264 +```
  265 +user.save(function (err, data) {
  266 +// do things
  267 +});
  268 +// saves the user then calls the callback function
  269 +```
  270 +
  271 +* * *
  272 +
  273 +#### .updateProperties
  274 +`updateProperties( properties )`
  275 +
  276 +Updates the properties of a model and asserts that they are valid; This method will not call save on the instance.
  277 +
  278 +##### properties
  279 +- `properties [object]`: an object who’s keys are property names and its values are the values to change the property to.
  280 +
  281 +##### example
  282 +```
  283 +user.updateProperties({
  284 + login: 'alerxst'
  285 +});
  286 +// updates the login property and validates it
  287 +```
  288 +
  289 +* * *
  290 +
  291 +#### static
  292 +
  293 +docs coming soon
  294 +
  295 +* * *
  296 +
  297 +#### .create
  298 +`create( params )`
  299 +
  300 +Creates a new model instance and returns it.
  301 +
  302 +##### params
  303 +- `params [object]`: an object whos keys are model properties
  304 +
  305 +##### example
  306 +```
  307 +var params = {
  308 + login: 'alex'
  309 +, password: 'lerxst'
  310 +, lastName: 'Lifeson'
  311 +, firstName: 'Alex'
  312 +};
  313 +var user = User.create(params);
  314 +```
  315 +
  316 +* * *
  317 +
  318 +#### .first
  319 +`first( query, options, fn )`
  320 +
  321 +Use the `first` method to find a single item. You can pass it an id, or a set of query parameters in the form of an object-literal. In the case of a query, it will return the first item that matches, according to whatever sort you've specified.
  322 +
  323 +##### query [string]
  324 +- `query [string]`: if the query is a string, it will be assumed that it’s an id
  325 +
  326 +##### query [object]
  327 +- `query [object]`: if the query is an object, it will be interpreted as a Query object
  328 +
  329 +##### example
  330 +```
  331 +User.first(‘sdfs-asd-1’, function (err, user) {
  332 + // do stuff with user
  333 +});
  334 +
  335 +
  336 +User.first({login: 'alerxst'}, function (err, user) {
  337 + // do stuff with user
  338 +});
  339 +```
  340 +
  341 +* * *
  342 +
  343 +#### .all
  344 +`all( query, options, fn )`
  345 +
  346 +Use the `all` method to find lots of items. Pass it a set of query parameters in the form of an object-literal, where each key is a field to compare, and the value is either a simple value for comparison (equal to), or another object-literal where the key is the comparison-operator, and the value is the value to use for the comparison.
  347 +
  348 +##### query [object]
  349 +- `query [object]`: if the query is an object, it will be interpreted as a Query object
  350 +
  351 +##### options
  352 +- `sort [object]`: each key is a property name, each value can either be `asc` or `desc`
  353 +
  354 +##### example
  355 +```
  356 +User.all({location: ‘san francisco’}, function (err, users) {
  357 + // do stuff with users
  358 +});
  359 +
  360 +
  361 +User.all({location: ‘san francisco’}, {sort: {createdAt: ‘desc’}}, function (err, users) {
  362 + // do stuff with users
  363 +});
  364 +```
  365 +
  366 +* * *
  367 +
  368 +#### .remove
  369 +`remove( id, fn )`
  370 +
  371 +Remove an instance from the database by id.
  372 +
  373 +##### id
  374 +- `id [string]`: the id of the instance to be removed
  375 +
  376 +##### examples
  377 +```
  378 +User.remove(‘abc-123’, function (err, data) {
  379 + // do something now that it’s removed.
  380 +});
  381 +```
  382 +
  383 +* * *
  384 +
  385 +#### queries
  386 +
  387 +docs coming soon
  388 +
  389 +* * *
  390 +
  391 +#### events
  392 +
  393 +Both the base model 'constructors,' and model instances are EventEmitters. The
  394 +emit events during the create/update/remove lifecycle of model instances. In all
  395 +cases, the plain-named event is fired after the event in question, the
  396 +'before'-prefixed event, of course happens before.
  397 +
  398 +The 'constructor' for a model emits the following events:
  399 +
  400 + - beforeCreate
  401 + - create
  402 + - beforeValidate
  403 + - validate
  404 + - beforeUpdateProperties
  405 + - updateProperties
  406 + - beforeSave (new instances, single and bulk)
  407 + - save (new instances, single and bulk)
  408 + - beforeUpdate (existing single instances, bulk updates)
  409 + - update (existing single instances, bulk updates)
  410 + - beforeRemove
  411 + - remove
  412 +
  413 +Model-item instances emit these events:
  414 +
  415 + - beforeUpdateProperties
  416 + - updateProperties
  417 + - beforeSave
  418 + - save
  419 + - beforeUpdate
  420 + - update
  421 +
  422 +* * *
317 docs/5-templates.md
Source Rendered
... ... @@ -0,0 +1,317 @@
  1 +Geddy's view layer provides a versitile set of templating languages and helpers to get you started quickly.
  2 +
  3 +* * *
  4 +
  5 +#### engines
  6 +The view layer supports these four templating engines:
  7 +
  8 ++ EJS
  9 ++ Jade
  10 ++ Mustache
  11 ++ Handlebars
  12 +
  13 +To use them, just give your template the correct file extension.
  14 +
  15 +* * *
  16 +
  17 +#### yield
  18 +Yield is a function that's only available on layout templates. Yield, yields the template content and is put in place where the yield function is called.
  19 +
  20 +* * *
  21 +
  22 +#### partial
  23 +`partial(partialURL<String>, data<Object>)`
  24 +
  25 +Partial takes a partialURL which is the location to a partial template and a data object which is the data to render the partial with(params, etc), then it renders the partial and puts the contents in place where the partial function was called.
  26 +
  27 +* * *
  28 +
  29 +#### truncate
  30 +`truncate(string<String>, options<Integer/Object>)`
  31 +
  32 +Truncates a given `string` after a specified `length` if `string` is longer than `length`. The last character will be replace with an `omission` for a total length not exceeding `length`.
  33 +
  34 +#####Options [Integer]:
  35 +- If an `options` is an integer it will be assumed that is the desired `length`
  36 +
  37 +#####Options [Object]:
  38 +- `length [Integer]` Length the output string will be(Default: 30)
  39 +- `len [Integer]` Alias for `length`
  40 +- `omission [String]` Replace the last letters with an omission(Default: '...')
  41 +- `ellipsis [String]` Alias for `omission`
  42 +- `seperator [String/RegExp]` Break the truncated text at the nearest `seperator`
  43 +
  44 +#####Warnings:
  45 +- Please be aware that truncating HTML elements may result in malformed HTML returned. If you'd like safe HTML truncation look at `truncateHTML`
  46 +
  47 +#####Examples:
  48 +```
  49 +truncate('Once upon a time in a world', { length: 10 })
  50 +// => 'Once up...'
  51 +
  52 +
  53 +truncate('Once upon a time in a world', { length: 20, omission: '...(continued)' })
  54 +// => 'Once u...(continued)'
  55 +
  56 +
  57 +truncate('Once upon a time in a world', { length: 15, seperator: /\s/ })
  58 +// => 'Once upon a...'
  59 +// Normal Output: => 'Once upon a ...'
  60 +
  61 +
  62 +truncate('Once upon a time in a world', { length: 15, seperator: ' ' })
  63 +// => 'Once upon a...'
  64 +// Normal Output: => 'Once upon a ...'
  65 +
  66 +
  67 +truncate('<p>Once upon a time</p>', { length: 20 })
  68 +// => '<p>Once upon a ti...'
  69 +```
  70 +
  71 +* * *
  72 +
  73 +#### truncateHTML
  74 +`truncateHTML(string<String>, options<Integer/Object>)`
  75 +
  76 +Truncates a given `string` after a specified `length` if `string` is longer than `length`. The lat character will be replace with an `omission` for a total length not exceeding `length`. If `once` is true, only the first string in the first HTML element will be truncated leaving others as they were.
  77 +
  78 +#####Options [Object]:
  79 +- `once`[Boolean] If true only the first string in the first HTML element will be truncated(Default: false)
  80 +
  81 +#####Notes:
  82 +- All options available to `truncate` are available for `truncateHTML`
  83 +- HTML elements are not included with the length of the truncation
  84 +- HTML elements will not be truncated, so return value will always be safe for rendering
  85 +
  86 +#####Examples:
  87 +```
  88 +truncateHTML('<p>Once upon a time in a world</p>', { length: 10 })
  89 +// => '<p>Once up...</p>'
  90 +
  91 +
  92 +truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10 })
  93 +// => '<p>Once up...<small>in a wo...</small></p>'
  94 +
  95 +
  96 +truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10, once: true })
  97 +// => '<p>Once up...<small>in a world</small></p>'
  98 +```
  99 +
  100 +* * *
  101 +
  102 +#### imageLink
  103 +`imageLink(source<String>, link<String/Object>, imageOptions<Object>, linkOptions<Object>)`
  104 +
  105 +Returns an anchor element to a given `link` with the given `linkOptions`, with the content being a image element to the given `source` and includes it's `imageOptions`
  106 +
  107 +#####Notes:
  108 +- `linkto` is used on the backend so any `linkOption` will be used for `linkTo`
  109 +- `imageTag` is used on the backend as well so any `imageOptions` will be used for `imageTag`
  110 +