At Iron Yard Houston, we use Middleman1 to generate static websites as our first entry into website development. Middleman creates static website — locally it creates HTML files that don’t change when on the server. This is ideal for blogs (since there’s no wordpress to hack into), and information sites (like the heres-why-this-app-is-awesome part of a mobile app).
Middleman uses the same concept as Rails, our ultimate destination. You have ERB, layouts, partials, an asset pipeline; concepts that can be a bit confusing when you’re learning Rails / databases / and programming too.
However, static sites can seem limiting — you don’t want to have to manually create and write 100 different pages. So, we use two advanced parts of Middleman to programmatically create 100 different pages for us. Because computers are really good at doing something over and over and over again.
To create, first we’ll `middleman init movie movie`
Next, we’ll have middleman create a page for every movie in the json file:
We’ve chosen to have each movie that exist in the rotten_tomatoes.json file to exist at /movies/$ID.html. It’ll use an ERB file for a template to create each of those files at /movies/template.html.
Inside of the movies/template.html/erb we can display the image (with some light hacking of image sizing), and display the title and synopsis.
Whenever we “middleman build”, it’ll build an HTML file for each movie, with maximum super coolness. However, a student pointed out that Nic Cage has movie out right now, and maybe we might not want to include them. So, we added a helper (also in the config.rb):
* Note that this technique, where our protagonist has local-data TM and creates a series of published HTML files is not new. I was using Net Objects Fusion 4.0 in 1998 at my first consulting company in college. What was old is new again.