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:
Install Espresso and Enginery:
Create a new application utilizing DataMapper:
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.
Next, generate your first model:
This generates a Tasks model with 3 columns in it: - id: primary key, generated automatically by DataMapper - name: string, which is the default data type - description: text
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.
This particular migration has a serial number of 1.
Let’s finish the migration:
With a table now associated with the database, let’s add some tasks!
Fire up the server:
Then navigate to http://localhost:5252/admin, click Tasks and add a few in. Get creative.
Fast, right? Let’s get even faster with Frontline.
Espresso + Enginery + Frontline
Frontline is is a front-end manager for Enginery, which allows you to fully manage applications within the browser. Yes, you heard that right.
Rock it: http://localhost:5000
Boom! Is any explanation needed? Perhaps …
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.
Let’s update the base view. Click the “Maintenance” menu and select “layout.erb”. Update the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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:
1 2 3 4 5 6 7 8 9
Then add the following code to list.erb:
1 2 3 4 5 6 7 8 9
Then check out your live app at http://localhost:5252/list