diff --git a/app/controllers/my_plugin_module/examples_controller.rb b/app/controllers/my_plugin_module/examples_controller.rb new file mode 100644 index 0000000..9ca421b --- /dev/null +++ b/app/controllers/my_plugin_module/examples_controller.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module ::MyPluginModule + class ExamplesController < ::ApplicationController + requires_plugin PLUGIN_NAME + + def index + render json: { hello: "world" } + end + end +end diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..25a67c9 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +MyPluginModule::Engine.routes.draw do + get "/examples" => "examples#index" + # define routes here +end + +Discourse::Application.routes.draw { mount ::MyPluginModule::Engine, at: "my-plugin" } diff --git a/lib/my_plugin_module/engine.rb b/lib/my_plugin_module/engine.rb new file mode 100644 index 0000000..26e035c --- /dev/null +++ b/lib/my_plugin_module/engine.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module ::MyPluginModule + class Engine < ::Rails::Engine + engine_name PLUGIN_NAME + isolate_namespace MyPluginModule + config.autoload_paths << File.join(config.root, "lib") + end +end diff --git a/plugin.rb b/plugin.rb index f0bae53..b280a1c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -9,4 +9,12 @@ enabled_site_setting :plugin_name_enabled -after_initialize {} +module ::MyPluginModule + PLUGIN_NAME = "discourse-plugin-name" +end + +require_relative "lib/my_plugin_module/engine" + +after_initialize do + # Code which should run after Rails has finished booting +end