/
debug.rb
45 lines (35 loc) · 863 Bytes
/
debug.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Debug Filter version 0.3 November 2013 written by Feherke
# Facilitates access to information about the template variables.
#
# Syntax :
# {{ variable | call: 'method', 'parameter' }}
# Calls the specified method of the variable. ( See Object#send . )
# {{ variable | log: 'filename' }}
#
# Sample input :
# data: whatever
#
# Sample code :
# {{ data | call: 'tr', 'e', '3' }}
#
# Sample output :
# what3v3r
#
# Sample code :
# {{ data | log: '/tmp/liquid.log' }}
module Jekyll
module DebugFilter
def call input, method, *param
input.send method, *param rescue $!
end
def log input, filename
File.open filename, 'a' do |file|
file.puts "--=[ #{ Time.now } ]=--"
file.puts input
file.puts
end
nil
end
end
end
Liquid::Template.register_filter Jekyll::DebugFilter