mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:25:24 +08:00
Can change TOS content via site content editor
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user