ikhono.net

Gnome autotest Notifications 14

Posted on Sunday, December 16

I finally found some time to familiarize myself with RSpec by working through the excellent PeepCode RSpec screencasts (part 1, part 2, and part 3). In his screencasts, Geoffrey is using Growl for displaying notifications of autotest.

I wanted something similar and found a few examples explaining how to use notify-send from libnotify. While this is pretty easy to implement, it is just not flexible enough.

After some more searching I found an article by Derek Berner about ruby-libnotify doing more or less exactly what I want. The only problem was, that I couldn’t get his code working on my computer running Ubuntu 7.10. So I decided to write my own autotest configuration and now enjoy nice autotest notifications.

Notify

The status symbol in the notification area additionally shows the last autotest result as a tooltip.

Tooltip

Continue reading...

With a little help from my friends 0

Posted on Friday, November 30

In this article I’d like to present you some of my favourite Rails helper methods. Just add them to your app/helpers/application.rb file to use in your own application.

Booleans

This is maybe one of the most basic helpers you’ll ever encounter. But it also helps you DRY up your code, e.g. if your application is multilingual.

1
2
3
def yes_no(bool)
  bool ? "yes" : "no"
end

Numbers

The following helper prints numbers with correct delimiters and a fitting form of title.

1
2
3
def print_number(title, number)
  number_with_delimiter(number) + " " + title.pluralize(number)
end

Page title

The title helper helps to DRY up page titles:

1
2
3
4
5
def title(page_title)
  content_for(:title) {
    page_title
  }
end

I found this helper on Railscasts.

In app/views/layouts/application.rhtml I use the following two snippets:


<title>MySite :: <%= yield(:title) || "My uber cool site!" %></title>
1
2
3
<% if yield(:title) %>
  <h1><%= yield(:title) %></h1>
<% end %>

To set the title, I call the title helper in my views like this:


<% title "User profile of #{@user.login}" %>

Forms

The tabindex attribute of form elements specifies the position in the tabbing order. The tabbing order defines the order in which elements will receive focus when navigated by the user via the keyboard.

Instead of specifying the tabindex yourself, you can use the helper method

1
2
3
4
def autotab
  @current_tab ||= 0
  @current_tab += 1
end

in your views like this:


<%= f.text_field :first_name, :tabindex => autotab %>

Ruby on Rails 2.0 added the very handy label form helper. But unfortunately there is no label_tag helper. So I added one myself:

1
2
3
4
5
6
7
# Creates a label tag.
#   label_tag('post_title', 'Title')
#     <label for="post_title">Title</label>
def label_tag(name, text=nil, options = {})
  content = (text.blank? ? nil : text.to_s) || name.to_s.humanize
  content_tag('label', content, { 'for' => name }.merge(options.stringify_keys))
end

I often use a submit button together with a link to cancel. Overriding the submit_tag helper provided by Rails, helps me to DRY up my views:

1
2
3
4
5
def submit_tag(value = "Save changes", options = {})
  or_opt = options.delete(:or)
  return super + " <span class='button_or'>" + "or" + " " + or_opt + "</span>" if or_opt
  super
end

Now I can use the following code in my views:


<%= f.submit 'Update', :or => link_to('Cancel', user_path(@user)), :tabindex => autotab %>

Markaby

Markaby lets you generate HTML for views by writing ordinary Ruby code. I particulary like to use Markaby in my helpers. To simplify the use of Markaby, I’m using the following helper method:

1
2
3
def markaby(&block)
  Markaby::Rails::Builder.new({}, self, &block) 
end

The markaby helper can be used in other helpers like this:

1
2
3
4
5
6
7
8
def logo_text
  markaby do
    span.logo do
      span.blue "My"
      span.green "App"
    end
  end
end

The above helper generates the following HTML code:


<span class="logo"><span class="blue">My</span><span class="green">App</span></span>

New hoster 0

Posted on Saturday, November 24

I’ve had some big problems with hosting Rails applications at my previous hoster, so I decided to switch to the official Ruby on Rails host Joyent.

I signed up for a shared hosting account and I’m really happy with it. I can deploy Rails applications with Mongrel and the support is excellent.

me.goes :Camping 0

Posted on Monday, June 18

I was playing with Camping lately and thought I’d share some of the links I found with you: