Rango

1,173 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,173
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rango

  1. 1. Introduction to Rango Jakub Stastny aka @botanicus
  2. 2. About me • Ruby & JavaScript developer. • Currently based in London. • Working as a freelancer. • botanicus.github.com
  3. 3. What is Rango? • Rack-based light-weight web framework. • As agnostic and flexible as possible. • Ruby 1.9 only. • Provides generators, but doesn’t insist on any certain structure. • Inspired by Django & Merb.
  4. 4. • Django terminology: View is called template and view means an action in controller. • You can use just whichever subset of Rango you want and it will work. • No strict conventions, just recommendations, often use hooks or strategies.
  5. 5. Boot Process • Script init.rb should setup environment. • Work as a runner: ./init.rb myscript.rb • And as a console: ./init.rb -i • Or both altogether: ./init.rb -i myscript.rb • Start web server: ./config.ru • Rewrite arguments: ./config.ru -s thin
  6. 6. Routers • Every router based on Rack (via env [“rango.router.params”]). • Rango::UrlHelper for url(:post, id)
  7. 7. Rendering • You don’t need controllers for it:
  8. 8. RenderMixin
  9. 9. • The most low-level rendering layer. • Template will be evaluated in context of the third argument which defaults to Object.new. • post is defined as a local variable.
  10. 10. ExplicitRendering
  11. 11. • Template will be evaluated in context of self.scope which you can redefine. • Data from self.context hash will be available as local variables. • Context defaults to {request: self.request}.
  12. 12. ImplicitRendering
  13. 13. • Standard Rails-like rendering. • Template will be evaluated in context of self, so you can use. • Methods as self.request or instance variables as @post are evaluated on self directly, no context required.
  14. 14. Template Inheritance • Much more flexible and cleaner than layout/ view, no hacking around with content_for and a bunch of partials. • Just an inheritance: (admin/posts.html => admin/ base.html => base.html). • The only implementation in Ruby(?) • Haml-only, because there's no such thing as <%= method(&block) %> in Erb. • I recently extracted it to template-inheritance gem (see my GitHub).
  15. 15. Basic Example #8 Default value for block • render “index.html” • extends “base.html” will parse base.html and replace its blocks by blocks in index.html
  16. 16. Returning values • Block can return whichever value via arguments. • Block returns captured string from &block.
  17. 17. AJAX
  18. 18. • It will render normal page with layout if the request isn’t AJAX. • If request is AJAX it will just render index.html. Haml render everything starting with =, it will render content block which we can use for updating part of site via JS.
  19. 19. GenericViews (GV) • Borrowed from Django. • Just a reusable Rack apps. • Can extend router (redirect, defer). • Just render template Rango::GV.static.
  20. 20. GV: Router Extensions • Deferred routes: check request and decide where to route (different actions for desktop/mobile, for registered/unregistered users etc). • Rango::GV.redirect may be useful if your router doesn’t support it.
  21. 21. HTTP Errors Handling • Based on exceptions inherited from Rango::HttpError. • Error404 resp. NotFound. • Has status, content_type and headers.
  22. 22. Rango::Controller#rescue_http_error
  23. 23. Rango::Controller#render_http_error 1
  24. 24. Rango::Controller#render_http_error 2
  25. 25. Other useful tools • Pupu: package manager for assets from GitHub (pupu install mootools). • Formidable: because helpers is welcome-back- to-PHP-mess. Again inspired by Django. Includes validations (server-side & HTML 5), coercions etc. • Git-deployer let you deploy via Git (git push staging-server staging-branch). Similar as what Heroku use, but this is more generic and you can use it with your own server.
  26. 26. Links • Wiki: http://wiki.github.com/botanicus/rango • Issues: http://github.com/botanicus/rango/issues • Twitter: http://twitter.com/RangoProject • http://groups.google.com/group/rango-project • http://github.com/botanicus/ruby-manor-rango
  27. 27. Thank you for your attention!

×