MVC way to introduce sails.js - Caesar Chi
http://sailsjs.org/#!
Monday, May 12, 14
Web, MVC
Monday, May 12, 14
Monday, May 12, 14
Monday, May 12, 14
Rails like framework, but extends node.js feature
Monday, May 12, 14
http://sailsjs.org/
Monday, May 12, 14
Sails.js
•Auto Routing
•Express base
•Scaffolding
•Socket.io support
•Restful blueprint
Monday, May 12, 14
Support
and
Enhance
Monday, May 12, 14
Monday, May 12, 14
Blueprint default support, you do not key in CRUD
https://github.com/hankejh/blueprint
Monday, May 12, 14
Model module, use Waterline
https://github.com/balderdashy/waterline
Monday, May 12, 14
Route Setting
is
*ucking EASY
Monday, May 12, 14
Scaffolding
create
controllers
models
in 1 second
Monday, May 12, 14
Blueprint built-in
Restful service in
1 second
Monday, May 12, 14
How to start?
Monday, May 12, 14
npm install -g sails
cli
Monday, May 12, 14
Quick start
Monday, May 12, 14
run app
• cd project
• node app
• sails lift
Monday, May 12, 14
Sails.js command line
Monday, May 12, 14
Sails generate
Controller
Model
action ...
cli
Monday, May 12, 14
Generate
sails generate
controller
model
name
blueprints include
cli
Monday, May 12, 14
Generate(cli)
• Model
• path:
• /api/model
• Controller
• Path:
• /api/controller
Monday, May 12, 14
Generate(cli)
• Model
• path:
• /api/model
• Controller
• Path:
• /api/controllerModel, Controller will be global object
M...
Controller
http://sailsjs.org/#!documentation/controllers
Monday, May 12, 14
sails generate controller Comment create destroy tag like
cli
Monday, May 12, 14
sails generate controller Comment create destroy tag like
cli
Request, Response
Monday, May 12, 14
CommentController.js
Monday, May 12, 14
CommentController.js
This is Model object
Monday, May 12, 14
Controller
• /api/controllers/
• http://sailsjs.org/#!documentation/controllers
Monday, May 12, 14
View
Monday, May 12, 14
View
• View -> as a render function
• Path:
• /view/...
• Support
• ejs (default)
• jade
Monday, May 12, 14
View
• View -> as a render function
• Path:
• /view/...
• Support
• ejs (default)
• jade
ejs (default)
Monday, May 12, 14
http://embeddedjs.com/
Monday, May 12, 14
Monday, May 12, 14
html layout
html body (content)
Monday, May 12, 14
view path
response.view()
controller
Monday, May 12, 14
parameters
response.view()
controller
Monday, May 12, 14
View Partials
Monday, May 12, 14
Response view
• res.view() = res.render();
• res.send({ some: 'json' });
• res.json({ user: 'tj' });
• res.redirect('/', 3...
Route
http://sailsjs.org/#!documentation/routes
Monday, May 12, 14
Route
• Route
• Path
• /api/routes.js
Monday, May 12, 14
Route (default)
default follow blueprint
URL route
Monday, May 12, 14
Route (default)
default follow blueprint
Controller name
Controller action (function)
Monday, May 12, 14
view point to route
URL route View route
Monday, May 12, 14
Route(default)
Monday, May 12, 14
Route and action
config/Route.js
Monday, May 12, 14
Model
Monday, May 12, 14
Model
• file path -> api/models
• Capital naming
• Set schema and rule.
• ORM like
• you can use multi-adapter
Monday, May ...
example, api/models/Post.js
Monday, May 12, 14
example, api/models/Post.js
defined
key
&
attribute
Monday, May 12, 14
example, controller call Post model
Monday, May 12, 14
example, controller call Post model
model name
Monday, May 12, 14
example, controller call Post model
model
behavior
Monday, May 12, 14
example, controller call Post model
new data
Monday, May 12, 14
example, controller call Post model
success
callback
&
response
Monday, May 12, 14
Model document
http://sailsjs.org/#!documentation/models
Monday, May 12, 14
Controller, Model, Service, will be Global object
Monday, May 12, 14
MVC way example
https://github.com/nodejs-tw/example-week3
Monday, May 12, 14
@clonncd
Monday, May 12, 14
Sails.js
• sails.js version is 0.9.x
• the model part and service, we will talk in
another chapter.
• keep coding, be pass...
Upcoming SlideShare
Loading in...5
×

MVC way to introduce Sails.js - node.js framework

6,419

Published on

introduce Sails.js in MVC way, we all know MVC for web development, let looking for Sails.js for Node.js Web application MVC infrastructure and development.

Published in: Internet, Technology, Business
0 Comments
20 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,419
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
89
Comments
0
Likes
20
Embeds 0
No embeds

No notes for slide

MVC way to introduce Sails.js - node.js framework

  1. 1. MVC way to introduce sails.js - Caesar Chi http://sailsjs.org/#! Monday, May 12, 14
  2. 2. Web, MVC Monday, May 12, 14
  3. 3. Monday, May 12, 14
  4. 4. Monday, May 12, 14
  5. 5. Rails like framework, but extends node.js feature Monday, May 12, 14
  6. 6. http://sailsjs.org/ Monday, May 12, 14
  7. 7. Sails.js •Auto Routing •Express base •Scaffolding •Socket.io support •Restful blueprint Monday, May 12, 14
  8. 8. Support and Enhance Monday, May 12, 14
  9. 9. Monday, May 12, 14
  10. 10. Blueprint default support, you do not key in CRUD https://github.com/hankejh/blueprint Monday, May 12, 14
  11. 11. Model module, use Waterline https://github.com/balderdashy/waterline Monday, May 12, 14
  12. 12. Route Setting is *ucking EASY Monday, May 12, 14
  13. 13. Scaffolding create controllers models in 1 second Monday, May 12, 14
  14. 14. Blueprint built-in Restful service in 1 second Monday, May 12, 14
  15. 15. How to start? Monday, May 12, 14
  16. 16. npm install -g sails cli Monday, May 12, 14
  17. 17. Quick start Monday, May 12, 14
  18. 18. run app • cd project • node app • sails lift Monday, May 12, 14
  19. 19. Sails.js command line Monday, May 12, 14
  20. 20. Sails generate Controller Model action ... cli Monday, May 12, 14
  21. 21. Generate sails generate controller model name blueprints include cli Monday, May 12, 14
  22. 22. Generate(cli) • Model • path: • /api/model • Controller • Path: • /api/controller Monday, May 12, 14
  23. 23. Generate(cli) • Model • path: • /api/model • Controller • Path: • /api/controllerModel, Controller will be global object Monday, May 12, 14
  24. 24. Controller http://sailsjs.org/#!documentation/controllers Monday, May 12, 14
  25. 25. sails generate controller Comment create destroy tag like cli Monday, May 12, 14
  26. 26. sails generate controller Comment create destroy tag like cli Request, Response Monday, May 12, 14
  27. 27. CommentController.js Monday, May 12, 14
  28. 28. CommentController.js This is Model object Monday, May 12, 14
  29. 29. Controller • /api/controllers/ • http://sailsjs.org/#!documentation/controllers Monday, May 12, 14
  30. 30. View Monday, May 12, 14
  31. 31. View • View -> as a render function • Path: • /view/... • Support • ejs (default) • jade Monday, May 12, 14
  32. 32. View • View -> as a render function • Path: • /view/... • Support • ejs (default) • jade ejs (default) Monday, May 12, 14
  33. 33. http://embeddedjs.com/ Monday, May 12, 14
  34. 34. Monday, May 12, 14
  35. 35. html layout html body (content) Monday, May 12, 14
  36. 36. view path response.view() controller Monday, May 12, 14
  37. 37. parameters response.view() controller Monday, May 12, 14
  38. 38. View Partials Monday, May 12, 14
  39. 39. Response view • res.view() = res.render(); • res.send({ some: 'json' }); • res.json({ user: 'tj' }); • res.redirect('/', 301); Monday, May 12, 14
  40. 40. Route http://sailsjs.org/#!documentation/routes Monday, May 12, 14
  41. 41. Route • Route • Path • /api/routes.js Monday, May 12, 14
  42. 42. Route (default) default follow blueprint URL route Monday, May 12, 14
  43. 43. Route (default) default follow blueprint Controller name Controller action (function) Monday, May 12, 14
  44. 44. view point to route URL route View route Monday, May 12, 14
  45. 45. Route(default) Monday, May 12, 14
  46. 46. Route and action config/Route.js Monday, May 12, 14
  47. 47. Model Monday, May 12, 14
  48. 48. Model • file path -> api/models • Capital naming • Set schema and rule. • ORM like • you can use multi-adapter Monday, May 12, 14
  49. 49. example, api/models/Post.js Monday, May 12, 14
  50. 50. example, api/models/Post.js defined key & attribute Monday, May 12, 14
  51. 51. example, controller call Post model Monday, May 12, 14
  52. 52. example, controller call Post model model name Monday, May 12, 14
  53. 53. example, controller call Post model model behavior Monday, May 12, 14
  54. 54. example, controller call Post model new data Monday, May 12, 14
  55. 55. example, controller call Post model success callback & response Monday, May 12, 14
  56. 56. Model document http://sailsjs.org/#!documentation/models Monday, May 12, 14
  57. 57. Controller, Model, Service, will be Global object Monday, May 12, 14
  58. 58. MVC way example https://github.com/nodejs-tw/example-week3 Monday, May 12, 14
  59. 59. @clonncd Monday, May 12, 14
  60. 60. Sails.js • sails.js version is 0.9.x • the model part and service, we will talk in another chapter. • keep coding, be passions. Monday, May 12, 14
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×