#738 ✓hold
Tacid

Tutorial 19: save_xml_file enchantment to use with multi-lingual text

Reported by Tacid | June 9th, 2010 @ 12:11 PM

There is a problem when doing "Tutorial 19 – Using FusionCharts with Hobo" in "Rapid Rails with Hobo" book.
If labels is not in english (in my case cyrillic) there is problem with characters in charts:

1) ruby xml Builder escapes international characters with &#_NUMBER_ but FusionCharts does not understand html escapes
so I've to unescape characters befor writing them down to file with CGI.unescapeHTML()

2) FusionCharts can work with utf-8 xml files only if there is a BOM stamp in the beginning of the file (first 3 bytes) - http://www.fusioncharts.com/Docs/Contents/SpChar.html

So i have added one string to save_xml_file method:
data = [0xEF,0xBB,0xBF].pack("c3") + CGI.unescapeHTML(data)

def save_xml_file(filename, data)
  FileUtils.rm(filename, :force => true)
  f = File.new(filename, 'w')
  data =  [0xEF,0xBB,0xBF].pack("c3") + CGI.unescapeHTML(data)
  f.write(data)
  f.close
end

and now I have all the cyrillic characters on my charts
FusionCharts with cyrillic

Thank you for your work!

P.S. And I've found little error in screenshot of recipe_controller.rb code listing on page 232: in the end of listing of save_xml_file there is .close string but has to be f.close i think

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Attachments

Pages