Up and Running With Espresso: Rapid Web Development in the Browser

Jun 13th, 2013

Please note: The developer of Espresso is no longer maintaining the project. I revived it for the sake of this tutorial, but I will not be maintaining it either. If you wish to take on this awesome project, please contact me. Cheers!

In this tutorial we’ll be developing a simple application with Espresso, a minimalist Ruby web framework, in the typical MVC fashion. We will also be using Enginery and Frontline to speed up the development process by developing straight from the browser.

Espresso + Enginery

Create a new project directory:

1

$ mkdir espresso

Install Espresso and Enginery:

12

$geminstallespresso-framework$geminstallenginery

Create a new application utilizing DataMapper:

1

$ enginery g orm:dm

Watch your terminal window. Enginery is generating a project structure, adding the required Gems (‘data_mapper’ and ‘dm-sqlite-adapter’) to the Gemfile, updating the Rakefile and configuration file, and finally running bundler to install the Gems.

Essentially, Enginery is similar to the Rails’ Scaffolding functionality, allowing rapid development of a project built around the MCV-style architecture. It logically separates the project into Models, Views, and Controllers, and defines basic defaults - which can be modified to fit your particular application.

Now we need to create a table for our Tasks model by migrating up the initialization migration. When we created our model, this generated a serial number associated with the migration. You can find the migrations within your project structure.

Load your existing app using the project name, espresso, and the path, /Users/michaelherman/desktop/espresso (customize for your app and path). From here you have total control over setting up and maintaining your application. You can even put it under version control.

Now let’s add some controllers, routes, and additional views. Enginery already generated the Index controller with an index route in it. Let’s create a new route within the Index controller. Click “Controllers” => “Index” => “New Actions”. For the action name, enter “list” and click the arrow to the right to process.

Let’s add some logic to the new route. Click “Index Action”, and then “list”. Add the following code to the list.rb file: