First commit

This commit is contained in:
hadley
2015-07-27 16:52:19 -05:00
commit 851a889411
11 changed files with 177 additions and 0 deletions

24
_plugins/knit.r Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/Rscript
library(rmarkdown)
library(bookdown)
library(methods)
args <- commandArgs(trailingOnly = TRUE)
path <- args[1]
if (!file.exists(path)) {
stop("Can't find path ", path, call. = FALSE)
}
if (file.access(path, 4) != 0) {
stop("Can't read path ", path, call. = FALSE)
}
html_path <- render(path, html_chapter(raw = TRUE, toc = "toc.rds"),
quiet = TRUE)
read_file <- function(path) {
size <- file.info(path)$size
readChar(path, size, useBytes = TRUE)
}
cat(read_file(html_path))

33
_plugins/rmarkdown.rb Normal file
View File

@@ -0,0 +1,33 @@
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`
if $?.exitstatus != 0
raise "Knitting failed"
end
content
# File.unlink f.path
end
end
end