Rails plugin generator

I just finished creating a public version of this. That way others can use it as well and I can share links to specifics since I realized there are some more points that I do.

https://github.com/procourse/discourse-plugin-template

  • Whenever I add custom routes to a plugin, I always use a Constraint that ties to the plugin enabled setting. This prevents the routes from existing unless the site setting is true. I wish I saw this more in plugins as custom routes shouldn’t be allowed just because the plugin is installed.

  • This template includes a Rails controller and an Ember route. These are only used in about half of the plugins I do, but it’s nice to have them there just so the structure already exists. I don’t know that this generator needs to include these pieces, but it’s helpful on my end.

  • I always start my stylesheets with a global class selector. Every time I add HTML to the plugin, I start with a wrapper div with class="discourse-plugin-template". That ensures that my styles only apply to my custom code. Sometimes I need to add CSS outside of that selector, but it seems like most cases don’t have that requirement.

11 Likes