How do you learn to build Discourse plugins?

It seems like you’re asking for the conceptual viewpoint of how to build a plugin over the technical. I can’t say that I see myself as a great example of how to do it the right way, but here’s what I would suggest:

  1. Go through @eviltrout’s guide to building plugins and do every step. No skipping. This will give you a foundation of how to get started with a plugin and teach the core processes that you’ll need later.
  2. Pay attention to how things are done in core. What elements are used repeatedly? How do they use buttons, navigation, links, etc…? This will pay huge dividends later when you have an idea and want to know how to do it. Which brings me to 3.
  3. Learn how to trace code. When you see an element or want to use something from core (like the methods used to create new color themes in Customize), you need to know how to search the repository for the handlebars template that generates the html and trace it all the way back to the Rails routes or vice versa. If you can nail down every file and piece of code that is run to generate the front-end, you’re set up to duplicate a LOT without needing to write it all from scratch.
  4. Develop ninja skills when searching on GitHub. Knowing how to search for a code snippet within a given path in the repo or searching across repos within an organization are huge for me.
  5. Get really good with developer tools. It’s rare that I have an issue with code that I can’t decipher with the Chrome developer tools. Add the Ember Inspector extension to Chrome and pull up Meta. Open the composer, navigate to profiles, do stuff. And pay attention to how things move and change as you interact with the application. Pro tip: The network tab will give you tons of clues about how to pass data back and forth between Ruby and Ember.
  6. Read the code for other plugins. We’re all learning new ways to build plugins as we go. Cruise through the code of your favorite plugins and see how they’re doing things. This will help you translate the core code into plugin code.
  7. Just keep building. The more you try to build, the more you’ll learn how to build, and the better at building them you’ll become. We all start somewhere and we’re all still growing. Build something and share it.
  8. Don’t be afraid to ask. Sometimes it’s intimidating to post a question to something you feel is obvious. Do some searches and if you can’t find the answer, post it. Tell us what you’ve tried and where you’re stuck. We’re all problem-solving together.

That’s what I’ve got. I hope that’s along the lines you were looking for. If not, let me know. I’d love to help others get going with Discourse plugins. There’s a lot of power in being able to customize and tweak your own site via custom code.

29 Likes