Class: Tilt::KnitrTemplate
- Inherits:
-
Template
- Object
- Template
- Tilt::KnitrTemplate
- Defined in:
- lib/tilt-knitr.rb
Overview
knitr template github.com/yihui/knitr
Instance Method Summary collapse
Instance Method Details
#evaluate(scope, locals, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tilt-knitr.rb', line 19 def evaluate(scope, locals, &block) fig_path = @fig_path if locals.has_key? "fig.path" fig_path = locals["fig.path"] end stdin, stdout, stderr = Open3.popen3('R --vanilla --slave -e "library(knitr);opts_chunk\$set(fig.path=\"'+fig_path+'\");data=readLines(file(\'stdin\'));out=knit(text=data,output=NULL);cat(\'KNITR<<<<<<<<<<<\n\');cat(out)"') if !block.nil? raise "Knitr Templates do not support inner blocks!" end #, locals.merge(scope.is_a?(Hash) ? scope : {}).merge({:yield => block.nil? ? '' : block.call})) stdin.write(data) stdin.write("\n") stdin.close $stderr.print stderr.readlines.join stdout.readlines.join.sub(/.*KNITR<<<<<<<<<<</m,"").strip end |
#initialize_engine ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/tilt-knitr.rb', line 9 def initialize_engine; stdin, stdout, stderr = Open3.popen3('R --vanilla --slave -e "library(knitr)"') err = stderr.readlines.join if ! err.empty? raise LoadError, err end end |
#prepare ⇒ Object
17 |
# File 'lib/tilt-knitr.rb', line 17 def prepare; end |