What Is Hobo ?


Published on

This is an introduction to Hobo a web application builder for Ruby on Rails. It helps beginners to understand the basic concepts and get started

Published in: Business, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

What Is Hobo ?

  1. 1. What is Hobo ? Evarist Lobo [email_address]
  2. 2. Introduction <ul><li>Hobo is an Open Source extension to Ruby on Rails which helps you build full blown web applications incredibly quickly and easily. Available as a Gem or Rails plugin. </li></ul><ul><li>Builds on other available plugins </li></ul><ul><li>Hobo provides a simple, clean and elegant development framework which allows for rapid prototyping or production of the most sophisticated web applications. </li></ul><ul><li>Created by Tom Locke </li></ul>
  3. 3. Main Features <ul><li>Rapid implementation of dynamic Ajax interfaces in your application with no extra programming. </li></ul><ul><li>Switchable themes. Customise and tweak your application structure and layout to meet any design goals. </li></ul><ul><li>Powerful mark-up language, DRYML, combines rapid development with ultimate design flexibility. The end of the cookie cutter blues! </li></ul><ul><li>Rails extends Ruby Hobo extends Rails ! </li></ul>
  4. 4. Audience <ul><li>Hobo is a powerful tool for professional web developers who want to speed up the creation of rich, complex applications, as well as simple ‘off the cuff’ prototypes. </li></ul><ul><li>Hobo is great for designers too because the concise and elegant DRYML code makes design changes a snap to implement. </li></ul><ul><li>Newcomers to Ruby on Rails can use Hobo as a fast and easy way to learn and practice agile, iterative application development. </li></ul>
  5. 5. What can Hobo do? <ul><li>Hobo is nothing but extensions to Rails! </li></ul><ul><li>There’s nothing that Rails can do that Hobo can’t. </li></ul><ul><li>DRYML </li></ul><ul><li>Ajax Rendering </li></ul><ul><li>Hobo Rapid Tag Library </li></ul><ul><li>ActiveRecord Permission System </li></ul>
  6. 6. What can Hobo do ? <ul><li>Cross-Model Search </li></ul><ul><li>Switchable Themes </li></ul><ul><li>User Management (Acts As Authenticated) </li></ul><ul><li>ActiveRecord Composable Query Mechanism </li></ul><ul><li>Generic Model Controller (CRUD Support) </li></ul><ul><li>Migration Enhancements </li></ul><ul><li>ID Names </li></ul>
  7. 7. What is DRYML? <ul><li>A powerful tag and template language </li></ul><ul><li>Tags can be composed of other tags </li></ul><ul><li>Contains anything you can put in an XHTML page </li></ul><ul><li>Simpler to use than Erb </li></ul><ul><li>Comes with a large number of helpful tags </li></ul><ul><li>Looks like HTML </li></ul>
  8. 8. Ajax Rendering <ul><li>Integrated with Scriptaculous </li></ul><ul><li>Comes with an editor integrated </li></ul><ul><li>Very simple to use </li></ul><ul><li>Ability to mark a section of your page as a “part”. Having done this, Hobo will track the object that was in context when the part was rendered, and can re-render the part using the new state of that object when requested. </li></ul>
  9. 9. Hobo Rapid Tag Library <ul><li>A tag library is basically just like a load of Rails helpers, but as DRYML tags instead of methods. Hobo Rapid contains the Hobo equivalent of link helpers, form helpers, ajax helpers, and pagination helpers. There’s also some “scaffold-like” tags for default pages, and support for navigation bars. </li></ul>
  10. 10. ActiveRecord Permission System <ul><li>Just a simple convention for declaring who’s allowed to do what to your models (create, update, delete and view). The permissions come into effect in two places: in customizing the views, and in validating http requests. </li></ul><ul><li>View customization is provided in the tag library. The output of various tags is dependent on permissions. </li></ul>
  11. 11. Cross-Model Search <ul><li>Fairly simple but useful. Models can declare which columns are searchable (there are sensible defaults of course!) and Hobo provides both server and client-side support for a nice ajaxified search that finds many types of model from a single search page. </li></ul>
  12. 12. Switchable Themes <ul><li>A Hobo theme consists of public assets such as a stylesheet and images, and some tag definitions. </li></ul><ul><li>The tags define the basic HTML structure of the various theme elements - the overall page, header and footer, navigation bar, sidebars, panels (boxed sections within the page) etc. </li></ul><ul><li>Themes are switchable by changing a configuration variable. </li></ul>
  13. 13. User Management (Acts As Authenticated) <ul><li>In order for the permission system to work, a user model must be present. </li></ul><ul><li>For that reason we decided to go ahead and include AAA in Hobo. </li></ul><ul><li>The user model has been merged with Front controller </li></ul><ul><li>The user model methods that are not commonly changed have been moved out into a module to keep your user model clean. </li></ul><ul><li>Hobo also adds the concept of a guest user, this is a pseudo model that is not stored in the database. </li></ul><ul><li>It’s just a place to define the permissions for someone who has not logged in. </li></ul>
  14. 14. Front controller <ul><li>Hobo’s “front” controller gives you your front page and related pages like search, login and signup for FREE ! </li></ul><ul><li>Also creates associated pages in the view </li></ul><ul><li>You can customize them using DRYML </li></ul>
  15. 15. ActiveRecord Composable Query Mechanism <ul><li>It’s common practice with ActiveRecord to write query methods to capture standard queries your application needs beyond the magic find_by_* methods. </li></ul><ul><li>You are to be able to compose queries: find everything that matches this query or that one; find the first record that matches some query and some other one. </li></ul>
  16. 16. CRUD Support <ul><li>generate hobo_model_controller <model-name> </li></ul><ul><li>Hobo derives the model class from the controller class name </li></ul><ul><li>The basic CRUD methods are created: index, show, new, create, edit and update </li></ul><ul><li>also has support for your has_many and belongs_to associations </li></ul>
  17. 17. CRUD support <ul><li>Support for your associations when creating / updating models. </li></ul><ul><li>When you post (create) or put (update), you can set both has_many associations and belongs_to associations. </li></ul><ul><li>You can either pass the id of an existing record, or pass entirely new records in nested parameter hashes. </li></ul><ul><li>There’s support for all this in DRYML and Hobo Rapid </li></ul>
  18. 18. Data filters <ul><li>Data filters allow you to expose composable query mechanism to the web </li></ul><ul><li>A page with all the people not in the group with id 7 would then be available at </li></ul><ul><li>/people?where_not_in=group_17 </li></ul>
  19. 19. Enhanced autocomplete <ul><li>Rails supports Scriptaculous auto-completer through the helper auto_complete_for </li></ul><ul><li>Hobo’s version is enhanced to work with the data filter mechanism. </li></ul><ul><li>Hobo Rapid has an auto-completer tag </li></ul>
  20. 20. Remote procedure calls <ul><li>Write an action in your controller as normal. Add web_method <method-name>. </li></ul><ul><li>Hobo will add a route for your method, and apply a before filter so the object in question is already available in @this. </li></ul><ul><li>Hobo’s AJAX mechanism supports updating the page with results from your method, and there’s integration into the permission system too. </li></ul>
  21. 21. Alternative show methods <ul><li>Alternatives to the standard view </li></ul><ul><li>show_method :profile </li></ul><ul><li>create app/views/users/profile.dryml. </li></ul><ul><li>You also get a named route person_profile so you can call person_profile_url(fred) and get the URL back. </li></ul>
  22. 22. Migration Enhancements <ul><li>This is a little one, but very useful. In create_table calls, you can add columns like this </li></ul><ul><li>t.string :name, :subject, :limit => 50 instead of </li></ul><ul><li>t.column :name, :string, :limit => 50 t.column :subject, :string, :limit => 50 There’s also t.auto_dates that gives you updated_at and created_at, and </li></ul><ul><li>t.fkey :zip, :zap That will give you integer columns zip id and zap id </li></ul><ul><li>Has been used in latest version of Rails </li></ul>
  23. 23. ID Names <ul><li>In ActiveRecord everything has a numeric ID. It’s common however, that models also have an identifying name (e.g. a name column where every row is unique). </li></ul><ul><li>If a model has an ID name like this, it’s nice to be able to sometimes use it instead of the numeric ID, for example in readable URLs. </li></ul><ul><li>If your model declares hobo_model, you can also declare id_name <column-name> If you don’t specify a column it defaults to name. </li></ul><ul><li>This gives you a read/write attribute id_name which is just an alias for the column in question. You also get find_by_id_name on the class. </li></ul>
  24. 24. ID Names <ul><li>If you are using Hobo’s model_controller you can then use names instead of IDs in your URLs, e.g. (using ID names in combination with the associations support): </li></ul><ul><li>/categories/News/posts </li></ul><ul><li>The helper object_url will generate this kind of URL too - if the object you pass supports ID names. </li></ul>
  25. 25. DRYML Details <ul><li>DRYML: The Dont-Repeat-Yourself Markup Language. In case you hadn’t guessed, we’re intending to bring a higher level of re-use to Rails’ views. </li></ul><ul><li>Why? Rails already has a bunch of mechanisms for re-use within views. Namely: layouts, partials and helpers. Each serves a different purpose, and yet, IMHO, there’s still a gap. I find that small fragments of mark-up tend to crop up over and over in my views. Yes I could extract them into paritals or helpers, but I find myself disinclined to do so. </li></ul><ul><li>Helpers are good for small bits of dynamic content, but not so convenient for re-use of HTML fragments - I don’t really want to embed loads of HTML in strings in Ruby source. Nor do I want to make excessive use of the tag helper. I want to put mark-up in mark-up files. </li></ul><ul><li>. </li></ul>
  26. 26. DRYML Details <ul><li>So partials would be appropriate. But each partial needs it’s own file, which again discourages me from making heavy use of them. </li></ul><ul><li>If you ever needed to call a helper passing in HTML mark-up in the parameters, that’s HTML within Ruby within HTML — not pretty. </li></ul><ul><li>ERB doesn’t need fixing. DRYML supports ERB scriptlets, but allows you to hide them away behind nice clean custom tags, leaving you with beautiful clean templates [swoon] where you can see what’s going on at a glance </li></ul>
  27. 27. DRYML Details <ul><li>Defining a tag essentially just creates a new helper method for you, and a use of that tag is nothing more than a call to that helper. This is just syntax. Witness: </li></ul><ul><li>hello_world.dryml </li></ul><ul><li><def tag=&quot;hello&quot;>Hello World!</def> <p>Here it is: <hello/></p> <p>And here it is again: <%= hello %></p> Groovy baby :-) </li></ul><ul><li>(check out the Hello World post to see how to get set up so you can try this) </li></ul><ul><li>And just as you can call a tag from Ruby instead of mark-up, you can define them in Ruby if you wish. You can do so in your helpers. Try this </li></ul><ul><li>app/helpers/application_helper.rb </li></ul><ul><li>module ApplicationHelper include Hobo::DefineTags def_tag :from_ruby do &quot;As easy as that eh?&quot; end end </li></ul>
  28. 28. DRYML Details <ul><li>That will give you a <from_ruby/> tag in all of your DRYML templates. If your tag contains more code than mark-up, it’s cleaner to define it in a module like this. </li></ul><ul><li>You could even define the tag in a helper module and call it from an ERB scriptlet, but that would be kinda strange… Hey — knock yourself out, it’s all good :-) </li></ul><ul><li>I’m trying not to get ahead of myself because there’s a Quick Guide to DRYML coming right up. I just want to show you that this is just a thin layer on top of your regular Rails template. They’re just purdier is all. </li></ul><ul><li>Actually there’s a lot more under the hood in DRYML — it’s not just syntax. We’ll get there. </li></ul>
  29. 29. CRUD Details <ul><li>The generic controller. A standard implementation of the CRUD actions that can be used out-of-the-box in a large majority of cases. </li></ul><ul><li>The idea is that the concrete controllers that make up an application will need no custom code at all — just a few declarations: I need an auto-completer for this attribute, an ajax-setter for that one… I don’t see why this can’t be done. </li></ul><ul><li>Of course if an application needs to do something unusual, then sure you might want a custom action or two. But a huge number of apps are really nothing more than a web-interface to a database, and nearly all apps have at least some parts that fit this description. </li></ul><ul><li>There are a couple of challenges though. Firstly, what should these standard actions render? It’s all very well to have a single URL that you hit to, say, create a new event in your calendar, but depending on where in your app you’re coming from, you’re likely to want a different page (or ajax update) to follow. </li></ul>
  30. 30. CRUD Details <ul><li>Simple answer - parameterize it. Have the browser request “create me a new event, then refresh parts a, b, and c of my page”. That functionality is now part of Hobo and seems to work great. As well as getting us closer to a fully generic controller, this idea has also yielded a very simple approach to ajax. </li></ul><ul><li>Another problem I’ve hit is that sometimes an application feature requires a whole graph of related models be created in one go. The solution to that one has been to extend the way ActiveRecord handles the hash you pass to MyModel.new. With Hobo’s ActiveRecord extensions, that single call to new can set up arbitrary relationships with other models, either existing or new. </li></ul><ul><li>Hobo’s approach will make ajax programming easier than with anything else out there. </li></ul>
  31. 31. Getting started <ul><li>http://www.hobocentral.net </li></ul><ul><li>Download plugin </li></ul><ul><li>Look at screencasts for quickstart </li></ul><ul><li>Read the blogs </li></ul><ul><li>Read the forums </li></ul>
  32. 32. Contributing <ul><li>Upload code to SVN </li></ul><ul><li>Create documentation </li></ul><ul><li>Create sample applications and tutorials </li></ul>
  33. 33. Thank You <ul><li>Thanks to Tom Locke and others for creating Hobo. </li></ul><ul><li>Please email me your feedback at evarist@gmail.com </li></ul>