Archive for March, 2008

Scriptaculous - a Javascript library

Friday, March 14th, 2008

Scriptaculous is a Javascript library for providing Web 2.0 effects in web pages. Scriptaculous is built on top of the Prototype library(prototype.js).Effects provided by scriptaculous include Visual effects like Appear,Higlight, Shake etc of DOM elements. It also provides advanced functions like Slider, Drag & Drop and Autocomplete for text boxes.

A drop and drop shopping cart example can be see here

Scriptaculous can be downloaded from here

Download and link the scriptaculouos.js file to your html page. Using scriptaculous effects is very easy

Example:

Effect.Appear('element_id'); (element_id is the id of a DOM element)

Similar examples with demo can be seen here

Scriptaculous library by itself is simple, but Ruby on Rails makes it even simpler. Rails has wrappers around scriptacuolus methods.

Examples:
i :onclick => visual_effect(:highlight, 'msg', :duration => 1.0)

ii. <%= draggable_element 'idOne', :revert => true %>

JuggerNaut - Push Server for Rails

Friday, March 14th, 2008

When we build a web page that contains data which gets updated very frequently (eg: Share price of Google, or score of a live cricket match), it would be extremely useful if we could ‘push’ data into the webpage, without the user having to ‘pull’ the data by reloading the page or requesting explicitly.

Juggernaut is a Ruby on Rails plugin that helps to implement this ‘push’ mechanism. Comet is the widely accepted technology for doing the same. Juggernaut claims to have a few advantages over comet. Details can be found here.

Apart from the Rails application, juggernaut runs a separate push server, which maintains persistent socket connection with all connected clients. Ruby app sends data to this push server, which pushes the data to all connected clients.

Juggernaut initiates a flash xmlsocket between server and browser allowing real time communication between the two. The open socket connection allows the server to ‘push’ base64 encoded javascript to the browser which is subsequently decoded and evaluated.

juggernaut.jpg

Installation and configuration of Juggernaut are explained in detail in the Juggrenaut page.

I tried to build a simple Juggernaut-Rails application that would push the current playing song name in my system(rails app runs on the same machine). It was fairly simple, current playing song name was extracted using the Dbus interface of Rhythmbox music player (More details on this can be found in my article on IPC with Dbus. Once the songname was obtained, pushing it to the browsers required only the following code in the controller:

 render :juggernaut do |page|
      page.replace_html 'song_name', "<b> #{song_name} </b>"
 end

Ramaze Ruby is amazing !!!

Saturday, March 1st, 2008

Ramaze-means Ruby Amaze , light and modular open-source web application framework written in Ruby.Which is more easy to work with and no complexities for a new user.Ramaze is claiming to have more advantages than ruby on rails in speed , safety , user friendliness etc.

Installation is very simple

$ gem install ramaze installing as rubygem

Now your ramaze is ready to use.You can build ur applications by saying

$ ramaze --create my_app

Which will give u the basic format and you can edit and build your application in the way you want.Ramaze follows MVC architecture , unlike Rails it can work on a single ruby program also.You can run your ramaze application like

$ramaze or
$ruby start.rb

Or if u want to run a single script just run
$ ruby yourscript.rb

Ramaze is well documented with basic examples and easy to use even for a newbie.Ramaze stays close to the ruby’s principles such as simplicity n elegance.Basically Ramaze contains a controller called MainController and which maps to ‘/’. Here data is getting saved in a ‘.yaml’ file instead of database.

class MainController < Ramaze::Controller
end

Also we can map to other URL s if we want.Its pretty simpler than Rails i guess.

class AnotherController < Ramaze::Controller
map '/another'
end

You will get the basic examples to run your application from here.

Ramaze supports a lot of templating engines and such as Haml, Erubis,Markaby an d Ezmar.Also includes support for several adapters, including Mongrel, Evented Mongrel and FastCGIetc.
In the homepage of Ramaze you can see the tutorials ,just give a try you will understand more.