我该如何猴子修补Jekyll扩展或插件? [英] How do I monkey-patch a Jekyll extension or plugin?
问题描述
我想重写如下所示的gem方法(Jekyll扩展名):
I'd like to override a gem method (a Jekyll extension) that looks like this:
文件: lib/jekyll-amazon/amazon_tag.rb
.
module Jekyll
module Amazon
class AmazonTag < Liquid::Tag
def detail(item)
...
end
end
end
end
Liquid::Template.register_tag('amazon', Jekyll::Amazon::AmazonTag)
我已经将具有相同结构的代码放置在项目中的 config/initializers/presentation.rb
_plugins/presentation.rb
文件夹中.如果我将方法detail
的名称更改为新名称,则它可以工作,但无法获取它来覆盖名称detail
.
我做错了什么?
I have placed code with the same structure in my project in the folder config/initializers/presentation.rb
_plugins/presentation.rb
. If I change the name of the method detail
to a new name, it works, but I can't get it to override the name detail
.
What have I done wrong?
(注意:在jekyll-amazon gem的0.2.2版中,detail
方法是私有的;我在本地更改了此方法,因此该方法不再是私有的.)
(Note: In version 0.2.2 of the jekyll-amazon gem, the detail
method is private; I have changed this locally so that the method is no longer private.)
推荐答案
您可以使用 查看全文