ruby - 在 github 页面中使用自定义 ruby​​ gem 会引发错误

标签 ruby rubygems jekyll github-pages gemfile

在运行 jekyll build 时,将自定义 gem 与 github-pages 一起使用会引发以下错误

C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/resolver.rb:356:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'tabs (= 0.0.3) x86-mingw32' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/resolver.rb:331:in `each'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/resolver.rb:331:in `verify_gemfile_dependencies_are_found!'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/resolver.rb:200:in `start'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/resolver.rb:184:in `resolve'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/definition.rb:200:in `resolve'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-3.2.1/lib/jekyll/plugin_manager.rb:36:in `require_from_bundler'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-3.2.1/exe/jekyll:9:in `<top (required)>'
    from C:/Ruby200/bin/jekyll:23:in `load'
    from C:/Ruby200/bin/jekyll:23:in `<main>'

我的 gem 文件

source "http://rubygems.org"
gem 'kramdown'
gem 'jekyll-sitemap'
gem 'nokogiri'
gem 'tabs', '0.0.3'
gem 'tabs-id', '0.0.1'

最后两颗 gem 是我创造的。

这是我的 ruby​​ gem 文件

require 'kramdown'
module Tags
    class TabsBlock < Liquid::Block
        def render(context)
            content = super(context)
            content = convert(content)
        end
        def convert(context)
            liArray = context.gsub(/<li role="presentation" class="">(.+)<\/li>/)
            nextLine = "\n"
            tabOpenTag = nextLine + '<div class="tabs">' + nextLine
            ulOpenTag = nextLine + '<ul class="nav nav-tabs" role="tablist">' + nextLine
            tabContentOpenTag = nextLine + '<div class="tab-content">' + nextLine
            closedivTag = nextLine + '</div>' + nextLine
            ulCloseTag = nextLine + '</ul>' + nextLine
            lis = '' + nextLine
            liArray.each do|li|
                lis = lis + li + nextLine
            end     
            return tabOpenTag + ulOpenTag + lis + ulCloseTag + tabContentOpenTag +context.gsub(/<li role="presentation" class="">(.+)<\/li>/,'') + closedivTag + ulCloseTag + closedivTag
        end
    end
end

Liquid::Template.register_tag("tabs", Tags::TabsBlock)

最佳答案

除了 gem github-pages 之外,您不能在 Github Pages 中使用任何其他 ruby​​ gem。

您的 Gemfile 应该阅读:

source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins

https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/

关于ruby - 在 github 页面中使用自定义 ruby​​ gem 会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39976298/

相关文章:

ruby - 构建逗号分隔文件

ruby-on-rails - 在深度嵌套对象模型中处理 nils 的技术

ruby-on-rails - 如何将大型 gem 转换为独立的 Rails 应用程序

twitter-bootstrap - 将 Bootstrap SASS 添加到 Jekyll/GitHub 页面

syntax-highlighting - 如何扩展 pygments.lexers.shell 的关键字列表

ruby-on-rails - 用于版本号的 Ruby 正则表达式

Ruby gem 相当于 "pip install -e"?

html - 如何在html内的markdown中使用脚注?

ruby-on-rails - ruby-rubocop 无法加载此类文件 -- rubocop/rspec/focused

ruby - gem 服务器不会提供 gem