2011-08-27
By Ivo Dancet
Tags:

Vim

Optimizing Vim: tab style

Optimizing Vim: tab style

As mentioned in a previous post of mine, I use Vim nowadays just like all the cool guys! And just like in that previous post, I would like to share a trick.

I mostly work with two screens. During (Rails) development my MacBook Pro screen is mostly dedicated to fullscreen iTerm with split screens for running Cucumber, rSpec and a tail on test.log. The other screen is used by Vim. In longer sessions my Vim tends to end up with multiple tabs of split screens.

I really like the Mac-styled tabs Vim shows in window mode, but I like the standard Vim tabs more for fullscreen work. So what I needed was a way to make command-enter do the fullscreen toggle and change the tab-style automatically. Making this work didn't prove to be really easy.

Some problems I encountered to make this work (which I found scattered all over the Internet):

  • The help file mentions a fuleave and fuenter (fullscreen-leave and fullscreen-enter) hook, but these are not implemented yet.
  • You need to write this in gvimrc.local and not in vimrc.local as the latter is read by Vim too early.
  • You cannot map the shortcuts used by MacVim itself unless you unmap them first which is done with a special command.

So this way, fullscreen looks like this:

vim style tab

And window mode like this:

vim mac style tabs

Comments
2011-05-09
By Ivo Dancet

haml-js and jammit

Using haml-js and Jammit in a Rails app (with backbone.js)

Some time ago I submitted a small patch to Jammit to enable haml-js as a template language. Afterwards I have received several questions through github on how to use it. I hope this blog entry helps if you too have any trouble to set this up.

Aside from the haml-js stuff I also added some tips. You will need to read through the Jammit documentation to know how to set things up from zero.

[update] setting up Rails

In order to be able to use the patch you'll still need to use the gem through github instead of the official one. So add the following to your Gemfile: (thanks for pointing this out David Francisco)

gem "jammit", :git => 'git://github.com/documentcloud/jammit.git'
          

You should not use the fork I've made since I may delete it soon (the only purpose was to be able to create the patch, I certainly do not intend to keep it around).

Setting up Jammit: assets.yml

This is an example config/assets.yml file. You can also see how I organise my files here.

As you can see I have mixed the view files within app/views (and are thus like partials, which in fact, they are of course).

You can choose the template_extension. I think .jst.haml is perfect. I also follow Rails conventions and add an underscore as a prefix to the filenames.

You also need Haml as the template_function. The compiled file Jammit is going to deliver (and your Rails application will use) looks like this:

Of course you need to have the haml-js required to make things work. From here on you can get back to the Jammit documentation.

Using the templates with backbone.js

This is pretty straightforward:

UserView = Backbone.View.extend({
            template: JST["users/_show"],
            render: function() {
              $(this.el).append(this.template(this.model.attributes));
              this.addAll();
              return this;
            }
          })
          
Comments
2011-03-07
By Ivo Dancet
Tags:

Vim

WriteRoom

VimRoom

VimRoom, a Vim-based replacement for WriteRoom

Since I changed from TextMate to Vim, every application I use feels like something is missing. Oh, I really miss all those blessed Vim-commands in every non-Vim app. One of the applications in which I miss the ability to move around Vim-style the most is WriteRoom (or JDarkRoom). I've searched the Internet many times before but have only found half-baked solutions. Well, till yesterday that is, when I found this wonderful and very simple MacVim based solution by Brandur Leach.

Applying the script is really simple and it is fairly complete although not everything changes into what the screenshot looks like. I've adapted the script and have put it in a gist.

I've also put my bash_profile alias in the gist. Not that it differs much from the original, but I just like the name VimRoom.

Comments

Hudson for a Rails3 project

Configuring Hudson for a Rails3 project

Using rSpec2, rCov, Cucumber, Bundler, rvm and git

 

Hudson: why?

Since a week my colleague and I have been using a Continuous Integration server. Let me explain in a few words why we think that's an enormous step forward.

We noticed that large projects on which we hadn't worked for several months started to wreck our Cucumber features and rSpec specs in some mysterious, unexpected way. This started to really hold us up too long and we felt discouraged to run all of our tests before a deploy. Quite a large part of this problem can of course be solved today using Bundler.

A second problem we faced is time. Running all tests in some javascript-heavy projects easily takes up half an hour.

A Continuous Integration server is what has changed all that. We now run each of our projects overnight whether we have worked on it or not. That's why we are able to stay confident about the quality of the tests and the software.

Why Hudson and not anything else? Well, let's be clear, we're a company run by two developers. We want something that gets us up to date as fast as possible. We had read good things about Hudson and after trying several possible solutions, Hudson seemed the most stable one that kept stuff really simple while offering tons of cool plugins (like the ones for "extreme feedback").

The setup

Up till now Hudson has run locally on my own MacBook Pro. So far this has been a good solution but it's obvious that as this laptop is also the one I constantly work on, it isn't possible to run tests after each git commit.

Therefore, we will consider two options in the future: buying a cheap desktop computer running Ubuntu or keep the Macbook Pro setup when we buy some new MacBooks for ourselves later this year. The latter seems the most interesting option as it won't cost us a lot of money, we can keep our beloved OS X, and so we will keep a backup laptop in case one of our new MacBook Pro's breaks down.

Installing

I'll explain what to do to get a similar setup.

Download the war file from the hudson-ci website and run (in the correct dir):

java -jar hudson.war

Once running, you can connect to http://localhost:8080 to configure the setup. (Yes, that was all there is to it ...)

Configuration

Hudson Plugins

Through the plugin system install the next plugins:

  • Hudson Git plugin
  • Hudson Rake plugin
  • Notifo plugin: this one notifies us of the outcome of builds on our iPhones

We also uploaded a plugin to be able to easily build with rvm support:

  • hudson-rvmRubyMetrics-plugin (to install, click the downloads button on github and download the .hpi file. Upload it as a plugin in the Hudson plugin configuration panel)

We think you don't need the rvmRuby plugin. The rvmRake plugin is already merged with the official Hudson Rake plugin. So no need to install that one either.

Rvm

You will need the latest rvm (or at least one with the rvm-shell command) (run rvm update and rvm reload to get up and running).

Your Rails project

You need to make sure your own project has the necessary requirements.

For starters, make sure your tests run on rSpec2, and not a beta-version.

Make a config/database.ci.yml file which you configure for a test db (if you work with ActiveRecord of course) and add it to your git repo.

Most importantly, you need rake tasks that run your tests and generate rcov data. It's also better to produce jUnit xml test reports. If you don't care, you will have to read through the console output. With the jUnit test reports, however, you will get nice, readable feedback.

I use the following rake task (not really polished). It does all I have said above:

At this stage you should be able to run the rake tasks Hudson will run:

rake hudson:rcov RAILS_ENV=test
rake hudson:cucumber RAILS_ENV=test

Cucumber should not exit with an error if there are pending steps

Cucumber is configured to exit with an error code if there are pending steps. If you do not want this to happen, remove the --strict from your config/cucumber.yml file.

Hudson Project

Finally, you can set up your project in Hudson:

I've got the following configuration:

  • Discard Old Builds and keep the last 200 builds
  • Get source code through git
  • Build periodically: 1 3 * * *. I've also set my Mac to wake at 3am and go back to sleep at 5am. You can schedule this through the energy panel (click the schedule button). Make sure the lid of the MacBook is not closed and the MacBook is plugged in.
  • Build steps (for Rake tasks I always select the appropriate Rake version, like ruby-1.8.7-p249@<project-name>):

    • shell script:
    • Invoke Rake: db:schema:load RAILS_ENV=test
    • shell script:
    • Invoke Rake: hudson:rcov RAILS_ENV=test
    • Invoke Rake: hudson:cucumber RAILS_ENV=test
  • After build:

    • Publish JUnit test result report, Test report XMLs: hudson/reports/**/*.xml
    • Publish Rails Notes report, fill in RVM Ruby string
    • Publish flog report: Ruby class directories: app (anyone knows how to set multiple directories here?)
    • Publish Rails stats report, fill in RVM Ruby string
    • Publish Rcov report, Rcov report directory: rcov, Coverage metric targets: 80, 0, 0
    • E-mail Notification (configure smtp server through Hudson > Manage Hudson > Configure System
    • Notifo: Instructions here, works like a charm!
  • I needed to install the flog gem on my system ruby to get the flog report to work.

Conclusion

I really like Hudson: it's easy to set up and most importantly, it makes my colleague and me feel very confident about our code.

If you have other tips or tricks on using Hudson or if you do things differently and better, I'll be glad to hear how from you.

These are the sources I used to figure everything out:

Comments
2010-09-15
By Ivo Dancet
Tags:

Rails3

Looking up Rails(3) routes

Looking up Rails3 routes

As everybody probably knows, you can use rake routes to look up info about existing routes and their helper methods. However, this takes a while to load and you need a huge screen to look at it. Today I thought of a much faster method for those of us having a rails console open all the time. Not that much of a deal, but it became a really helpful tool over the last week.

Just execute app.routes.sort. Even better if your Gemfile requires awesome_print, you can issue ap app.routes.sort. You could even filter the list using select or maybe even add methods to the app object to help with the filtering like in the example below which I use in my current project now. If you want to use it, just paste the code in a file like config/initializers/rinfo.rb, add awesome_print to your Gemfile and restart your console.

Comments
About
This blog is written by Wouter Vancraeynest and Ivo Dancet and is about what we come across while working at our company by2.be, located in Bruges, Belgium. This can be anything related - though sometimes only remotely - to programming, testing, marketing, Ruby, Apple and other things we do and love ...
Recent posts
Optimizing Vim: tab style
haml-js and jammit
VimRoom
Hudson for a Rails3 project
Looking up Rails(3) routes
Horror story, part II
All tags
Jammit - SaaS - Rails - WriteRoom - Haml - rSpec - Vim - Ruby on Rails - rcov - Cucumber - humans - continuous integration - Hudson - Rails3 - testing - rSquery - haml-js - Bundler - rvm - backbone.js - Selenium
rSquery
Some time ago we made rSquery to be able to easily use jQuery matchers in Selenium projects. You may want to check it out on github. By now this project is not in active development anymore but older projects can still profit from it. (We still use it)