# canvas-plugin-init > Initialize a new Canvas LMS plugin with GUI, API, Worker, and Course Navigation components. - Author: Kien - Repository: Kiennh/canvas-seb - Version: 20260210021946 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-10 - Source: https://github.com/Kiennh/canvas-seb - Web: https://mule.run/skillshub/@@Kiennh/canvas-seb~canvas-plugin-init:20260210021946 --- --- name: canvas-plugin-init description: Initialize a new Canvas LMS plugin with GUI, API, Worker, and Course Navigation components. --- # Canvas Plugin Initialization Skill This skill provides a standardized way to initialize a new plugin in Canvas LMS. It creates a robust starting point with GUI settings, a backend API, a background worker, and a customizable Course Navigation page with permissions. ## Features - **GUI (User Interface)**: Creates a `settings_partial` that displays a "Hello {{current_user}}" message and basic configuration fields. - **API Backend**: Sets up a controller in `app/controllers/api/v1/` and registers custom routes. - **Worker Job**: Implements a `Delayed::Job` compatible worker for background tasks. - **Course Navigation**: Adds a sample page to the Course menu (sidebar) that shows "Hello {{username}}, welcome to {{coursename}}". - **System Hooks (Canvas Extensions)**: Demonstrates how to hook into core Canvas logic using `Module#prepend` (example: `Quizzes::Quiz#generate_submission` to track quiz starts). - **Granular Permissions**: Registers a custom permission (`view__sample_page`) that can be configured in the Course/Account "Permissions" settings. - **Automatic Registration**: Updates `Gemfile.d/plugins.rb` to ensure the plugin is loaded by Canvas. ## Usage ### 1. Initialize a new plugin Use the `init_plugin.sh` script to scaffold the plugin. ```bash /bin/bash .agent/skills/canvas-plugin-init/scripts/init_plugin.sh ``` Example: ```bash /bin/bash .agent/skills/canvas-plugin-init/scripts/init_plugin.sh hello_world ``` ### 2. File Structure Created - `gems/plugins//.gemspec`: Gem specification. - `gems/plugins//lib//engine.rb`: Rails Engine, Permission registration, and Course Navigation extension. - `gems/plugins//app/views/plugins/__settings.html.erb`: Configuration GUI. - `gems/plugins//app/controllers/api/v1/_controller.rb`: API Backend. - `gems/plugins//app/controllers/course_sample_controller.rb`: Course Navigation controller. - `gems/plugins//app/views//course_sample/index.html.erb`: Course Navigation view. - `gems/plugins//config/pre_routes.rb`: Custom routes. - `gems/plugins//lib//worker.rb`: Background Worker. ### 3. Components Overview #### Course Navigation Extensions The skill uses `Course.prepend` to inject a custom tab into the `tabs_available` list. The tab only appears if the user has the registered permission for that course. #### Permissions Permissions are registered via `Permissions.register` in the engine's `to_prepare` block. They automatically appear in the Canvas Permissions UI under the name provided. #### GUI The settings partial is accessible via **Site Admin > Plugins > **. ## Requirements - Canvas LMS environment. - Sufficient permissions to create files in `gems/plugins/` and modify `Gemfile.d/plugins.rb`. ## Troubleshooting ### Missing partial plugins/__settings **Error:** ``` ActionView::MissingTemplate in Plugins#show Missing partial plugins/__settings ``` **Cause:** This error occurs when the plugin is registered with a `settings_partial` in the engine.rb file, but the corresponding partial view file doesn't exist. **Solution:** Ensure the settings partial exists at the correct location: ``` gems/plugins//app/views/plugins/__settings.html.erb ``` The `init_plugin.sh` script automatically creates this file. If you're creating a plugin manually or the file is missing, create it with the following structure: ```erb

<%= t(:_title, " Settings") %>

<%= t(:_description, "Configure settings.") %>

<%= fields_for :settings do |f| %>
<%= blabel :, :enabled, :en => "Enable Plugin" %> <%= f.check_box :enabled, :checked => Canvas::Plugin.value_to_boolean(settings[:enabled]) %>
<% end %> ``` **Key Points:** - The partial filename must start with an underscore (`_`) - The partial must be in the `app/views/plugins/` directory (not `app/views//`) - The `settings_partial` value in engine.rb should match: `"plugins/_settings"` (without underscore or .html.erb extension) - Use `fields_for :settings` to ensure form fields are properly namespaced