IT does really matter!

Hello, whole wide world!

This is my first blog post ever. So, i got this silly idea to start blogging about cool Information Technology topics and why does IT matter in the end.

First i had this basic problem about different blogging sites. I would consider even this as a IT-related problem. So i asked my friend (who is also not a blogger per se) about different blogging possibilities. He told me about blogspot (which i already knew) and tumblr and gave me the link about 10 weblog engines. I still decided to try tumblr out. I just found their main page to be very user friendly and web 2.0-ish.

Before making any actual posts i wanted to try some things out:

  • what kind of themes are available
  • how to make a post
  • how to insert some (Ruby) code snippets into the post with syntax highlighting

I’ve found myself a theme which i like the most but it seemed to me that it was the most popular one also which makes me soooo unoriginal doesn’t it?

Making a post is also relatively easy as long as you do not want to insert any code snippets into your posts. For my surprise i didn’t find any easy way to insert ‘code snippets’ as you can do with pretty much everything else.

Next thing i hit the google and started to search about code snippets syntax highlighting in blogs. To my surprise it seems that this is not a common thing to do yet in year 2009, thus many blogging sites do not even support it by default. Is there any which do? Anyway i found google code prettify project which allows you to highlight syntax of different languages (including Ruby) to some degree. Since tumblr allows editing of your theme’s html then you can pretty easily add some additional css/javascript/html if you like. So, adding prettify is pretty easy.

As i pointed out already then prettify supports syntax highlighting to some degree. What i meant by that is that it doesn’t support many code constructs, at least for Ruby, thus making it not so good. Little bit of more googling got me the result of using Ruby’s own syntax gem! I know that it is used by RSpec html reports, but i didn’t think about that at all. I edited the original code to add colors to more elements and made some other minor tweaks. I got most of the color codes from Textmate Vibrant Ink theme.

I also had to edit tumblr theme to add css for text wrap in <pre> tag, since i didn’t want to get any vertical scrollbars to my blogosphere. Oh and i had to turn off tumblr rich text editor and use plain text/html editor instead from the settings page. And that’s how i got my Ruby code syntax highlighting working in my blog with Ruby itself. Who could have thought…

Code itself is like that (with syntax highlighting of course):

require 'rubygems'
require 'syntax/convertors/html'

BACKGROUND_COLOR = '#2B2B2B'
COLOR = '#E6E1DC'
COLORS = {
  :keyword => '#FF6600',
  :symbol => '#6E9CBE',
  :constant => '#339999',
  :attribute => '#D0D0FF',
  :string => '#66FF00',
  :number => '#CCFF33',
  :comment => '#9933CC',
  :method => '#FFCC00',
  :ident => '#FFFFFF',
  :escape => '#555555',
  :expr => '#CCCC33',
  :regex => '#44B4CC',
  :class => '#FFFFFF;text-decoration:underline'
}

html = Syntax::Convertors::HTML.for_syntax('ruby').convert(File.read(ARGV[0]))

COLORS.each do |token, color|
  html.gsub!(%Q{class="#{token}"}, %Q{style="color:#{color}"})
end

puts %Q(<pre style="background-color:#{BACKGROUND_COLOR};color:#{COLOR};padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"><code>#{html}</code></pre>)


If you have some suggestions about missing or wrong colors when comparing to Vibrant Ink then feel free to let me know

Oh, just before making my initial post i found out that tumblr doesn’t have also any possibility to get comments from viewers. What a nice surprise :-) Thanks again to google i solved this problem quite quickly by using services of disqus. Hopefully it works too. Now i’m just wondering that maybe i should have started to use blogspot instead…

Phew, didn’t expect to get so much problems by creating my first blog post, but here it is. So, I.T. really matters! And it matters a lot. Too damn much in this particular case to be honest. What about all these non-techie people who just want to blog and have comments under their blogs etc.?

PS, forgive me about my not-so-good english since it is not my mother tongue…