DEV: Remove unused DiscoursePlugin class (#9715)

This commit is contained in:
David Taylor 2020-05-11 15:46:54 +01:00 committed by GitHub
parent addf9d62f8
commit 5fc51ed49c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 115 deletions

View File

@ -23,7 +23,6 @@ require 'sprockets/railtie'
# Plugin related stuff
require_relative '../lib/plugin_initialization_guard'
require_relative '../lib/discourse_event'
require_relative '../lib/discourse_plugin'
require_relative '../lib/discourse_plugin_registry'
require_relative '../lib/plugin_gem'

View File

@ -1,52 +0,0 @@
# frozen_string_literal: true
# A basic plugin for Discourse. Meant to be extended and filled in.
# Most work is delegated to a registry.
class DiscoursePlugin
attr_reader :registry
def initialize(registry)
@registry = registry
end
def setup
# Initialize the plugin here
end
# Loads and mixes in the plugin's mixins into the host app's classes.
# A mixin named "UserMixin" will be included into the "User" class.
def self.include_mixins
mixins.each do |mixin|
original_class = mixin.to_s.demodulize.sub("Mixin", "")
dependency_file_name = original_class.underscore
require_dependency(dependency_file_name)
original_class.constantize.public_send(:include, mixin)
end
end
# Find the modules defined in the plugin with "Mixin" in their name.
def self.mixins
constants.map { |const_name| const_get(const_name) }
.select { |const| const.class == Module && const.name["Mixin"] }
end
def register_js(file, opts = {})
@registry.register_js(file, opts)
end
def register_css(file, plugin_directory_name)
@registry.register_css(file, plugin_directory_name)
end
def register_archetype(name, options = {})
@registry.register_archetype(name, options)
end
def listen_for(event_name)
return unless self.respond_to?(event_name)
DiscourseEvent.on(event_name, &self.method(event_name))
end
end

View File

@ -296,10 +296,4 @@ class DiscoursePluginRegistry
locales.clear
end
def self.setup(plugin_class)
registry = DiscoursePluginRegistry.new
plugin = plugin_class.new(registry)
plugin.setup
end
end

View File

@ -1,56 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe DiscoursePlugin do
class TestPlugin < DiscoursePlugin
module SomeModule
end
module TestMixin
end
end
let(:registry) { mock }
let(:plugin) { TestPlugin.new(registry) }
describe ".mixins" do
it "finds its mixins" do
expect(TestPlugin.mixins).to eq([TestPlugin::TestMixin])
end
end
it "delegates adding js to the registry" do
registry.expects(:register_js).with('test.js', any_parameters)
plugin.register_js('test.js')
end
it "delegates adding css to the registry" do
registry.expects(:register_css).with('test.css', 'test')
plugin.register_css('test.css', 'test')
end
it "delegates creating archetypes" do
registry.expects(:register_archetype).with('banana', oh: 'no!')
plugin.register_archetype('banana', oh: 'no!')
end
context 'registering for callbacks' do
before do
plugin.stubs(:hello)
@proc = plugin.listen_for(:hello).first
end
after do
DiscourseEvent.off(:hello, &@proc)
end
it "calls the method when it is triggered" do
plugin.expects(:hello).with('there')
DiscourseEvent.trigger(:hello, 'there')
end
end
end