« Volver a Development

Ruby Portlets

(Redirigido desde Developing Ruby Portlets in Liferay)

Introduction #

Liferay supports developing portlets using the Ruby language by integrating the jRuby interpreter. While anyone can use the interpreter in their own portlets the purpose of the out-of-the-box integration is to allow the development of portlets with no need to develop in Java.

Downloading the Ruby portlet Sample #

The first step to develop a Ruby portlet is to download the sample available in sourceforge. At the moment of writing the latest version can be found in:

http://downloads.sourceforge.net/lportal/sample-ruby-portlet-4.4.0.1.war

http://downloads.sourceforge.net/lportal/sample-ruby-portlet-5.0.0.1.war

This WAR file can be deployed, just like any other Liferay plugin, by copying it to the auto deploy directory or through the Plugin Installer.

Examining the portlet sample #

To start developing your own portlet you should unzip the file to a folder of your computer. You may want to do it inside the Plugin SDK to use its ant tasks or just inside a folder controlled by your favorite IDE.

The main directories and files inside the WAR are:

  • /WEB-INF/ruby: contains the ruby sources of the portlet. These are the files that you'll work with more often. The ruby files are placed inside the WEB-INF directory to make it impossible for someone to download them (your code should never be downloadable!)
  • /WEB-INF/ruby/global : contains (by convention) ruby files that will always be loaded for every request. This files will be referenced from the 'action-file' init parameter of the portlet declaration in /WEB-INF/portlet.xml file.
  • /WEB-INF/src/com/sample/ruby/portlet/RubyPortlet.java: is the Java source code responsible for invoking the ruby files and passing them reference to the needed portlet objects such as: $portletConfig, $portletContext, $preferences, $userInfo, $actionRequest or $renderRequest and $actionResponse or $renderResponse.
  • /WEB-INF/lib: contains the classes needed by the previous class. In particular it contains the jruby.jar file which is the interpreter used to run the ruby code.

Developing complex portlets #

The Ruby portlet provided as an example is very useful to start developing in ruby very fast. Once your needs start becoming more and more complex you may want to extend it with more functionalities. The full source code is provided under the MIT license, so the sky is the limit :)

0 archivos adjuntos
20429 Accesos
Promedio (2 Votos)
La valoración media es de 3.0 estrellas de 5.
Comentarios
Respuestas anidadas Autor Fecha
How can I run it in Liferay 6? Is it possible? Jahangir Zinedine 28 de enero de 2012 23:10

How can I run it in Liferay 6? Is it possible?
Publicado el día 28/01/12 23:10.