Plugin using own gem


(Kgish) #1

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?


(cpradio) #2

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:


(Kgish) #3

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)

(Gerhard Schlager) #4

Did you run bundle install after adding the gem?


(cpradio) #5

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


(Alan Tan) #6

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

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.


Specifying the gem dependecies for plugin - gem does not exist
(Jay Pfaffman) #7

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.


(Kgish) #8

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


(Jay Pfaffman) #9

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.


(Kgish) #10

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


(Jay Pfaffman) #11

I’m very interested in seeing your code!