FEATURE: Allow multiple html builders to be registered via plugins
This commit is contained in:
parent
93633865d9
commit
2f0c9793f1
|
@ -465,9 +465,9 @@ class ApplicationController < ActionController::Base
|
|||
data.merge! DiscoursePluginRegistry.custom_html
|
||||
end
|
||||
|
||||
DiscoursePluginRegistry.html_builders.each do |name, blk|
|
||||
DiscoursePluginRegistry.html_builders.each do |name, _|
|
||||
if name.start_with?("client:")
|
||||
data[name.sub(/^client:/, '')] = blk.call(self)
|
||||
data[name.sub(/^client:/, '')] = DiscoursePluginRegistry.build_html(name, self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -137,11 +137,13 @@ class DiscoursePluginRegistry
|
|||
end
|
||||
|
||||
def self.register_html_builder(name, &block)
|
||||
html_builders[name] = block
|
||||
html_builders[name] ||= []
|
||||
html_builders[name] << block
|
||||
end
|
||||
|
||||
def self.build_html(name, ctx = nil)
|
||||
html_builders[name]&.call(ctx)
|
||||
builders = html_builders[name] || []
|
||||
builders.map { |b| b.call(ctx) }.join("\n")
|
||||
end
|
||||
|
||||
def javascripts
|
||||
|
|
|
@ -51,6 +51,13 @@ describe DiscoursePluginRegistry do
|
|||
DiscoursePluginRegistry.reset!
|
||||
expect(DiscoursePluginRegistry.build_html(:my_html)).to be_blank
|
||||
end
|
||||
|
||||
it "can register multiple builders" do
|
||||
DiscoursePluginRegistry.register_html_builder(:my_html) { "one" }
|
||||
DiscoursePluginRegistry.register_html_builder(:my_html) { "two" }
|
||||
expect(DiscoursePluginRegistry.build_html(:my_html)).to eq("one\ntwo")
|
||||
DiscoursePluginRegistry.reset!
|
||||
end
|
||||
end
|
||||
|
||||
context '.register_css' do
|
||||
|
|
Loading…
Reference in New Issue