The introduction series to Discourse plugins only touches the plugin outlet part. But how do I take that and integrate it with Discourse? I tried reading the source code of Discourse plugins, as Jeff suggested, But I only have questions like what does add_to_serializer or create_custom_field do ?
I also want to build amazing plugins / contribute to discourse⌠please let me know if you have any material on learning to create Discourse plugins.
Everything used by the plugins is defined in Discourse core⌠or by Rails, or by Ruby itself. Itâs open source all the way down, so if you donât know what add_to_serializer does, search the Discourse codebase for def add_to_serializer, and the learnings shall continue.
And how do you debug the discourse application? I am using byebug, but I was looking more into a debugger which can be easily integrated with the text editor like atom or brackets or visual studio code.
What you want is exactly what I want. I am completely lost as well. I was going to try a work around, but it seems that a plugin is the right way to do this. As there is no documentation, I will have to break the code to figure it out.
It took me a while to find it - maybe a link to the API topic could be added to the JavaScript section of the âBeginners guide to creating discourse pluginsâ @eviltrout
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:
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.
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.
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.
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.
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.
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.
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.
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.
The lack of documentation in some places has been the most frustrating part of using Discourse so far. If there were a way for the community to contribute to a simple documentation site (like sphinx/readthedocs), Iâd help write some of documentation as I figure things out. The documentation could be updated to point to the most relevant and current forum threads here for those tasks.
It would be useful to have one canonical entry point for learning how to build more complex plugins (not just âhello worldâ). A list of where to start looking for answers to common tasks would be useful. The sidebar for the API docs is a good example. At the moment, information is scattered over many different forum posts, and itâs difficult to find. Asking people who are new to Ruby, Rails, and Ember to âjust read the codeâ creates a significant barrier to entry for many.
Example: I want to override the log out functionality on Discourse (to add a POST request to another URL on-logout) but donât know where to look. I searched Github for Ruby files that handle log out and only found this, and it isnât clear how I would override the functionality there. Iâm too new to Ruby, Rails, and Ember to understand how itâs all wired together, so something that would only take a few hours with documentation ends up taking up days of time. Itâs not just reading the information that takes time â itâs mostly figuring where to even find it among years of scattered forum posts for various different versions and configurations of the software.
Isnât this already covered by the built in webhooks, in Admin, API, webhooks? We should have an on-user-logout webhook built in if we donât already cc @tgxworld
Is there any indication of what action is performed? When I try it, it POSTs JSON to a URL. The JSON contains information about the entity, but I donât see how to determine information like whether the user has logged in or out. Maybe it could be done with an extra key in the JSON?
{
"user": { // the type of event
// the main payload
},
"action": "login" // or logout, create, update, delete
}
(Feel free to move this post if it would fit better somewhere else in the forum.)