support server side js and arbitrary assets
proper chaining for emoji so other hooks can be called
This commit is contained in:
parent
d15083d3ee
commit
1132c10074
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue