RubyDemoMephisto
Mephisto Blogging Application
This document describes part 2 of the JRuby demo in the technical keynote on Tuesday afternoon of JavaOne 2007. Charlie Nutter started out demonstrating that you can run the Mephisto blogging application, a popular Ruby On Rails application, on top of JRuby. Not only that - using the Goldspike plugin, you can also deploy the application directly to a Java Application Server such as goldfish - all from within the IDE.
Hopefully, Charlie can provide instructions for how to do that and insert them here.
Now on to my own part of the demo - part 2 - where I take the standard Mephisto application, hack on it for about one minute, and add an audio-capability to it such that the article list has a set of "Speech" links. Clicking on the speech links reads out text in each blog entry as audio.
The Demo
First, perform the setup steps. Those are listed at the bottom of this blog entry. You'll need to perform them first - I'm just deferring the boring stuff to the end for those of you just reading this to "view" the demo.
Step 1: Jump to the Articles List
Screenshot
Step 2: Run it
I pressed Shift-F6. This "runs" the file, which will warp the browser to the page containing this view. This is a very quick way to jump to the right place to test the page. After doing this, I showed the articles list, pointed out the right side of the article list table, and stated that we'll be adding a column with "Speech" links. I hit Alt-Tab to jump back to the IDE.
Step 3: Add Speech Column
I went to the bottom of the file, and typed
<t
followed by Ctrl-Space. I typed "d", hit Enter, to end up with <td> in the source editor. I then hit Ctrl-Space again, which inserts a matching </td> behind the caret.
Step 4: Add a Speech link
I next invoked a TextMate-like code snippet to insert a Rails link in the RHTML file. I typed licai followed by Tab, and the source editor looks like this:
licai.tiff licai-middle.tiff licai-done.tiff
Step 5: Run It
I hit Shift-F6 again, which warps the browser back to the articles list and reloads the page. The page now contains Speak It links - which I click on. This gives us an error message, which I explain is to be expected, since we haven't implemented the speech action we just referenced in the link.
Let's go do that.
Press Ctrl-Shift-A to jump to the Action/Controller associated with this View. (Also found in the editor context menu, under Go To).
Step 6: Implement The Controller
Insert a new method: Type
def speech
and hit Enter. This will insert a matching end statement and move the caret to the middle of the method. We're now going to call into Java. Type
jc
followed by Enter. This will insert the
jc2
sendfile
rename
@article = site.articles.find(params[:id])
def speech
require 'java'
include_class 'speech.Speech'
@article = site.articles.find(params[:id])
filename = Speech.say(@article.body)
headers[Pragma] = 'public'
headers[CacheControl] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
headers[Expires] = "0"
send_file(filename, :type => "audio/wav", :disposition => "inline")
end
Setup
This was obviously not part of the demo. There are a couple of steps. First, create the Mephisto project; second, download and configure the FreeTTS text-to-speech library such that we can refer to it from the Ruby application.
Creating the Mephisto Project
First download Mephisto; I used version 0.7.3. Then in NetBeans, create a new project; choose Ruby On Rails application from existing source, and point to your mephisto installation directory. This creates the project - now we just need to configure the database.
Configure Your Database
I used MySQL. I installed it, logged in using the mysql command (mysql -l root -p), then created two databases:
mysql> create database mephisto_development; mysql> create database mephisto_test;
(For the demo, only the first database is necessary.)
Second, in your NetBeans mephisto project, open the database.yml file in Configuration. Edit the connection parameters if necessary to include your database login and password (and database names, if you didn't use the above). On some Linux distributions and otherwise, I hear MySQL can be configured in such a way that you need an additional "socket" parameter to be passed to it. Consult your docs and/or google.
Finally, you'll need to bootstrap the database. Go to the Run Rake Target menu item (in the context menu for the project), and choose Run Rake Target > db > bootstrap. This should connect to the database and construct all the tables necessary.
Populate The Blog
We'll need some sample data in the blog to make the demo useful. Log in to the "admin" console for the blog. First Run the application (which will start the web server and bring up the blog homepage). Add "/account/login" to the URL, and log in with the default name/password "admin" and "test". Put in some blog entries. The text I used for the demo was:
It's not a cup of coffee but it's hot as can be, Java, Java Jing Jing Jing

