How do I disable a Jekyll extension or plugin?

I would like to override the gem method (Jekyll extension), which looks like this:

File: 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) 

I placed the code with the same structure in my project in the config/initializers/presentation.rb _plugins/presentation.rb folder. If I changed the name of the detail method to a new name, it works, but I cannot force it to override the name of detail . What have I done wrong?

(Note: in version 0.2.2 of the jekyll-amazon gem, the detail method is private, I changed it locally so that this method is no longer private.)

+6
source share
1 answer

You can use alias_method

 module Jekyll module Amazon class AmazonTag < Liquid::Tag alias_method :old_detail, :detail def detail(item) # do your stuff here # eventually pass your stuff to old method old_detail(item) end end end end Liquid::Template.register_tag('amazon', Jekyll::Amazon::AmazonTag) 
+1
source

Source: https://habr.com/ru/post/1013935/


All Articles