Sha256: 950d6425c80b121866bdaccbfec459dec8b17153b93dce5ff0d4f7b9bc10e36d

Contents?: true

Size: 1.48 KB

Versions: 14

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

# For use/testing when no gem is installed
$LOAD_PATH.unshift __dir__

require "rubygems"
require "jekyll"
require "jekyll/commands/import"
require "colorator"

require "jekyll-import/importer"
require "jekyll-import/importers"
require "jekyll-import/util"

module JekyllImport
  # Public: Add the subcommands for each importer
  #
  # cmd - the instance of Mercenary::Command from the
  #
  # Returns a list of valid subcommands
  def self.add_importer_commands(cmd)
    commands = []
    JekyllImport::Importer.subclasses.each do |importer|
      name = importer.to_s.split("::").last.downcase
      commands << name
      cmd.command(name.to_sym) do |c|
        c.syntax "#{name} [options]"
        importer.specify_options(c)
        c.action do |_, options|
          importer.run(options)
        end
      end
    end
    commands
  end

  def self.require_with_fallback(gems)
    Array[gems].flatten.each do |gem|
      begin
        require gem
      rescue LoadError
        Jekyll.logger.error "Whoops! Looks like you need to install '#{gem}' before you can use this importer."
        Jekyll.logger.error ""
        Jekyll.logger.error "If you're using bundler:"
        Jekyll.logger.error "  1. Add 'gem \"#{gem}\"' to your Gemfile"
        Jekyll.logger.error "  2. Run 'bundle install'"
        Jekyll.logger.error ""
        Jekyll.logger.error "If you're not using bundler:"
        Jekyll.logger.abort_with "  1. Run 'gem install #{gem}'."
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
jekyll-import-0.24.0 lib/jekyll-import.rb
jekyll-import-0.23.0 lib/jekyll-import.rb
jekyll-import-0.22.0 lib/jekyll-import.rb
jekyll-import-0.21.0 lib/jekyll-import.rb
jekyll-import-0.20.0 lib/jekyll-import.rb
jekyll-import-0.19.2 lib/jekyll-import.rb
jekyll-import-0.19.1 lib/jekyll-import.rb
jekyll-import-0.19.0 lib/jekyll-import.rb
jekyll-import-0.18.1 lib/jekyll-import.rb
jekyll-import-0.18.0 lib/jekyll-import.rb
jekyll-import-0.17.1 lib/jekyll-import.rb
jekyll-import-0.17.0 lib/jekyll-import.rb
jekyll-import-0.16.0 lib/jekyll-import.rb
jekyll-import-0.15.0 lib/jekyll-import.rb