i.collect &:thoughts

i.collect &:thoughts

Micah Winkelspecht  //  Micah Winkelspecht is an entrepreneur and Ruby on Rails evangelist building next-generation web applications for other companies and his own. A few years ago, he left his comfy career in the video game industry to pursue his real passion for making the internet a better place.

Micah grew up by the beach, lives by the beach, and works by the beach, and he couldn't picture himself any place else. His current beach of choice: Manhattan Beach, CA.

Jul 25 / 10:53pm

Embedding a Google Wave into Ruby on Rails

If you're anything like me, sometime between May 28th, 2009 and now you spent an hour and 20 minutes of your life with your jaw resting firmly on the floor as you watched the creators of Google Wave give a live demo at the Google I/O conference. I think Google Wave has the potential to become a revolutionary technology and I wanted to start playing around with it right away by embedding a Wave directly onto a page in a Rails app. I found a few different Ruby libraries aimed at creating robots that live inside of a Google Wave conversation, but none that allowed me to use Ruby to embed a Google Wave into my app, so I decided to roll my own.

Without further ado, I introduce a new Rails plugin rave_embed. (I loved the name of Jason Rush's Google Wave robot library "rave", so I borrowed it. Hope you don't mind, Jason).

What is rave_embed?

rave_embed is a Ruby on Rails plugin that allows you to use Ruby to embed a Google Wave onto any page in your app. It allows you to configure your Google Wave settings using a simple Ruby method and it will generate the properly formatted Google Wave Embed API javascript automatically.

rave_embed is federation agnostic, meaning it's been designed to work with any Wave provider. But since Google is currently the ONLY Wave provider, we provide sensible default settings that will work with Google.

The bottom line is: with just a couple lines of code, you can add some of the most robust, feature rich communication and collaboration tools ever invented to your app.

What is Google Wave?

[From the Google Wave API website:] Google Wave is a product that helps users communicate and collaborate on the web. A "wave" is equal parts conversation and document, where users can almost instantly communicate and work together with richly formatted text, photos, videos, maps, and more. Google Wave is also a platform with a rich set of open APIs that allow developers to embed waves in other web services and to build extensions that work inside waves.

To sign up for a Google Wave account, go to http://wave.google.com/

If you want to dig deeper into the Google Wave API, go to http://code.google.com/apis/wave/

Dependencies

Currently, this plugin relies on the jQuery javascript framework. Only one line in the entire plugin requires it, so if someone requests it, a dependency-free version of this plugin may be on the way.  UPDATE: the plugin no longer requires jQuery. It uses standard javascript.

Installation

  1. First, install jQuery. Copy the javascript files from the jQuery website (http://docs.jquery.com/Downloading_jQuery) into your public/javascripts/ folder. UPDATE: This step is no longer required.
  2. From your app root directory, type:
    script/plugin install git://github.com/wink/rave_embed.git
  3. In your layout template, add this line to the <head> section:
    <%= RaveEmbed::JsInclude.new.to_html %>
    

Hello World!

The simplest way to embed an existing Wave into a view:

<%= RaveEmbed::WavePanel.new('my_wave_id').to_html %>

Be sure to replace 'my_wave_id' with the actual id of the Wave you want to embed.

Display Options

rave_embed works with Google Wave by default, but can be configured to work with any Wave provider (a.k.a. federation). rave_embed also allows you to customize the look and feel of the Wave to match your page. The plugin supports the following options:

  • :function_name
    • This is the name of the javascript function that draws the Wave on the page.
    • Default: 'wavePanelInit'
  • :dom_id
    • This is id of the empty div container to be replaced with the Wave panel.
    • Default: 'waveframe'
  • :root_url
    • This is the Wave server instance url. It currently points to the Google Wave servers, but could be configured to point to any Wave provider (e.g. corporate intranets).
    • Default: 'https://wave.google.com/wave/'
  • :bg_color
    • Customize the background color with a hex code string. (e.g. '#333333', '#999', 'green')
    • Default: nil (uses whatever Google chooses as it's default)
  • :color
    • Customize the text color with a hex code string. (e.g. '#333333', '#999', 'green')
    • Default: nil (uses whatever Google chooses as it's default)
  • :font
    • Customize the text font with a font string. (e.g. 'Arial')
    • Default: nil (uses whatever Google chooses as it's default)
  • :font_size
    • Customize the text font with a font size integer (in points). (e.g. 10, 12, 20)
    • Default: nil (uses whatever Google chooses as it's default)
  • :height
    • Define the height of the container div by adding a 'height' value as an inline css style. (e.g. '800px', '75%')
    • Default: nil
  • :width
    • Define the width of the container div by adding a 'width' value as an inline css style. (e.g. '800px', '75%')
    • Default: nil

Fully configured example

Add this to a helper:

module WavePanelHelper
  def wave_panel(wave_id)
    wave_panel = RaveEmbed::WavePanel.new(wave_id,
                             :function_name => 'wavePanelStart',
                             :dom_id => 'wave_container',
                             :root_url => 'https://wave.mycompany.com/',
                             :bg_color => 'green',
                             :color => '#FFFFFF',
                             :font => 'Arial',
                             :font_size => 12,
                             :height => '600px',
                             :width => '80%'
    )
    wave_panel.to_html
  end
end

And in your view:

<%= wave_panel('my_wave_id') %>

Feedback appreciated

For feedback, feature suggestions, bugs or slander, contact me at winkelspecht at gmail dot com.

Loading mentions Retweet

13 comments

Aug 20, 2009
lichu said...
Thanks for the plugin :) Still waiting for my Wave sandbox access so haven't tried it yet.
Sep 29, 2009
calas said...
Great! waiting for a wave account to try it!
Oct 02, 2009
This plugin has been updated to remove the jQuery dependency. It now creates the Google Wave panel with standard js
Oct 03, 2009
jasondenzin said...
This is a great plugin. It works well and is easy to install and setup. Thank you for taking the time to create it. Is there a way to change the height of the embedded wave as the waves I've embedded seem to be too small to be useful.
Oct 04, 2009
@jasondenzin Thanks! I've added :height and :width options to resize the wave container. These options add inline css styles to the generated wave container div. Alternatively, you can define your own css styles for this div in a separate css file.

Also, I've updated the default root url to use Google's production wave servers instead of the sandbox.

I've updated this post to reflect these changes. Thanks for the feedback!

Oct 05, 2009
jasondenzin said...
Thank you for making the changes so quickly. It's perfect now.
Dec 12, 2009
allbouttexas said...
How do I get the ID of the wave I want to embed?
Dec 12, 2009
@allbouttexas Here is a post from the Google Wave forum about how to obtain the wave ID. http://bit.ly/8aqkHS
Dec 13, 2009
allbouttexas said...
Great. That answered my question. I'm still waiting on my wave sandbox access. I tried it with a google.com wave from my account but that didn't work. - the plugin only works with the business wave accounts correct? Thanks.
Dec 13, 2009
allbouttexas said...
Nevermind, just had to use http://wave.google.com/wave as the :root_url. Plugin works like a charm.
Dec 13, 2009
allbouttexas said...
In order to have wave.mycompany.com, I must be granted sandbox access correct?
Dec 13, 2009
allbouttexas said...
One last thing... seems as though once google wave is embedded in my app, the wave that I specified (using the ID, googlewave.com!w+lwhhjOOTD), it doesn't actually focus on that wave, just shows a New Wave link in the right pane. Any ideas?
Dec 15, 2009
@allbouttexas In order to have wave.mycompany.com, you would need to install and manage your own wave server. Check out PyGoWave. You can read more about the wave federation protocol. As far as the problem with showing your wave, I'm looking into it to see if the API has changed.

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     twitter