-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
content_page.rb
52 lines (44 loc) · 1.08 KB
/
content_page.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'redcloth'
class ContentPage < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
attr_accessor :content_html
def self.find_for_permission(p_ids)
where('permission_id in (?)', p_ids)
.order(:name)
end
def url
"/#{self.name}"
end
def markup_style
if !@markup_style && markup_style_id && markup_style_id > 0
@markup_style = MarkupStyle.find markup_style_id
end
end
def before_save
self.content_cache = markup_content
end
def content_html
if content_cache && content_cache.length > 0
content_cache.html_safe
else
markup_content.html_safe
end
end
protected
def markup_content
markup = self.markup_style
if markup and markup.name
if markup.name == 'Textile'
content_html = RedCloth.new(self.content).to_html(:textile)
elsif markup.name == 'Markdown'
content_html = RedCloth.new(self.content).to_html(:markdown)
else
content_html = self.content
end
else
content_html = self.content
end
return content_html
end
end