middleman: passing local data variables between layout and template

Middleman is a great tool for creating static websites. Recently I've been using it to redesign my own website and a scenario I encountered was wanting to pass variables between my layout and my template file. Specifically, I wanted to pass information local data (a yaml file) to my layout file. Here's how I went about doing this: # in your layout file (inside layout/ folder): <% myvar = yield_content :myvar %> # in your template file (e.g., mypage.html.erb): <% content_for :myvar, data.somefile %> # this examples assumes there's a somefile.yml in your data/…Read more …

sinatra + heroku + postgres

Now that the (read-only) web service was working locally on my machine, I wanted to see if I could push it to Heroku. The first thing I did was to dump my Postgres database. Since the basic/free Heroku account only supports databases with at most 10k rows, I truncated the zip code database. There are a total of 42k+ rows, so chomping off this many rows is significant, but I'm mostly doing this just as a demonstration. Usually, you'd run pg_dump to export an entire Postgres database to a file. However, pg_dump is…Read more …

test-driven development (TDD) in sinatra

In the last post, I built a simple web service for looking up some basic geolocation information for a given zip code. To make sure the database was returning the expected output, I used irb to run specific commands. I decided to try out MiniTest and follow basic TDD principles to programmatically test out the zip code web service. MiniTest makes this really easy and, as a programming language, it's quite readable. Check out the simple test cases I used to make sure that the web service was returning accurate information (at least for 1…Read more …

getting started with sinatra and postgres web service

I'm in the process of resurrecting some of my past projects. One of them is a web service that provided details for a given zip code. For example, you could lookup the zip code '15213' and the web service would spit out the geographical center for the zip code (i.e., the latitude and longitude coordinates), as well as the city and state for that zip. I originally programmed the web service using Ruby on Rails, but using RoR for a relatively simple API is a bit overkill. So I decided to use this project…Read more …

flock 2014

I recently got back from my trip to Flock, held in Prague, Czech Republic. This is the first Fedora conference I've attended and, while the memories are still somewhat fresh in my mind, I thought I'd jot down some of my thoughts & reflections about the event. I arrived the night before the conference and was pleasantly surprised to find that getting to the conference venue was pretty easy. Prague's public transit system is extremely convenient - the metro, bus, and tram system are all integrated and tickets are very affordable. Buses from the…Read more …