public
Description: The OpenLaszlo Rails plugin makes it easy to use OpenLaszlo client-side applications with Rails.
Homepage:
Clone URL: git://github.com/osteele/openlaszlo_plugin.git
name age message
file .gitignore Thu Apr 03 05:52:51 -0700 2008 add rubyforge tasks; version 0.9 [osteele]
file CHANGES Mon Mar 30 07:19:30 -0700 2009 add openlaszlo:create:symlinks task [osteele]
file MIT-LICENSE Tue Jan 17 18:10:29 -0800 2006 == 0.6 (2006-01-13) * Added documentation * :ap... [osteele]
file README.rdoc Thu Apr 30 11:33:13 -0700 2009 openlaszlo-plugin -> openlaszlo_plugin [osteele]
file Rakefile Mon Mar 23 13:19:06 -0700 2009 update readme [osteele]
file TODO Sat Apr 12 18:07:48 -0700 2008 flashobject > swfobject [osteele]
directory assets/ Sun Mar 22 21:24:05 -0700 2009 update to swfobject 2.1; refer to expressInstall [osteele]
directory generators/ Mon Mar 23 10:51:37 -0700 2009 new app template demonstrates script includes; ... [osteele]
file init.rb Mon Apr 14 07:35:46 -0700 2008 split swfobject and applet view helpers into se... [osteele]
file install.rb Sun Mar 22 21:24:05 -0700 2009 update to swfobject 2.1; refer to expressInstall [osteele]
directory javascripts/ Sun Mar 22 21:24:05 -0700 2009 update to swfobject 2.1; refer to expressInstall [osteele]
directory lib/ Sat Mar 28 19:17:06 -0700 2009 fix regression re: applet_tag [osteele]
directory spec/ Mon Apr 14 07:35:46 -0700 2008 split swfobject and applet view helpers into se... [osteele]
directory tasks/ Mon Mar 30 07:19:30 -0700 2009 add openlaszlo:create:symlinks task [osteele]
README.rdoc

OpenLaszlo Rails Plugin

The OpenLaszlo Rails plugin makes it easy to use OpenLaszlo client-side applications with Rails. It includes a generator and helper for creating OpenLaszlo applications and displaying them within Rails views.

For example, the following shell command will create an OpenLaszlo application named applet, and a view named controller/index. Requesting the view will recompile the applet.

  $ ./script/generate applet contact applet

View Helper

The plugin introduces two view helpers. swfobject_tag generates code that embeds a flash object in the page (using the swfobject JavaScript library). applet_tag additionally recompiles the applet if it is out of date, and swaps in a version of the applet compiled with the debug flag set if the debug query parameter is present in the request that resulted in the call — both of these additional features are available only in development mode.

Generators

The plugin defines the following generators, that can be used to quickly create an OpenLaszlo stub application and a view that displays it.

This generates an OpenLaszlo source file in app/applets/my-app:

  $ ./script/generate applet my-app

This also creates a model and view at /my-controller/index that displays the applet. When the app’s source changes, requesting the view recompiles the app.

  $ ./script/generate applet my-app my-controller index

Rails Tasks

The plugin defines the following tasks:

  # Recompile any applets in the app/applets directory
  rake openlaszlo:build:applets

  # Clean the applets directory
  rake openlaszlo:clobber:applets

  # Copies the swfobject javascripts to public/javascripts
  rake openlaszlo:install:javascripts

Requirements

Installation (using templates; for Rails 2.3 or later)

In Rails 2.3 or later, you can use the Rails template mechanism to install the OpenLaszlo plugin and the gem that it depends on.

The template requires that you give it sudo access, in order to run sudo rake gems:install. If you don’t want to or can’t do this, you can use the instructions for previous versions of Rails below.

To create a new Rails app:

  rails webapp -m http://gist.github.com/83809.txt

To upgrade an existing app:

  rake rails:template LOCATION=http://gist.github.com/83809.txt

To create a new Rails app, or upgrade an existing one, and create a starter applet that’s served from /home/applet, do one of:

  generate=myapp rails webapp -m http://gist.github.com/83809.txt
  generate=myapp rake rails:template LOCATION=http://gist.github.com/83809.txt

Installation (Rails 2.1 or later)

0: Install OpenLaszlo, Ruby, and Ruby on Rails.

1: In config/environment, place the following code inside the Rails::Initializer.run block:

  config.gem 'ropenlaszlo', :lib => 'openlaszlo', :version => '>= 0.6.3'

2: Install the ropenlaszlo gem:

  $ sudo rake gems:install

3: Install this plugin:

  $ ./script/plugin install git://github.com/osteele/openlaszlo_plugin.git

4: Set the OPENLASZLO_HOME environment variable to the directory that contains the OpenLaszlo SDK. The first line below is an example of this in bash (although you will probably want to put this in your .bashrc or .profile too). If you’re not using Windows, the second line of shell script will tell you whether you’ve set it right.

  $ export OPENLASZLO_HOME="/Applications/OpenLaszlo Server 4.2.0.2"
  $ grep -qs Laszlo "$OPENLASZLO_HOME/README.txt" && echo yes || echo no

Usage

In your RAILS application directory:

1: Create an applet, and a view that displays it:

  $ ./script/generate applet my-applet controller index

2: Compile the applet (this step is optional):

  $ rake openlaszlo:build:applets

Now launch the server (script/server), and you can view your applet at http:127.0.0.1:3000/controller/index.

Using the Compile Server

The steps described above use the OpenLaszlo command-line compiler to compile applications. A faster technique, although one that requires more configuration, is to leave the OpenLaszlo server running as a compile server.

The instructions for setting up an OpenLaszlo compile server are here.

Resources

Authors