From 8421cf6d72e548cb9301060a0c1e28df7f76a6d0 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 24 Feb 2023 13:00:01 +0000 Subject: [PATCH] DEV: Add rails engine and file paths to skeleton (#29) --- .../my_plugin_module/examples_controller.rb | 11 +++++++++++ config/routes.rb | 8 ++++++++ lib/my_plugin_module/engine.rb | 9 +++++++++ plugin.rb | 10 +++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/controllers/my_plugin_module/examples_controller.rb create mode 100644 config/routes.rb create mode 100644 lib/my_plugin_module/engine.rb 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