Hobo 1.4 Changes
{: .document-title}
Documents the changes made in Hobo 1.4 and the changes required to
migrate applications to Hobo 1.4
Contents
{: .contents-heading}
- contents
{:toc}
# Installation
## Creating a new application
Hobo 1.4 gems have not yet been released, so the standard instructions
of "gem install hobo; hobo new foo" do not yet work.
If you're on Linux you'll have to install a javascript runtime.
On Ubuntu 11.10 you can get one by typing `apt-get install
nodejs-dev`. Other Linuxes should be similar. Windows & OS X users
should already have a javascript scripting host installed. The list
of compatible javascript runtimes is [here](https://github.com/sstephenson/execjs).
Next you'll need to download the hobo source
git clone git://github.com/tablatom/hobo
Now you have two options: create gems, or use the source.
### Via gems
cd hobo
rake gems[install]
cd wherever-you-want-to-generate-your-app
hobo new foo
Once you've generated an app, you may wish to go in and replace the
version strings for the hobo_* gems with `:git => "git://github.com/tablatom/hobo"
### Via source
(This won't work on Windows)
export HOBODEV=`pwd`/hobo
$HOBODEV/hobo/bin/hobo new foo
## Updating an existing installation
There are several changes that need to be made to your application to
upgrade from Hobo 1.3 to Hobo 1.4. Most of these changes are
required by the addition of the asset pipeline which was introduced in
Rails 3.1.
Follow the asset pipeline upgrade steps outlined here:
http://guides.rubyonrails.org/asset_pipeline.html#upgrading-from-old-versions-of-rails
The easiest way to upgrade an existing Hobo 1.3 application is to
generate a new Hobo 1.4 application and copy differences from the new
app into your existing app.
### Gemfile
You'll need to add the gems required for the asset pipeline, add the
jquery-rails and jquery-ui-themes gem, and adjust the version numbers
for rails, hobo and perhaps others.
Hobo has also gained several additional gems, so you will have to add
dependencies for those. hobo_rapid is the Hobo tag library,
hobo_jquery is the javascript for hobo_rapid, and hobo_clean is the
default theme. Instead of or as well as hobo_clean you can use
hobo_clean_admin or hobo_clean_sidemenu. Hopefully there will be
additional themes available soon.
### config/
All of the changes in config/ are due to the assets pipeline. See
http://guides.rubyonrails.org/asset_pipeline.html#upgrading-from-old-versions-of-rails
Additionally, the Hobo 1.4 generator installs the
[rails-dev-tweaks](https://github.com/wavii/rails-dev-tweaks) gem. We
adjust the configuration so that rails-dev-tweaks applies only to
assets, not to XHR.
### application.dryml or front_site.dryml
Replace
with
Note that the default Hobo generation now always creates both a
front_site.dryml and an application.dryml, even if you don't create
any subsites.
### move public/ to app/assets/
In Rails 3.1, images, javascripts and stylesheets are loaded from
app/assets/ rather than from public/ so you'll have to move them.
Note that the following are Rails and/or Hobo assets that are now
included via the pipeline and can be deleted rather than moved:
images/rails.png
hobothemes/**
javascripts/controls.js,dryml-support.js,hobo-rapid.js,ie7-recalc.js,prototype.js,blank.gif,dragdrop.js,effects.js,IE7.js,lowpro.js,rails.js
stylesheets/reset.css,hobo-rapid.css
Note how Hobo organizes the app/assets directory. There will be a
directory called app/assets/javascripts/application/ and a directory
called app/assets/javascripts/front/. If you have added a subsite
called admin there will also be a directory called
app/assets/javascripts/admin/. Any files in application/ will always
be included, and the files in front/ or admin/ will be included only
on the corresponding subsite.
# Changes from Hobo 1.3 & hobo-jquery 1.3
## Javascript framework changed to jQuery
Hobo 1.3 and earlier versions used prototype.js for its Ajax support.
In Hobo 1.4 all of our javascript code has been rewritten to use
jQuery instead of prototype.js.
In the process of rewriting the code many tags have been updated to
add AJAX support, and tags that used non-standard AJAX mechanisms have
been updated to use standard Hobo form AJAX. The most visible of
these changes have been to the editors.
## The Asset Pipeline
Hobo 1.4 uses the asset pipeline features introduced in Rails 3.1.
Hobo 1.4 does not work out of the box with the asset pipeline turned
off. It'd certainly be possible to copy all Hobo assets into public/,
but you would have to do that manually.
## :inverse_of recommended
For correct behaviour, please ensure that all accessible associations
have their :inverse_of option set in both directions.
## set-theme deprecated
The old Hobo theme support has never worked well, and has been
replaced. Themes are now Hobo plugins and work like every other Hobo
1.4 plugin.
Replace:
with
and add
*= require hobo_clean
to your app/assets/stylesheets/front.css. Some themes may also
include javascript which would require them to be added to front.js as
well.
## default doctype changed
The default doctype has been changed from `XHTML 1.0 TRANSITIONAL` to
`html`, also known as "standards mode" in Internet Explorer 8 and 9
and "html5" in other browsers.
## default field-list changed
The default for `` has changed to ``.
The old behaviour is still available in ``. Please
provide feedback: we are open to reversion before final release.
## Helper rearrangement
In previous versions of Hobo, all Hobo helpers were available in both
the controllers and the views. In this version, some helpers are
only available in the views. If there is a helper function that you
need to access in your controller, you can call in your controller:
HoboTypeHelper.add_to_controller(self)
Other Helper classes not included in the controller by default are
HoboDebugHelper, HoboDeprecatedHelper and HoboViewHintHelper.
Several helpers have been moved into
app/helpers/hobo_deprecated_helper.rb
If your application depends on any of these, you can set
config.hobo.include_deprecated_helper.
## Rails 3.1 required
Hobo 1.4 currently requires Rails 3.1 for operation. We expect to be
on Rails 3.2 before final release.
## Enhancements
### Nested caching
See the docs for `` and the blog post I'm going to
eventually write...
### push-state
AJAX now supports a new AJAX option 'push-state' if you have
History.js installed. It was inspired by [this
post](http://37signals.com/svn/posts/3112-how-basecamp-next-got-to-be-so-damn-fast-without-using-much-client-side-ui)
which uses push-state and fragment caching to create a very responsive
rails application. Hobo has always supported fragment caching
through Rails, but push-state support is new.
The easiest way to install History.js is to use the [jquery-historyjs](https://github.com/wweidendorf/jquery-historyjs)
gem. Follow the instructions in the [README at the
link](https://github.com/wweidendorf/jquery-historyjs).
push-state blurs the line between AJAX and non-AJAX techniques,
bringing the advantages of both to the table. It's considerably more
responsive than a page refresh, yet provides allows browser bookmarks
and history navigation to work correctly.
For example, if the foos and the bars pages have exactly the same
headers but different content, you can speed up links between the
pages by only refreshing the content:
<%# foos/index.dryml %>
Bars
...
Note to Hobo 1.3 users: We're using the new `ajax` attribute instead of
`update="content"` because the link is inside the part. Outside of the
part we'd use `update="content"` instead of `ajax`.
The `new-title` attribute may be used with push state to update the
title. If you want to update any other section in your headers, you
can put that into a part and list it in the update list as well.
However the new page cannot have new javascript or stylesheets.
Avoiding the refresh of these assets is one of the major reasons to
use push-state!
push-state is well suited for tasks that refreshed the current page
with new query parameters in Hobo 1.3, like `filter-menu`, pagination and
sorting on a `table-plus`. Thus these tags have been updated to
support all of the standard ajax attributes.
Of course, ajax requests that update only a small portion of the page
will update faster than those that update most of the page. However,
a small update may mean that a change to the URL is warranted, so you
may want to use standard Ajax rather than push-state in those cases.
Also, push-state generally should not be used for requests that modify
state
push-state works best in an HTML5 browser. It works in older browsers
such as IE8, IE9 or Firefox 3, but results in strange looking URL's. See
the README for History.js for more details on that behaviour.
### plugin generators
Hobo has gained two new generators.
`hobo generate install_plugin` may be used from inside a Hobo
application to install a Hobo plugin. It modifies the Gemfile,
application.dryml or X_site.dryml and adds the plugin to
app/assets/javascripts and app/assets/stylesheets.
`hobo plugin` is used from outside of a Hobo application to create the
skeleton for a new plugin. See [the plugin manual page](FIXME) for
more details.
### multiple parts
I've updated DRYML so that it emits a different DOM ID if you
re-instantiate a part. (The first use of a part retains the DOM
ID=partname convention for backwards compatibility) "update=" requires
a DOM ID, so I've also added 2 new AJAX attributes that can be used
instead of "update=".
The first one is "updates=". Instead of a comma separated list of DOM
ID's, it takes a CSS selector.
The other one is "ajax". If used inside of a part, it indicates that
the containing part should be updated. If used outside of a part,
AJAX will be used but no parts will be updated.
These three Ajax attributes may be used simultaneously.
Example:
### allowing errors in parts
Older versions of Hobo did not render a part update if the update did
not pass validation.
This behaviour may now be overridden by using the 'errors-ok'
attribute on your form. (or formlet or whatever other tag initiates
the Ajax call).
The 'errors-ok' attribute is processed in update_response. If you've
supplied a block to hobo_update you will be responsible for
implementing this functionality yourself.
### AJAX file uploads
If you have malsup's form plugin installed, Ajax file uploads should
"just work", as long as you don't have debug_rjs turned on in your
config/initializers/development.rb.
### AJAX events
The standard 'before', 'success', 'done' and 'error' callbacks may
still be used. Additionally, the AJAX code now triggers
'rapid:ajax:before', 'rapid:ajax:success', 'rapid:ajax:done' and
'rapid:ajax:error' events to enable you to code more unobtrusively.
If your form is inside of a part, it's quite likely that the form will
be replaced before the rapid:ajax:success and rapid:ajax:done events
fire. To prevent memory leaks, jQuery removes event handlers from all
removed elements, making it impossible to catch these events.
If this is the case, hobo-jquery triggers these events on the document
itself, and passes the element as an argument.
$(document).ready(function() {
jQuery(document).on("rapid:ajax:success", function(event, el) {
// `this` is the document and `el` is the form
alert('success');
});
});
### before callback
A new callback has been added to the list of Ajax Callbacks: before.
This callback fires before any Ajax is done. If you return false
from this, the Ajax is cancelled. So you should probably ensure you
explicitly return true if you use it and don't want your ajax
cancelled.
### callbacks
Normally in HTML you can attach either a snippet of javascript or a
function to a callback.