Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that my own importer works locally, on my machine #412

Closed
nicktmro opened this issue May 25, 2019 · 4 comments
Closed

Check that my own importer works locally, on my machine #412

nicktmro opened this issue May 25, 2019 · 4 comments

Comments

@nicktmro
Copy link
Contributor

Hi all,

I am not a ruby dev so please keep that in mind.

TL;DR
How can I check that a plugin I wrote actually does what I want it to do? How can invoke or run in Terminal / Console the jekyll-import and pass as a parameter my new importer?

Details
I want to extend the behaviour of the RSS importer. I manually edited the /Library/Ruby/Gems/2.3.0/gems/jekyll-import-0.18.1/lib/jekyll-import/importers/rss.rb file and saved my changes and it definitely does what I want it to do.

Now this is obviously more than hacky, so I'd like to create a plugin that does what I want it to do (rss_podcast). I followed the instructions on the Contributing page on the jekyll-import website but I cannot find a script/console command anywhere to check that the plugin I wrote actually works alongside the other plugins.

Thanks a bunch!

@ashmaroli
Copy link
Member

Couple of stuff:

  • Never make changes to files within an existing gem. Its not easy to keep track of the bugs you may introduce and forget.
  • Clone this repository and make your changes in that clone.
  • There is no script/console. (The documentation needs updating..)
  • Since your importer is based on an existing importer, you can simply inherit your importer from the existing one:
    # New importer in a new file:
    # lib/jekyll-import/importers/rss_podcast.rb
    module JekyllImport
      module Importers
        class RSSPodcast < RSS
          # add just those methods (entire definition) that are being changed
        end
      end
    end
  • Then test it as documented at https://import.jekyllrb.com/docs/rss/ replacing the RSS Importer with yours.

@nicktmro
Copy link
Contributor Author

Thanks for the reply, @ashmaroli. I agree that what I did is super bad, which is why I came to ask for help.

Can you please describe / share the command I need to issue in order to run my extension of the importer?

Like I said, I'm not a ruby dev, but I thought that running the command from the link you shared would ignore my local changes and would not fail to find the rss_podcast.rb file in the path?

Basically, what do I need to run instead of this (how can i specify the path to my local implementation?):

$ ruby -r rubygems -e 'require "jekyll-import";
    JekyllImport::Importers::RSSPodcast.run({
      "source" => "my_file.xml"
    })'

@ashmaroli
Copy link
Member

Running Ruby with -I will let you set the $LOAD_PATH:

$ ruby -I lib -r rubygems -e 'require "jekyll-import";
    JekyllImport::Importers::RSSPodcast.run({
      "source" => "my_file.xml"
    })'

Alternatively, paste the code into a fresh file and run it directly:

# ./run_importer.rb

$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
require 'jekyll-import'

JekyllImport::Importers::RSSPodcast.run(
  "source" => ARGV[0] || 'my_file.xml'
)
$ ruby ./run_importer.rb my_backup.xml

@nicktmro
Copy link
Contributor Author

This worked great. Thank you!

ruby -I lib -r rubygems -e 'require "jekyll-import";
JekyllImport::Importers::RSSPodcast.run({
"source" => "my_file.xml"
})'

@jekyll jekyll locked and limited conversation to collaborators May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants