r4ds/_plugins/rmarkdown.rb

34 lines
587 B
Ruby
Raw Normal View History

2015-07-28 05:52:19 +08:00
require 'tempfile'
module Jekyll
class RMarkdownConverter < Converter
safe :false
priority :high
def matches(ext)
ext =~ /^\.(rmd|rmarkdown)$/i
end
def output_ext(ext)
".html"
end
def convert(content)
f = File.new("temp.Rmd", "w")
f.write(content)
f.write("\n")
f.flush
# http://rubyquicktips.com/post/5862861056/execute-shell-commands
content = `_plugins/knit.r temp.Rmd`
2015-07-28 05:52:19 +08:00
if $?.exitstatus != 0
raise "Knitting failed"
2015-07-28 05:52:19 +08:00
end
2015-07-28 05:52:19 +08:00
content
# File.unlink f.path
end
end
end