//depot/projects/wiki/app/models/page.rb#2 – edit change 227 (text) ·revision history
| 1 | require 'redcloth' |
| 2 | |
| 3 | class Page < ActiveRecord::Base |
| 4 | WIKI_WORD = /\b([A-Z][a-z]+(?:[A-Z][a-z]+)+)\b/ |
| 5 | |
| 6 | validates_presence_of :name |
| 7 | validates_uniqueness_of :name |
| 8 | validates_format_of :name, :with => /^#{WIKI_WORD.source}$/, |
| 9 | :message => "must be a WikiWord" |
| 10 | |
| 11 | def to_html |
| 12 | html = RedCloth.new(body.to_s).to_html |
| 13 | html.gsub!(/<\/?script[^>]*>/i, '') |
| 14 | html.gsub!(/\son\w+\s*=/i, ' x-nope=') |
| 15 | html.gsub(WIKI_WORD) { "<a href=\"/wiki/show/#{$1}\">#{$1}</a>" } |
| 16 | end |
| 17 | end |