support server side js and arbitrary assets

proper chaining for emoji so other hooks can be called
This commit is contained in:
Sam 2013-08-01 17:35:31 +10:00
parent d15083d3ee
commit 1132c10074
3 changed files with 19 additions and 3 deletions

View File

@ -106,6 +106,7 @@ Discourse.Markdown = {
});
converter.hooks.chain("preConversion", function(text) {
Discourse.Markdown.textResult = null;
Discourse.Markdown.trigger('beforeCook', { detail: text, opts: opts });
return Discourse.Markdown.textResult || text;
});

View File

@ -103,6 +103,16 @@ class Plugin
@javascripts << js
end
def register_asset(file,opts=nil)
full_path = File.dirname(path) << "/assets/" << file
assets << full_path
if opts == :server_side
@server_side_javascripts ||= []
@server_side_javascripts << full_path
end
end
def automatic_assets
css = ""
js = "(function(){"
@ -149,19 +159,24 @@ class Plugin
assets.concat auto_assets
end
unless assets.blank?
paths = []
assets.each do |asset|
if asset =~ /\.js$/
DiscoursePluginRegistry.javascripts << asset
elsif asset =~ /\.css$|\.scss$/
DiscoursePluginRegistry.stylesheets << asset
end
paths << File.dirname(asset)
end
# TODO possibly amend this to a rails engine
Rails.configuration.assets.paths << auto_generated_path
Rails.configuration.assets.paths << File.dirname(path) + "/assets"
end
if @server_side_javascripts
@server_side_javascripts.each do |js|
DiscoursePluginRegistry.server_side_javascripts << js
end
end
end
def auth_provider(type, opts)

View File

@ -4,7 +4,7 @@
// Regiest a before cook event
Discourse.Markdown.on("beforeCook", function(event) {
var text = event.detail;
var text = this.textResult || event.detail;
var opts = event.opts;
this.textResult = text.replace(/\:([a-z\_\+\-0-9]+)\:/g, function (m1, m2) {