Sha256: 89d40cd2f8f00aad9aa673087f2e4867c571df970188471d189fc20ee84d936d

Contents?: true

Size: 1.76 KB

Versions: 95

Compression:

Stored size: 1.76 KB

Contents

module J1
  module External
    class << self
      #
      # Gems that, if installed, should be loaded.
      # Usually contain subcommands.
      # ------------------------------------------------------------------------
      def blessed_gems
        %w(
          jekyll-docs
          jekyll-import
        )
      end

      #
      # Require a gem or file if it's present, otherwise silently fail.
      #
      # names - a string gem name or array of gem names
      #
      def require_if_present(names)
        Array(names).each do |name|
          begin
            require name
          rescue LoadError
            J1.logger.debug "Couldn't load #{name}. Skipping."
            yield(name) if block_given?
            false
          end
        end
      end

      #
      # Require a gem or gems. If it's not present, show a very nice error
      # message that explains everything and is much more helpful than the
      # normal LoadError.
      #
      # names - a string gem name or array of gem names
      # ------------------------------------------------------------------------
      def require_with_graceful_fail(names)
        Array(names).each do |name|
          begin
            J1.logger.debug "Requiring:", name.to_s
            require name
          rescue LoadError => e
            J1.logger.error "Dependency Error:", <<-MSG
Yikes! It looks like you don't have #{name} or one of its dependencies installed.
In order to use Jekyll as currently configured, you'll need to install this gem.

The full error message from Ruby is: '#{e.message}'

If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
            MSG
            raise J1::Errors::MissingDependencyException, name
          end
        end
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
j1-template-2023.8.0 lib/j1/external.rb
j1-template-2023.7.0 lib/j1/external.rb
j1-template-2023.6.0 lib/j1/external.rb
j1-template-2023.5.2 lib/j1/external.rb
j1-template-2023.4.5 lib/j1/external.rb
j1-template-2023.4.4 lib/j1/external.rb
j1-template-2023.4.3 lib/j1/external.rb
j1-template-2023.4.2 lib/j1/external.rb
j1-template-2023.4.1 lib/j1/external.rb
j1-template-2023.4.0 lib/j1/external.rb
j1-template-2023.3.3 lib/j1/external.rb
j1-template-2023.3.2 lib/j1/external.rb
j1-template-2023.3.1 lib/j1/external.rb
j1-template-2023.3.0 lib/j1/external.rb
j1-template-2023.2.7 lib/j1/external.rb
j1-template-2023.2.6 lib/j1/external.rb
j1-template-2023.2.5 lib/j1/external.rb
j1-template-2023.2.4 lib/j1/external.rb
j1-template-2023.2.3 lib/j1/external.rb
j1-template-2023.2.2 lib/j1/external.rb