Plugin using own gem

I am developing a plugin that needs to use an external gem, namely docx in order to generate word docs.

Is there someway to do this or do I have to append it to the Gemfile?

إعجاب واحد (1)

There is a way to do it. You put the following in your plugin.rb file

gem 'omniauth-linkedin-oauth2', '0.1.5'

Example of usage:
https://github.com/discourse/discourse-plugin-linkedin-auth/blob/master/plugin.rb

4 إعجابات

Thanks, gave it a go but get the following error message:

/home/kiffin/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'rubyzip' (~> 1.1.6) among 186 total gem(s) (Gem::LoadError)

Did you run bundle install after adding the gem?

Yeah on your dev machine you will have to do bundle install. Docker does that for you, I believe.

Gems declared in a plugin are installed and loaded differently as per our implementation:

https://github.com/discourse/discourse/blob/master/lib/plugin/instance.rb#L353-L381

In order to get it to work, you’ll have to specify all the gem’s dependencies which are not already included in the Gemfile.

8 إعجابات

What’s your plugin going to do? I’ve got a client who would love to be able to export a topic as a Word document.

I’ve created a plugin that does just that, click on the word-icon, interested?

إعجاب واحد (1)

I"m sure she will be. I just wrote a Ruby program that takes either a topic or category URL on the command line and downloads a topic (or all of them in the category) as a sort-of MBOX file with headers like these:

From username 1365 2016-07-18T02:20:41.074Z
Name: Jay User (username)
Subject: Week 7 Discussion
Date: 2016-07-28T02:20:41.074Z
Post: 10
Reply-to: 9
Num-Replies: 0
Read-time: 30
Times-read: 21
Post-URL: https://literatecomputing.com/t/79/10

followed by either the HTML or the raw Markdown text.

I guess that’s one way of doing it. My method however does something similar and delivers the generated doc directly to the user.

إعجاب واحد (1)

I’m very interested in seeing your code!