Plugin using own gem

AI-generated summary

The discussion revolves around developing a plugin using an external gem. kgish is developing a plugin that generates Word documents using the docx gem and seeks advice on how to include it. cpradio suggests adding the gem to the plugin.rb file, but kgish encounters a Gem::LoadError. gerhard and cpradio recommend running bundle install to resolve the issue. tgxworld explains that gems declared in plugins are installed and loaded differently and may require specifying additional dependencies.

The discussion takes a turn when pfaffman expresses interest in kgish’s plugin, which allows users to export topics as Word documents. kgish shares a screenshot of the plugin in action, and pfaffman describes a similar Ruby program they created. kgish notes the differences between their approaches, and pfaffman expresses interest in seeing kgish’s code.

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?

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:

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:

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.

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?

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.

I’m very interested in seeing your code!