How to Test/Debug Jekyll Plugins?
Solution 1:
The solution was beyond my Ruby knowledge, but mostly straightforward, once I connected the pieces of information floating around.
First, this existing answer is about a specific issue dealing with Rails, but incidentally shows how to deal with private new
methods: Call them through send
, as in HeaderInlineTag.send :new
.
Then, this indirect call to .new()
now (of course) calls .initialize()
, meaning that it needs the three parameters that are required by any plugin. Two parameters are for the testing itself, so they're easy. The third is a parse context. Documentation on writing Jekyll plugins is never clear on what the parse context actually is, since it gets sent automatically as part of the build process. However, some research and testing turns up Liquid::ParseContext
as the culprit.
Finally, .render()
also takes the ParseContext
value.
Therefore, the the test scaffold should look something like this.
require 'liquid'
require_relative '../_plugins/header.rb'
context = Liquid::ParseContext.new
ht = HeaderInlineTag.send :new, 'header', 'some path...', context
puts ht.render context
I can call this from my blog's root folder with ruby _test/header.rb
, and it prints the plugin's output. I can now update this script to pull the parameters from the command line or a CSV file, depending on the tests required.