mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: HTML Builders should respect if a plugin is enabled or not (#8454)
Previously they would return the HTML regardless of whether the plugin was enabled or not.
This commit is contained in:
@ -418,7 +418,10 @@ class Plugin::Instance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def register_html_builder(name, &block)
|
def register_html_builder(name, &block)
|
||||||
DiscoursePluginRegistry.register_html_builder(name, &block)
|
plugin = self
|
||||||
|
DiscoursePluginRegistry.register_html_builder(name) do |*args|
|
||||||
|
block.call(*args) if plugin.enabled?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_asset(file, opts = nil)
|
def register_asset(file, opts = nil)
|
||||||
|
@ -32,7 +32,10 @@ describe Plugin::Instance do
|
|||||||
|
|
||||||
context "with a plugin that extends things" do
|
context "with a plugin that extends things" do
|
||||||
|
|
||||||
class Trout; end
|
class Trout
|
||||||
|
attr_accessor :data
|
||||||
|
end
|
||||||
|
|
||||||
class TroutSerializer < ApplicationSerializer
|
class TroutSerializer < ApplicationSerializer
|
||||||
attribute :name
|
attribute :name
|
||||||
|
|
||||||
@ -90,7 +93,6 @@ describe Plugin::Instance do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "checks enabled/disabled functionality for extensions" do
|
it "checks enabled/disabled functionality for extensions" do
|
||||||
|
|
||||||
# with an enabled plugin
|
# with an enabled plugin
|
||||||
@plugin.enabled = true
|
@plugin.enabled = true
|
||||||
expect(@trout.status?).to eq("evil")
|
expect(@trout.status?).to eq("evil")
|
||||||
@ -114,6 +116,17 @@ describe Plugin::Instance do
|
|||||||
expect(@child_serializer.include_scales?).to eq(false)
|
expect(@child_serializer.include_scales?).to eq(false)
|
||||||
expect(@child_serializer.name).to eq("a trout jr")
|
expect(@child_serializer.name).to eq("a trout jr")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "only returns HTML if enabled" do
|
||||||
|
ctx = Trout.new
|
||||||
|
ctx.data = "hello"
|
||||||
|
|
||||||
|
@plugin.register_html_builder('test:html') { |c| "<div>#{c.data}</div>" }
|
||||||
|
@plugin.enabled = false
|
||||||
|
expect(DiscoursePluginRegistry.build_html('test:html', ctx)).to eq("")
|
||||||
|
@plugin.enabled = true
|
||||||
|
expect(DiscoursePluginRegistry.build_html('test:html', ctx)).to eq("<div>hello</div>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user