FIX: adding a custom emoji needed an application restart to work on the server-side rendering

This commit is contained in:
Régis Hanol 2015-01-29 17:35:52 +01:00
parent b5a6193d36
commit 3a24df6956
3 changed files with 9 additions and 10 deletions

View File

@ -76,19 +76,13 @@ module PrettyText
)
Dir["#{app_root}/app/assets/javascripts/discourse/dialects/**.js"].sort.each do |dialect|
unless dialect =~ /\/dialect\.js$/
ctx.load(dialect)
end
ctx.load(dialect) unless dialect =~ /\/dialect\.js$/
end
# custom emojis
# emojis
emoji = ERB.new(File.read("#{app_root}/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb"))
ctx.eval(emoji.result)
Emoji.custom.each do |emoji|
ctx.eval("Discourse.Dialect.registerEmoji('#{emoji.name}', '#{emoji.url}');")
end
# Load server side javascripts
if DiscoursePluginRegistry.server_side_javascripts.present?
DiscoursePluginRegistry.server_side_javascripts.each do |ssjs|
@ -102,8 +96,8 @@ module PrettyText
end
end
ctx['quoteTemplate'] = File.open(app_root + 'app/assets/javascripts/discourse/templates/quote.hbs') {|f| f.read}
ctx['quoteEmailTemplate'] = File.open(app_root + 'lib/assets/quote_email.hbs') {|f| f.read}
ctx['quoteTemplate'] = File.read("#{app_root}/app/assets/javascripts/discourse/templates/quote.hbs")
ctx['quoteEmailTemplate'] = File.read("#{app_root}/lib/assets/quote_email.hbs")
ctx.eval("HANDLEBARS_TEMPLATES = {
'quote': Handlebars.compile(quoteTemplate),
'quote_email': Handlebars.compile(quoteEmailTemplate),
@ -160,6 +154,11 @@ module PrettyText
end
end
# custom emojis
Emoji.custom.each do |emoji|
context.eval("Discourse.Dialect.registerEmoji('#{emoji.name}', '#{emoji.url}');")
end
context.eval('opts["mentionLookup"] = function(u){return helpers.is_username_valid(u);}')
context.eval('opts["lookupAvatar"] = function(p){return Discourse.Utilities.avatarImg({size: "tiny", avatarTemplate: helpers.avatar_template(p)});}')
baked = context.eval('Discourse.Markdown.markdownConverter(opts).makeHtml(raw)')