DEV: Allow plugins to register Onebox handlers (#16870)

This targets only the local Oneboxes and allows plugins to customize
regular or inline Oneboxes for routes inside the site.
This commit is contained in:
Bianca Nenciu
2022-05-23 20:02:02 +03:00
committed by GitHub
parent 28573b504f
commit 6c8f491dc3
4 changed files with 46 additions and 0 deletions

View File

@@ -21,6 +21,14 @@ class InlineOneboxer
Discourse.cache.read(cache_key(url))
end
def self.local_handlers
@local_handlers ||= {}
end
def self.register_local_handler(controller, &handler)
local_handlers[controller] = handler
end
def self.lookup(url, opts = nil)
opts ||= {}
opts = opts.with_indifferent_access
@@ -46,6 +54,8 @@ class InlineOneboxer
# not permitted to see topic
return nil
end
elsif handler = local_handlers[route[:controller]]
return handler.call(url, route)
end
end