//depot/projects/wiki/app/models/page.rb#1 – add change 171 (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(WIKI_WORD) { "<a href=\"/wiki/show/#{$1}\">#{$1}</a>" } |
| 14 | end |
| 15 | end |