Beginner's Guide to Creating Discourse Plugins - Part 1

plugins

#24

I mean that getting through the first 4 pages proved doable for me, and this was all late lastnite and today. So it’s not an issue of outdated info.

That’s where I’m stuck.

Are you doing a hard refresh? On chrome I’m hitting ctrl-f5 after restarting rails.


(Tyler Thrailkill) #25

Dang. Well I can’t even get past this first tutorial.


#26

We’re equally noobish in the grand scheme, don’t feel bad. Let’s get you to where I’m at see if you can push both of us passed.


(Mittineague) #27

Does this solve it for you?


(Tyler Thrailkill) #28

finally got it working, no clue what changed but the last few commands I ran were (as the vagrant user in the vagrant vm) rm -rf tmp and then sudo rm -rf /tmp

I feel I should stress that I ran these commands maybe 20 times before this time and in none of the previous tries did this work.


#29

Perhaps discourse was continuously writing files to tmp directory for some reason?

At any rate I wrote a line in /etc/crontab to nuke the tmp directory every second :smile:

Just got my server properly setup with ubuntu 16.04 so going to try page 5 again, someone wrote a reply apparently the instructions were incorrect.

Looks like we’re both making progress :+1:

This is what I eventually stumbled on to make it work:

http://ubuntuforums.org/showthread.php?t=2263316

Would have taken me a week to figure all that out on my own.


#30

Thanks for this great set of tutorials. I’m working on a first plugin and I can’t seem to get my head around what I can and can’t call (or even how to do so)

I have a couple of custom fields on user that I want to have the user be able to edit. I’d like to use the input on those fields to create a button on the User profile or User card (thinking of a follow me on service x type button). When I access Discourse.User.current().custom_fields via browser console I just get an empty object. What are the other ways I can access those custom_fields on the User?


(Mittineague) #31

That sounds a bit more advanced than “beginner”

Anyway, did you manage to get the plugin to show in the Admin Plugins list and the alert() to work?

Have you worked through the other tutorials in the series successfully?


#32

I did get that alert() to work. I have looked through but not completed all of the tuts.


(Mittineague) #33

Great!

I think once you get through the others and if you install the data explorer plugin

You’'ll be in a good place.


#34

Great! I did get a snippet to pull the data I was looking for a single user :slightly_smiling:

{"user_field_1"=>"WarbleSync"}

Next step is figuring out how to access that for all users. Then I need to figure out how to listen for save and updates on that set of fields. Then maybe I can worry about how to add the buttons :slight_smile:

My forum is a gaming forum so I’m trying to write a plug to allow a user to enter their in a Steam user name or ID and then use that to generate a “Add me on Steam button” to the user card and/or profile. I know I can accomplish it I just have to figure out how this stuff works :smile:

I did try to install the discourse-data-explorer but it borked my plugins in my dev environment. I just cloned the git into plugins folder which may not be the recommend method of install. May be because my dev env is local too.


(Angus McLeod) #35

@eviltrout I’ve been meaning to ask this for a while…

What’s the difference between the initializers and pre-initializers folders?

Putting my initialize() function in the pre-initializers folder seems to make it work more reliably. (e.g.).

Is this recommended?


(Robin Ward) #36

What do you mean more reliably?

The distinction was made because at one point Ember changed the way and order that initializers were loaded. I created pre initializers a backwards compatible way of allowing plugins to work.

I didn’t think any plugins would need to use a pre-initializer though - so far none of mine have needed it. I’ve only needed to use them for discourse internals.


(Angus McLeod) #37

Yes sorry, I was a bit pressed for time this morning.

What specifically led to this question was that Topic Ratings stopped working with the latest Discourse code.

If you check it out locally and rename the /pre-initializers folder to /initializers, none of the changes to the composer controller take (stick a console.log in any of the functions and nothing will fire - no errors show up either). If you change it back to /pre-initializers and refresh it will work as normal.

While there are other possible causes, the folder name change also may have fixed the issue for the bug reporter.

The initialize() function is actually running when the ratings-edits.js.es6 file is in /initializers (if you stick a console.log right before the ComposerController.reopen it will fire). However none of the edits in the reopen function are being applied.

The Topics Ratings plugin was working fine using just /initializers until recently. The plugin itself hasn’t changed.

I did notice that @joebuhlig uses the pre-initializers folder for Feature Voting as well.

All that said, I use the /initializers folder without problem in my other plugins.


(Robin Ward) #38

That’s odd because the error reported for the Topic Ratings plugin was server side, not client side!

The issue is probably the load order of your initializer. You aren’t supplying one, so it’s up to Ember to decide when the initializer should be loaded, and you might be depending on something that isn’t initialized yet.

You might want to try adding after: 'inject-objects' or maybe after: 'message-bus' and try again.

If that doesn’t work I might have to install it locally and try myself :slight_smile:


(Angus McLeod) #39

Thanks. I tried those hooks, but neither worked.

By trial and error (i.e. successively checking out older commits), I’ve narrowed down my issue to this merge by @tgxworld:

Prior to that merge commit, the ComposerController.reopen function in my initialize function works fine in the initializers folder. After that commit my initialize function has to be in pre-initializers for the ComposerController.reopen function to work.

I’ll investigate this a bit more later today or tomorrow.


(Robin Ward) #40

I actually ran into issues related to the same thing in my new ES6 branch.

The problem is that the details plugin and poll builder were calling lookup instead of lookupFactory, which was causing a new controller to be created after it was already decorated with new stuff.

In my branch I’ve fixed it by replacing with lookupFactory. It should be merged in on Monday. But if you want to before that, feel free to update to lookupFactory locally :slight_smile:


(Chris Beach) #41

UPDATED - see bottom of post

Apologies in advance - n00b here.

I’m on a Mac and love the Docker deployment mechanism for Discourse. I was hoping I’d be able use this when developing a plugin. I tried using a “volume” to link my fledgling plugin from my Mac filesystem into the docker container like so:

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log
  - volume:
      host: /Users/chris/Development/discourse-plugin-stripe
      guest: /var/www/discourse/plugins/discourse-plugin-stripe

I thought this might allow me to edit plugin code in an IDE on my Mac, while running Discourse in Docker to test it as I code.

However, when I tried ./launcher rebuild app I got a load of permissions errors which prevented the rebuild:

I, [2016-07-06T21:06:08.196890 #14]  INFO -- : > cd /var/www/discourse && chown -R discourse /var/www/discourse
chown: changing ownership of '/var/www/discourse/plugins/discourse-plugin-stripe/.git/objects/5e/1422c9c3f1ddaae47b5b1b597bc80748611993': Permission denied
chown: changing ownership of '/var/www/discourse/plugins/discourse-plugin-stripe/.git/objects/6c/4fb1c84c54a20a0d50facf10d4a18582956116': Permission denied
...

The perms for these files on my Mac are chris:staff -r--r--r--:

root:/var/discourse $ ls -la /Users/chris/Development/discourse-plugin-stripe/.git/objects/5e/1422c9c3f1ddaae47b5b1b597bc80748611993
-r--r--r--  1 chris  staff  614 Jul  6 12:47 /Users/chris/Development/discourse-plugin-stripe/.git/objects/5e/1422c9c3f1ddaae47b5b1b597bc80748611993

UPDATED: I changed the volume to:

  - volume:
      host: /Users/chris/Development/discourse-plugin-stripe
      guest: /var/discourse-plugins/discourse-plugin-stripe

Then I added a step to the plugin setup commands:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/PoloGT/abbreviation-discourse-plugin.git
          - ln -snf /var/discourse-plugins/discourse-plugin-stripe discourse-plugin-stripe

This has got me further - I’m now able to rebuild the app.


(dtbaker) #42

I just made my first plugin and ./launcher rebuild app took a good 4-5 minutes to run. Is there any way I can edit the “live” plugin code (js/css) just to test things out without having to rebuild the whole thing?


(OG) #43

You need to install development environment: Beginners Guide to Install Discourse on Ubuntu for Development