ryanb / railscasts

railscasts.com in open source goodness!

This URL has Read+Write access

commit  23145fc1bd2a3843207fd69b2b56c27cd32ed23e
tree    005674be3fe0716c8e97f967c6f76fdb28528c47
parent  7172c252aaa78bbfadf4cb19c609d24d5e46e766
railscasts / lib / textilizer.rb
100644 17 lines (14 sloc) 0.351 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Textilizer
  def initialize(text)
    @text = text
  end
  
  def to_html
    RedCloth.new(formatted_text).to_html
  end
  
  def formatted_text
    @text.gsub(/^@@@ ?(\w*)\r?\n(.+?)\r?\n@@@\r?$/m) do |match|
      lang = $1.empty? ? nil : $1
      "\n<notextile>" + CodeRay.scan($2, lang).div(:css => :class) + "</notextile>"
    end
  end
end