Browse files

Added dump

  • Loading branch information...
1 parent b01b820 commit 66a87a53534a8cc9a07df545c7bf3e1c18bed766 Anatoliy Chakkaev committed May 12, 2011
Showing with 27 additions and 0 deletions.
  1. +24 −0 app/controllers/
  2. +2 −0 config/routes.js
  3. +1 −0 db/dump.json
@@ -86,3 +86,27 @@ action 'reorder', ->
Page.getSorted().forEach (p) ->
console.log p.pos
send 'ok'
+action 'backup', ->
+ require('fs').writeFileSync(app.root + '/db/dump.json', JSON.stringify(Page.getSorted().map (page) -> page.doc))
+ send 'ok'
+action 'restore', ->
+ wait = 0
+ waitSaving = 0
+ saved = ->
+ if --waitSaving == 0
+ send '0k'
+ done = ->
+ if --wait == 0
+ pages = JSON.parse(require('fs').readFileSync(app.root + '/db/dump.json').toString('utf8'))
+ pages.forEach (page) ->
+ delete page._id
+ p = new Page(page)
+ waitSaving += 1
+ Page.find (err, pages) ->
+ pages.forEach (page) ->
+ wait += 1
+ page.remove(done)
@@ -1,4 +1,6 @@
exports.routes = function (map) {
+ map.get('/pages/restore', 'pages#restore');
+ map.get('/pages/backup', 'pages#backup');
map.resources('pages');'/pages/reorder', 'pages#reorder');
@@ -0,0 +1 @@
+[{"_id":"4db989fbe18a1eff57000002","content":"What is railway?\r\n----------------\r\n\r\nRailway is Node.JS MVC framework based on Express, allows you to build web applications in similar manner as in Ruby On Rails. This is very young but powerful tool.\r\n\r\nInstallation\r\n------------\r\n\r\n sudo npm install express-on-railway\r\n\r\nQuick start\r\n-----------\r\n\r\nYou can use railway app generator and scaffold generator to build your first railway app in minute\r\n\r\n railway init blog && cd blog\r\n railway generate scaffold post title content date:date published:boolean\r\n railway server 8888\r\n\r\nThen visit `http://localhost:8888/posts` - it should work.\r\n\r\nWhat is under the hood\r\n----------------------\r\n\r\n - Full MVC+H stack\r\n - Resource-based [routing][1]\r\n - [Mongoose.js][2] ORM\r\n - Multi-locale support\r\n - [Coffee-script][3] support ([howto][4])\r\n - Generators for model, controller, scaffold\r\n - Testing: nodeunit, cucumis, code coverage reporting\r\n - Debugging: [railway console][5]\r\n - [Extensions][6]\r\n\r\n\r\n [1]: /routing\r\n [2]:\r\n [3]:\r\n [4]: /features/coffee\r\n [5]: /features/console\r\n [6]: /features/extensions","path":"/","pos":"0","position":4,"title":"Railway"},{"_id":"4db9aa4443dc722f5f000007","content":"Routing basics\r\n--------------\r\n\r\nThe purpose of routes is to connect URL with controller action. For example you can define route:\r\n\r\n map.get('signup', 'users#new');\r\n\r\nto link `GET /signup` with `new` action of `users` controller.\r\n\r\nResource-based routing\r\n----------------------\r\n\r\nResource-based routing provides standart mapping between HTTP verbs and controller actions:\r\n\r\n map.resources('posts');\r\n\r\nwill provide following routes:\r\n\r\n helper | method | path | controller#action\r\n ---------------------------------------------------------------\r\n posts GET /posts posts#index\r\n posts POST /posts posts#create\r\n new_post GET /posts/new posts#new\r\n edit_post GET /posts/:id/edit posts#edit\r\n post DELETE /posts/:id posts#destroy\r\n post PUT /posts/:id posts#update\r\n post GET /posts/:id posts#show\r\n\r\nto list available routes you can run command `jake routes`.\r\n\r\nFirst column in table is `helper` - you can use this identifier in views and controllers to get route. Some examples:\r\n\r\n path_to.new_post # /posts/new\r\n path_to.edit_post(1) # /posts/1/edit\r\n path_to.edit_post(post) # /posts/1/edit (in this example post = {id: 1})\r\n path_to.posts # /posts\r\n # /posts/1\r\n\r\nNested resources\r\n----------------\r\n\r\nResources may have nested sub-resources:\r\n\r\n map.resources('post', function (post) {\r\n post.resources('comments');\r\n });\r\n\r\nThis routing map will provide following routes:\r\n\r\n $ jake routes\r\n\r\n post_comments GET /posts/:post_id/comments comments#index\r\n post_comments POST /posts/:post_id/comments comments#create\r\n new_post_comment GET /posts/:post_id/comments/new comments#new\r\n edit_post_comment GET /posts/:post_id/comments/:id/edit comments#edit\r\n post_comment DELETE /posts/:post_id/comments/:id comments#destroy\r\n post_comment PUT /posts/:post_id/comments/:id comments#update\r\n post_comment GET /posts/:post_id/comments/:id comments#show\r\n posts GET /posts posts#index\r\n posts POST /posts posts#create\r\n new_post GET /posts/new posts#new\r\n edit_post GET /posts/:id/edit posts#edit\r\n post DELETE /posts/:id posts#destroy\r\n post PUT /posts/:id posts#update\r\n post GET /posts/:id posts#show\r\n\r\nTo use routes like `post_comments` you just need to pass parent resource or identifier before nested resource:\r\n\r\n path_to.post_comments(post) # /posts/1/comments\r\n path_to.edit_post_comment(post, comment) # /posts/1/comments/10/edit\r\n\r\nNamespaces\r\n----------\r\n\r\nYou may wish to organize groups of controllers under a namespace. For example, let's create admin namespace:\r\n\r\n namespace('admin', function (admin) {\r\n admin.resources('users');\r\n });\r\n\r\nThis routing rule will match with urls `/admin/users`, `admin/users/new`, etc..\r\n\r\nRestricting routes\r\n------------------\r\n\r\nIf you need routes only for several actions (e.g. `index`, `show`) you can specify `only` option:\r\n\r\n map.resources('users', {only: ['index', 'show']});\r\n\r\nIf you want to have all routes except some route, you can specify `except` option:\r\n\r\n map.resources('users', {except: ['create', 'destroy']});\r\n\r\nCustom actions in resourceful routes\r\n------------------------------------\r\n\r\nIf you need some specific action to be added to you resource-based route, use this example:\r\n\r\n map.resources('users', function (user) {\r\n user.get('avatar', 'users#avatar');\r\n });","path":"/routing","pos":"1","position":3,"title":"Routing"},{"_id":"4dc90bb9fbf97ce419000044","content":"Have fun with coffee-script\r\n---------------------------\r\n\r\nAll you need is just to add `--coffee` argument to railway command:\r\n\r\n railway init blog --coffee\r\n cd blog\r\n railway generate scaffold post title content --coffee\r\n\r\nAnd then you can run `railway server` or `coffee` to have server running on 3000 port\r\n\r\nYou can use coffeescript in models and controllers. Here is generated coffee-controller:\r\n\r\n before ->\r\n Post.findById, (err, post) =>\r\n if err or not post\r\n redirect path_to.posts\r\n else\r\n @post = post\r\n next()\r\n , only: ['show', 'edit', 'update', 'destroy']\r\n \r\n # GET /posts/new\r\n action 'new', ->\r\n @post = new Post\r\n render\r\n title: 'New post'\r\n \r\n # POST /posts\r\n action 'create', ->\r\n @post = new Post\r\n ['title', 'content'].forEach (field) =>\r\n @post[field] = req.body[field] if req.body[field]?\r\n \r\n (errors) ->\r\n if errors\r\n flash 'error', 'Post can not be created'\r\n render 'new',\r\n title: 'New post'\r\n else\r\n flash 'info', 'Post created'\r\n redirect path_to.posts\r\n \r\n # GET /posts\r\n action 'index', ->\r\n Post.find (err, posts) ->\r\n render\r\n posts: posts\r\n title: 'Posts index'\r\n \r\n # GET /posts/:id\r\n action 'show', ->\r\n render\r\n title: 'Post show'\r\n \r\n # GET /posts/:id/edit\r\n action 'edit', ->\r\n render\r\n title: 'Post edit'\r\n \r\n # PUT /posts/:id\r\n action 'update', ->\r\n ['title', 'content'].forEach (field) =>\r\n @post[field] = req.body[field] if req.body[field]?\r\n \r\n (err) =>\r\n if not err\r\n flash 'info', 'Post updated'\r\n redirect\r\n else\r\n flash 'error', 'Post can not be updated'\r\n render 'edit',\r\n title: 'Edit post details'\r\n \r\n # DELETE /posts/:id\r\n action 'destroy', ->\r\n @post.remove (error) ->\r\n if error\r\n flash 'error', 'Can not destroy post'\r\n else\r\n flash 'info', 'Post successfully removed'\r\n send \"'\" + path_to.posts + \"'\"\r\n\r\n\r\n","path":"/features/coffee","pos":"2","position":1,"title":"Coffee-script"},{"_id":"4dca6faad0b6adbc69000010","content":"Synopsis\r\n--------\r\n\r\nGeneral purpose of npmfile is to collect dependencies of application and require npm packages on application loading depending on environment.\r\n\r\nThis file should be in the root of application, and can be written in both languages: nodejs and coffeescript.\r\n\r\nnpmfile.js:\r\n\r\n require('ejs-ext');\r\n\r\n group('development', function () {\r\n require('profiler');\r\n require('dummy-mailer');\r\n });\r\n\r\\r\n\r\n require 'ejs-ext'\r\n\r\n group 'development', ->\r\n require 'profiler'\r\n require 'dummy-mailer'\r\n\r\n\r\nGroup requirements\r\n------------------\r\n\r\nNpm file allows you to call `group` function to collect packages specified for environment:\r\n\r\n\r\n group('development', function () {\r\n require('railway-profiler');\r\n require('dummy-mailer');\r\n });\r\n\r\n group('production', function () {\r\n require('error-tracker');\r\n require('nodemailer');\r\n });\r\n\r\n group('test', function () {\r\n require('sinon');\r\n require('factory-girl');\r\n require('nodeunit');\r\n require('railway/stubs');\r\n });","path":"/features/npmfile","pos":"3","position":5,"title":"npmfile"},{"_id":"4dca6c86d0b6adbc69000007","content":"Extend railway\r\n--------------\r\n\r\nAny npm package is already extension for railway. Just put line to [`npmfile.js`][1]:\r\n\r\n require('jade');\r\n\r\nCurrently I working on app-to-extension API, it will be ready soon.\r\n\r\n\r\n [1]: /features/npmfile","path":"/features/extensions","pos":"4","position":2,"title":"Extensions"},{"_id":"4dba70c43e6196835700009c","content":"","path":"/features/console","pos":"5","position":0,"title":"Console"}]

0 comments on commit 66a87a5

Please sign in to comment.