Can change TOS content via site content editor

This commit is contained in:
Robin Ward
2013-04-05 15:21:55 -04:00
parent af9b27358c
commit 72b4f41254
8 changed files with 80 additions and 24 deletions

View File

@ -4,19 +4,36 @@ module SiteContentClassMethods
@types || []
end
def content_type(content_type, format, opts=nil)
def find_content_type(ct)
SiteContent.content_types.find {|t| t.content_type == ct.to_sym}
end
def add_content_type(content_type, opts=nil)
opts ||= {}
@types ||= []
format = opts[:format] || :markdown
@types << SiteContentType.new(content_type, format, opts)
end
def content_for(content_type, replacements=nil)
replacements ||= {}
replacements = SiteSetting.settings_hash.merge!(replacements)
site_content = SiteContent.select(:content).where(content_type: content_type).first
return "" if site_content.blank?
site_content.content % replacements
result = ""
if site_content.blank?
ct = find_content_type(content_type)
result = ct.default_content if ct.present?
else
result = site_content.content
end
result.gsub!(/\%\{[^}]+\}/) do |m|
replacements[m[2..-2].to_sym] || m
end
result
end