Posted by Kresimir Bojcic on June 4, 2010
There is one pretty annoying gotcha in Rails UTF-8 support. As it turns out, downcase is local insensitive. So if you put “HELLO”.downcase you’ll get “hello” as a result. But if you put “ŠĐČHELLOŽŽ”.downcase you’ll get “ŠĐČhelloŽŽ”. Now this is not that I would call a principle of a least surprise. On the bright side it’s supposed to be fixed in Ruby 2.0. Until then there is an easy fix:
gem install unicode
#enviroment.rb
require 'unicode'
require 'lib/string'
#lib/string.rb
class String
def downcase
Unicode::downcase(self)
end
end
Posted by Kresimir Bojcic on May 23, 2010
Gruff is plugin for creating pretty decent charts in Rails. It has nice straight forward API and couple of built-in themes.

To render it I’ve used(Haml)
%img{:src =>'/izvjestaji/ucestalost_po_rasvjetnom_mjestu_graf' ,
:style =>'border:1px solid #aabcca;'}
and in controller:
def ucestalost_po_rasvjetnom_mjestu_graf
g = create_pie
ucestalost_po_rasvjetnom_mjestu.each do |item|
g.data item.oznaka.to_s, item.broj_kvarova.to_i
end
send_data(g.to_blob(), :disposition => 'inline', :type => 'image/png',
:filename => "ucestalost_po_rasvjetnom_mjestu")
end
def create_pie
g = Gruff::Pie.new('948x450')
g.theme_pastel
g.font = "#{Prawn::BASEDIR}/data/fonts/times.ttf"
g.legend_font_size = 10
g.hide_title
g.title_margin = 0
g.title_font_size = 0
return g
end
My biggest issue with Gruff was having to install RMagick. Please read RMagick FAQ. You’ll have to compile it, and make sure you have all the libraries it needs.
Major grief were Croatian characters(ŠĐŽĆČ) but it applies to all utf-8. Worst part was that compile went OK, but result was all but OK
To save some time make sure you:
1. Use true type font that has chars that you want
2. Install RMagick with all the -dev libraries that it needs (otherwise special characters are screwed up)
3. FreeType library is a must – make sure you have it before compilation
When I look at the result I wish it had 3D pie, but never the less it’s worth to keep an eye on.
Posted by Kresimir Bojcic on May 16, 2010
I finally decided to give it another shot. First time I’ve checked I was not very impressed with Haml. I did like the logo, and the theory… but in practice it just didn’t feel quite right. Boy am I glad that I tried it out for the second time. This time it is a definitive yay.

What I like about it?
1. You get smaller template
2. Nice ruby and .css integration
3. Haml validations that makes you align everything just right
4. Not having to close tags – this always seemed too mechanical
My advice would be – definitely try it out if you are not already using it. Convert a couple of templates and decide for yourself. BUT DO try it out yourself on real example!
Posted by Kresimir Bojcic on November 16, 2009
Rake stats is useful when you need to know the statistics of your project. However if you try to add custom folder to be listed – documentation is somewhat sparse.
Question is why would you need a custom folder? After all isn’t the Rails prescribed way to go… Well not everything is a model or a a lib. You can have complex domain models in Ruby that have nothing to do with the database or the general library utility classes. Those poor classes just scream for the folder of their own.
If you add code to new folder named FancyNewFolder “rake stats” is not picking it up.

Here is what I did.
gvim lib/tasks/AppTasks.rake
And then I’ve added
STATS_DIRECTORIES = [
%w(Controllers app/controllers),
%w(Helpers app/helpers),
%w(Models app/models),
%w(Libraries lib/),
%w(FancyNewFolder app/fancy_new_folder),
%w(Integration\ tests test/integration),
%w(Functional\ tests test/functional),
%w(Unit\ tests test/unit)
].collect {|name, dir| [name, "#{RAILS_ROOT}/#{dir}"]}.select {|name, dir| File.directory?(dir)}
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
require 'code_statistics'
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
Voilà there is your custom folder, I’ll bet the stats are not so good as they used to be, but at least now you know the truth 

Posted by Kresimir Bojcic on September 25, 2009

You have upgraded to Ruby 1.9.1 and now (after manually changing & compiling mongrel to work) you noticed that redgreen plugin is not working. Whenever you start test you get something similar to this:
`require': no such file to load -- test/unit/ui/console/testrunner (MissingSourceFile)
Just type this in:
sudo gem install test-unit -v 1.2.3
If you are one of those “problematic” people that want to know why is this working… truth is much simpler than I would like it to be considering that I lost 2 hours over this
Ruby 1.9.1 replaced test-unit framework with minitest (because it’s supposed to be better). Redgreen plugin depends on console-runner from test-unit so you need to install it as u gem. (Older version, because the new 2.0.3 changed API just enough so redgreen is not working)