[Logo] Menta Developers Blog
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Moderation Log] Moderation Log   [Register] Register / 
[Login] Login 
[Logo]
Bye Merb Welcome Rack  XML
Forum Index » Computer Programming and IT (English)
Author Message
saoj


[Avatar]

Joined: 13/12/2007 14:28:28
Messages: 41
Offline

The answer to my prayers has just arrived. It looks like a miracle, but it is actually a Rack (not a hack).

Welcome to Rack, a foundation framework that makes it easy to write your own web frameworks in Ruby. You can think of it as a Java Servlet API, at least the basic request and response paradigm.

Rack comes with handlers for the most common Ruby web servers, such as Mongrel and WEBrick. For sanity reasons we will stick to Mongrel.

So I have given up Merb and welcome Mongrel + Rack + Erubis. Erubis is a fast template engine for Ruby that we are going to use for our HTML page generators. You can think of Erubis as a Ruby Server Pages implementation, much like JSP.

Aside from the Mentawai web framework implementation, I wanted a web container as similar to Tomcat as possible when it comes to functionality. Therefore I implemented the following features not currently (as of 0.3.0) supported by Rack:

Support for different applications (web contexts) running in the same server instance
Support for session expiration and invalidation in a thread-safe way
Support for added_to_session and removed_from_session callbacks (pretty much like HttpSessionBindingListener)
Support for custom tags, but since we are using Erubis, a better name is: custom page methods (more on that later)

Another great thing of Ruby is RubyGems. It can take some days to hack all the pieces together to make your gem available to the world, but thanks to newgem this process can now take some hours instead of days.

So ramp up your shell console and type:

You should see 1.0.1 as above. If you don't, just type:

Wait until your RubyGems is updated to the latest version.

Then you need to install Mongrel, Rack, Erubis and Mentawai, in any order.

That's it. You are ready to play with all these precious gems. Type menta to make sure Mentawai was installed correctly:

Now all you have to do is go to a directory such as c:\my_ruby_projects and type menta <app_name> to create your blank Mentawai application:

Success! Go to the HelloMenta directory and check the files.

The start.rb file is what you will use to start the web server to serve your application.
The app_manager.rb is the old and famous Mentawai application manager.
The /actions directory is where you will place your actions
The /views directory is where you will place your pages (erubis templates)

Before we go into more details about these files, let's run our application so we can be happy:

Now point your browser to http://localhost:8081/Hello.mtw?username=Jack and you should see the results of your action.

The start.rb file:

The comments say it all. You can create as many web applications and each one will have its own context path. For each application you specify a context path, the application manager file and the application manager class name. Then you start the server.

The app_manager.rb file:

That's the good and old application manager. Mentawai has conventions for everything as well. Note how you can define your own page methods. (more about page methods in a later article!)

The hello.rb action file:

The hello.erb view page:

That's it for now. After we have a solid foundation for the Mentawai architecture, we can start coding all the thousands features of the Mentawai framework. Thanks to Rack it looks like we are in the right track!
 
Forum Index » Computer Programming and IT (English)
Go to:   
Powered by JForum 2.1.8 © JForum Team