What is the proper way to structure Plugins?


(Mittineague) #1

OK, I confess that one way I learn is by “monkey see, monkey do”.

I have looked at a lot of plugins, and if they worked, analyzed them.

I have seen some that have only a single plugin.rb file with everything in it.
* OK for simple plugins I guess, but I’m not a big fan of this when they’re more complex.

And I understand that “.handlebars” files are now “.hbs”, that “.js” files are now “.js.es6”, and that these files are “auto-magically” included.
So I guess folder structure isn’t all that important? More so it makes sense than it is a necessity?

I’m guessing some of the variations I’m seeing differ depending on whether or not the plugins are doing things RoR or Ember.

I’n any case, I have in the past been known to be inconsistent in such things and have over the years made progress in getter better at being consistent.

If possible, I would like to know the “best practice” conventions so that I won’t at some point in the future feel the need to “unlearn” something.

Any pointers on what I should take a look at will be appreciated as I find something like the following confusing.

my-plugin/
  plugin.rb
  app/
    controllers/
      file_controller.rb
    helpers/
      file_helper.rb
    models/
      folder/
        file.rb
    views/
      file.js.es6
      folder/
        file.html.erb
  assets/
    javascripts/ 
      discourse/
        components/
          file.js.es6
        controllers/
	  file.js.es6
	initializers/
	  file.js.es6
	templates/
	  file.hbs
	views/
	  file.js.es6
	helpers/
	  file.js.es6	  
      initializers/
        file.js.es6	 
      stylesheets/
        file.scss  
  config/
    routes.rb
    settings.yml
    locales/
      client.en.yml
      server.en.yml

(Sam Saffron) #2

I think the folder structure matters especially for initializers / locales and so on.

I don’t know I worry that if we publish a best practice we are somehow binding ourself to that spec and we still are expecting to change a few things around plugins in the next few versions.


(Mittineague) #3

Thanks. Fair enough.

Yes, I’ve noticed they seem to be universally the same in the plugins I’ve looked at that have them.

I’ll go with what makes sense to me and works, keeping in mind that things may change.


(Erlend Sogge Heggen) #4

Can’t say I understand that rationale. Any greenhorn developer who is just starting out with Discourse development is going to want to rewrite their first plugin in 6 months anyways.

I think you’re hampering your developer adoption by putting these things off all the time.


(Robin Ward) #5

The folder structure matters a lot for Ember. It is used for ember to discover things. For example: controllers/widget.js.es6 will be what the container uses to find controller:widget when wiring up things automatically.

I agree, I really want to spend time writing this up. It is overdue. I am super swamped. I think we could write up some things that will not change (or change infrequently) and put in suggestions for others.


Definitive and Explicit Guide to Plugin Development is Needed