Jaime Iniesta

Freelance Ruby on Rails developer.

I'm an independent web developer currently living in Girona, Spain, and working at ProRuby.

I've been developing applications for 10 years now, the last 6 of them as a freelance.

I work with Rails since 2005. I'm a co-founder of the Spanish Ruby Users Group, member of Spain.rb, and organizer of Conferencia Rails and EuRuKo 2009.

I'm a Ruby on Rails contributor.

I also have experience as college professor and as speaker at Ruby (and Ruby on Rails) conferences.

If you would like to hire me, please contact me at jaimeiniesta@gmail.com.

Posts

  • August 10, 12:48 PM

    How to generate a static version of a website using nanoc and nokogiri

    More than a year has passed since we organized EuRuKo 2009 on Barcelona, so we thought that it had come the time to shut down the Ruby on Rails web applications we used for its website (a custom registration app and a simplelog).

    We wanted to maintain an archive for them, but it had to be so simple that it required zero maintenance. So we thought, hey, let's just make a static HTML version of the whole site.

    Static, but not too static

    After considering several techniques like activating full page caching on the rails applications and grab the generated files, or use wget on recursive mode to spider the site, none of these solutions satisfied me. Both of these solutions would do more or less what we wanted, but we would end up with hundreds of static html files that would be a nightmare to postprocess and adapt for the final static version.

    So after thinking about it for a while, I reached out for my ruby toolbox, took a few of them and built a custom quick-and-dirty script standing on the shoulders of giants like nanoc and nokogiri.

    What is nanoc?

    "nanoc is a tool that runs on your local computer and compiles documents written in formats such as Markdown, Textile, Haml… into a static web site consisting of simple HTML files, ready for uploading to any web server".

    Yeah, that's what it is. You have a folder with the content of each section, and a folder with the layouts you want to apply, using erb, just like you would do on a Ruby on Rails site. nanoc runs through all the content files and applies the layout to them, generating an output folder with all your HTML ready to upload to the server.

    You're also able to define custom rules and use helpers and filters for processing the content, it's a really simple and awesome tool, perfect for this task.

    So, I chose nanoc. Adapting the layout from our rails apps was a piece of cake. I had almost the same layout with its <%= yield %> line into place, and I also copied the assets (css, javascript and images). Now I just needed to define the contents of each section. But we had hundreds of them!

    We need a spider robot here

    Going manually through all of the sections on the original site and copypasting its contents was certainly not one of my options. I'd rather sit on a slowly rotating swordfish. 

    This was a job for one of those efficient and cold-blooded spider robots. That's the plan: have a spider robot visit all the sections of the original site, and get its title and the contents of the DIV with id="content". Then tell nanoc to create an item for it. Put the grabbed content on the nanoc item, along with its title attribute. Then, once done for all the site, we would just run "nanoc compile" and the whole static site would be generated. Easy, isn't it?

    Sitemaps for lazy spiders

    Poor little spider robot looked at me and said "hey, it's summer here, I'm lazy, I could certainly find my way through your website but... know what? We spider robots are quite tired of doing all this over and over again! I'd too rather sit on a slowly rotating swordfish than spidering all of your links and then finding that some of them had to be excluded. Why don't you give me a little sitemap and I'll know exactly what you want me to visit?"

    So I said "hey, excuse me, you're right, I wouldn't want to waste your precious robot time, let's build this sitemap you want". And I emailed Fernando Guillén, who had built the original app, and I said to him, "hey, can you build a sitemap of the site for this little grumpy spider?". And in a couple of minutes he had it ready.

    Enter nokogiri

    So, if you're still reading this, at this point of the story the plan is visiting a sitemap XML file with all the URLs we want to grab, and for each one of them, visit it and scrape its title and the contents of a given DIV. What could we use for this? Right! Nokogiri!

    "Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among Nokogiri’s many features is the ability to search documents via XPath or CSS3 selectors."

    Nokogiri can process XML files, as well as HTML files. It can also process a file on a server, or a local file. Perfect for the job.

    The script

    So I wrote this quick-and-dirty script. ("hey, stop calling me quick and dirty!" -- said the spider. But that's what it is, a quick, dirty and hairy spider robot.)

    To create a new spider you need to pass it these three parameters:
    • sitemap, which can be a local XML file or a remote XML file on a server
    • root_url, which is a string indicating the original root URL 
    • extract_id, which is a string telling the id of the DOM element from where the contents should be grabbed
    Then you just call its create_nanoc_items method, and the spider will go berserker, process the XML and create all the sections inside your nanoc site.

    Helpers and filters

    nanoc lets you use helpers, just like you're used to in a Rails application. I used two from nanoc's helpers, one to let me include partials, other to be able to use link_to, and defined a pair of them myself.

    You can also use filters to process your content. I defined a custom filter to clean the grabbed HTML a bit, hiding an annoying div and rewriting some links.

    Rack attack!

    So I finally run the spider, it fetched the site and prepared all those nanoc items for me. Thanks! Then I just run "nanoc compile" to generate the final site, and the generated static site was there waiting peacefully on its output folder. Time to upload it to the new server!

    While it would be too easy to just upload it to a normal web server, we thought it would be hackier to put it on Heroku. We love it and it's as simple as it can get. Yes, you can have static sites on Heroku too, as long as you define some basic rack configuration for its Thin web server.

    I then remembered that Raúl Murciano had given a great talk (with a pair of videos available) about Rack on Conferencia Rails 2009, so I emailed him for help, and he soon came out with this config.ru file. I throwed it in, along with the gem manifesto file that Heroku asks, pushed it to the server and... boom! there it was, alive and kicking, but completely static, the new EuRuKo 2009 archive.

    Permalink | Leave a comment  »

  • August 07, 10:36 AM

    Interviewed on Spanish Rails podcast

    Ruby on Rails has a large community of developers in Spain, which is growing day by day thanks in part to initiatives like Rails Hispano, a new Spanish podcast about Ruby on Rails.

    I was invited to participate on the latest episode, where I talked about my experience as a Ruby on Rails freelance. It was a pleasure to share the mic with Fernando Guillén, Raúl Murciano and Marcelino Llano.

    I'd like to see more people encouraged to try the freelance way in Spain, come on people, give yourself a chance!

    Permalink | Leave a comment  »

  • June 25, 02:32 PM

    Having fun with 37signals Draft

    Draft, the first 37signals app for the iPad lets you draw quick sketches and wireframes, using only your fingers. It's great, you only have two inks, white and red, and an eraser. Why more?

    You can also send your drawings to Campfire or by email. This is a great tool to quickly express your ideas, and I find that it's also very relaxing, just sit on the sofa and draw like a kid!

    There goes my first piece of art. This is the Guy With The Curved Scrollbar Hat:

    And, here's my second masterpiece, the Bloody Mosquito:

    Even my 5 months old son has been able to make a great piece of abstract work. :P

    If you're not on an iPad you can try a clone of this app that runs on a browser. It's really great, offers you 4 inks (although maybe with 2 is enough), but lacks an eraser (which could be easily implemented with a black ink as does 37signals).

    But of course, drawing with your fingers is so much better than with a mouse. Go try Draft on an iPad!

    Permalink | Leave a comment  »

  • June 21, 11:24 AM

    hashtag_retweet_bot

    hashtag_retweet_bot is a ruby bot that retweets all twits tagged by a certain hashtag. It's ideal for conferences, meetup groups, communities, etc.

    As an example, let's say you want to retweet every twit found with the hashtag #icecream every 5 minutes (300 seconds). This ruby gem will let you do it as easily as running:

    hashtag_retweet_bot icecream 300

    This bot was born as a little script for the Scotland On Rails 2008 conference. We saw it in action there and as it was nice and useful, so we forked it to adapt it to our needs at the EuRuKo 2009 conference.

    This year, Tomasz Stachewicz from the EuRuKo 2010 has adapted and modernized it so that it works with Bundler, OAuth, native RT and some other improvements.

    We can expect the EuRuKo 2011 will go ahead and improve it for the next year :)

    Permalink | Leave a comment  »

  • June 17, 06:07 PM
  • June 16, 10:46 AM

    The Agile Samurai

    I've just finished reading The Agile Samurai (better said, the first 17 chapters that have been written as this book is still on beta), and I would like to share it with you as I think it's a nice book to read.

    To be honest, I expected a bit more from a book with such a strong title, but I see that this book was intented for people who want to get a general idea of what the Agile developing world is like.

    So, if you're already into Agile lands, you'll surely find it a fun book to read but it won't teach you anything you didn't already know; if you're new into Agile, it will show you a whole new land. You should definitely read it in this case.

    This book covers topics like project inception, planning, creating agile teams, comunication, story cards, burn-down charts, test-driven development, and more.

    Permalink | Leave a comment  »

Information

Repos
Gists
Followers
Following

Repositories

Watched Repositories

Profile

Jaime Iniesta

Internet | Mataró Area, Spain, ES

Recent tracks

Top tracks