2. About me
• Ruby & JavaScript
developer.
• Currently based in
London.
• Working as a
freelancer.
• botanicus.github.com
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. • 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. 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. Routers
• Every router based on Rack (via env
[“rango.router.params”]).
• Rango::UrlHelper for url(:post, id)
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.
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}.
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. 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. 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. Returning values
• Block can return whichever value via arguments.
• Block returns captured string from &block.
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. GenericViews (GV)
• Borrowed from Django.
• Just a reusable Rack apps.
• Can extend router (redirect, defer).
• Just render template Rango::GV.static.
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.
22.
23. HTTP Errors Handling
• Based on exceptions inherited from
Rango::HttpError.
• Error404 resp. NotFound.
• Has status, content_type and headers.
27. 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.