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

phaedryx/urug-syntax-highlighting-helper

Demonstrates how to make a simple syntax highlighting helper for rails. - phaedryx/urug-syntax-highlighting-helper