This repository has been archived by the owner on Aug 15, 2018. It is now read-only.
/
content_section.rb
82 lines (67 loc) · 1.98 KB
/
content_section.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require File.join(RAILS_ROOT, "lib", "ansuz", "plugin_settings.rb")
module Ansuz
module JAdams
class ContentSection < ActiveRecord::Base
include Ansuz::PluginSettings
before_save :set_default_content_section_type
CONTENT_SECTION_TYPES = ["FCKeditor", "Markdown", "Textile"]
has_settings
# Prevent bad things ™ from happening on initial rake db:migrate -james
begin
# It actually caused bad things when running rake db:create:all -josh
if( ActiveRecord::Base.connection.tables.include?("content_sections"))
acts_as_versioned
end
rescue
end
def self.admin_partial
"/admin/content_sections/edit"
end
def edit_path
"/admin/content_sections/#{id}/edit"
end
def self.view_partial
"/admin/content_sections/content_section"
end
def view_partial
self.class.view_partial
end
def content_type=(val)
self.settings[:content_section_type] = CONTENT_SECTION_TYPES.detect{|t| t == val.to_s }
end
def content_type
self.settings[:content_section_type]
end
def markdown?
self.content_type == "Markdown"
end
def fckeditor?
self.content_type == "FCKeditor"
end
def textile?
self.content_type == "Textile"
end
def to_html
if( self.markdown? )
return BlueCloth.new( self.contents ).to_html
end
if( self.textile? )
return RedCloth.new( self.contents ).to_html
end
if ( self.fckeditor? )
return self.contents
end
end
# Read the global setting or default to FCKeditor
def default_content_type
ContentSection.plugin_settings[:content_type] || "FCKeditor"
end
protected
def set_default_content_section_type
if( self.content_type.nil? )
self.content_type = default_content_type
end
end
end
end
end