Syntax Highlighting for Ruby Made Very Easy

So I've been making do with lame-o 'pre' tags for my code snippets and my blog looks, well, lame. But the various alternatives for highlighting ruby either didn't work for Blogger or smacked of effort (and you know how I feel about effort).

Well, recently I joined Obtiva and I was being all nosy looking at my new co-worker's blogs, when I found Tyler Jennings post about creating Spotlight. Take some ruby code, paste it into the text box, press a button, and you get some html which you copy and past into your blog. You'll have to include the default css in your css file the first time, but that's not too hard. Output looks like this:


 1 class Echo < ActionMailer::Base
2 def copy formatted_message, incident_id
3 users_with_echo_emails = User.find(:all,
4 :conditions => "echo_email is not NULL")
5 users_with_echo_emails.reject! {|user| !user.receive_echo?}
6 recipients_array = users_with_echo_emails.map { |user| user.echo_email }
7 recipients_array << ENV['default_echo_email'] if ENV['default_echo_email']
8
9 recipients recipients_array
10 subject "Globex pager incident #{incident_id} updated"
11 from 'noreply@globex.com'
12 body :message => formatted_message, :incident_id => incident_id
13 end
14 end



Cool huh?

Comments

Anonymous said…
Hey ,Thats cool..Keep posting.Hey.I am tryting to put a blog on Ruby on Rails.http://www.chaitanyavellanki.net/
I want to put my way through As I learn new things in ruby.Thankyou
Mike Zazaian said…
Good write-up, but there are some really robust syntax highlighting solutions available for ruby and rails. I just did a whole write-up on them:

http://doblock.com/articles/a-whistle-stop-tour-of-syntax-highlighting-and-markdown-solutions-for-rails

I hope you find it useful. Thanks again.

Popular posts from this blog

What's a Good Flog Score?

Point Inside a Polygon in Ruby

SICP Wasn’t Written for You