Debug
Sometimes is not simple to guess why the variable set in the YAML front matter is not inserted as expected in the generated document. This plugin was initially written to just display the class name of a variable.
Most of the time looking at output of the generator is easier than looking into the generated document. And always is easier to look at one generator output that looking
in all generated documents to check one value in each. That is why this plugin got its second filter, to puts
the value to the output.
But the Ruby objects have many handy methods and the Liquid template allows using only a couple of them. So I just deleted everything and wrote a single filter : call
.
Note
In version 0.2 the call
filter’s name was send
. Renamed in version 0.3 because some conflict.
Usage
call
is a Liquid filter, so you just put it after the {{
and }}
enclosed variable. The first parameter is the method name, the remaining
parameters are passed forward to the called method :
Type of variable is {{ variable | call: 'class' | call: 'name' }}
3rd letter of variable is {{ variable | call: '[]', 2 }}
Print variable to stdout {{ variable | call: 'display' }}
log
is a Liquid filter which returns nil
. It just writes the variable’s value into the specified file, together with a timestamp.
{{ variable | log: '/tmp/liquid.log' }}
Configuration
None.
Versions
- 0.0 - October 2011
- Initial release.
- 0.1 - February 2012
- Added the
puts
filter.
- Added the
- 0.2 - February 2012
- Removed the
debug
andputs
filter. - Added the
send
filter.
- Removed the
- 0.3 - November 2013
- Renamed the
send
filter tocall
as some conflict appeared since one of the updates. - Added the
log
filter to write the input to a file.
- Renamed the
Plans
- Maybe some really pretty printing. ( Sorry, not fan of
pp
. For now I will useto_yaml
. )
Download
You can find the related files on GitHub in my Jekyll-plugin repository’s debug directory :
- debug.rb - script