I came across a presentation I did for my local meetup several months ago on how to write a code formatting helper for Rails. If you're interested, here are some screenshots.
Link to the repo: https://github.com/phaedryx/urug-syntax-highlighting-helper

