avoid calling v8 multiple times ( makes certain testing simpler)

This commit is contained in:
Sam 2013-08-16 13:03:47 +10:00
parent 9a2f758a00
commit be4b326f46
1 changed files with 10 additions and 8 deletions

View File

@ -128,6 +128,7 @@ module PrettyText
end end
def self.v8 def self.v8
return @ctx if @ctx return @ctx if @ctx
# ensure we only init one of these # ensure we only init one of these
@ -145,15 +146,16 @@ module PrettyText
baked = nil baked = nil
@mutex.synchronize do @mutex.synchronize do
context = v8
# we need to do this to work in a multi site environment, many sites, many settings # we need to do this to work in a multi site environment, many sites, many settings
v8.eval("Discourse.SiteSettings = #{SiteSetting.client_settings_json};") context.eval("Discourse.SiteSettings = #{SiteSetting.client_settings_json};")
v8.eval("Discourse.BaseUrl = 'http://#{RailsMultisite::ConnectionManagement.current_hostname}';") context.eval("Discourse.BaseUrl = 'http://#{RailsMultisite::ConnectionManagement.current_hostname}';")
v8.eval("Discourse.getURL = function(url) {return '#{Discourse::base_uri}' + url};") context.eval("Discourse.getURL = function(url) {return '#{Discourse::base_uri}' + url};")
v8['opts'] = opts || {} context['opts'] = opts || {}
v8['raw'] = text context['raw'] = text
v8.eval('opts["mentionLookup"] = function(u){return helpers.is_username_valid(u);}') context.eval('opts["mentionLookup"] = function(u){return helpers.is_username_valid(u);}')
v8.eval('opts["lookupAvatar"] = function(p){return Discourse.Utilities.avatarImg({size: "tiny", avatarTemplate: helpers.avatar_template(p)});}') context.eval('opts["lookupAvatar"] = function(p){return Discourse.Utilities.avatarImg({size: "tiny", avatarTemplate: helpers.avatar_template(p)});}')
baked = v8.eval('Discourse.Markdown.markdownConverter(opts).makeHtml(raw)') baked = context.eval('Discourse.Markdown.markdownConverter(opts).makeHtml(raw)')
end end
# we need some minimal server side stuff, apply CDN and TODO filter disallowed markup # we need some minimal server side stuff, apply CDN and TODO filter disallowed markup