Class: VivlioStarter::CLI::PreProcessCommands::MathTransformer::NodeRenderer
- Inherits:
-
Object
- Object
- VivlioStarter::CLI::PreProcessCommands::MathTransformer::NodeRenderer
- Defined in:
- lib/vivlio_starter/cli/pre_process/math_transformer.rb
Overview
Node 上の MathJax を呼び出して LaTeX→SVG する既定レンダラ。 items([latex, display])を stdin で渡し、=> svg を受け取る。
Instance Method Summary collapse
-
#initialize(node_command, mathjax_root) ⇒ NodeRenderer
constructor
A new instance of NodeRenderer.
- #render_batch(items) ⇒ Object
Constructor Details
#initialize(node_command, mathjax_root) ⇒ NodeRenderer
Returns a new instance of NodeRenderer.
343 344 345 346 |
# File 'lib/vivlio_starter/cli/pre_process/math_transformer.rb', line 343 def initialize(node_command, mathjax_root) @node_command = node_command @mathjax_root = mathjax_root end |
Instance Method Details
#render_batch(items) ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/vivlio_starter/cli/pre_process/math_transformer.rb', line 348 def render_batch(items) input = JSON.generate(items) output = nil env = { 'MATHJAX_ROOT' => @mathjax_root } IO.popen(env, [@node_command, SCRIPT_PATH], 'r+', err: File::NULL) do |io| io.write(input) io.close_write output = io.read end return {} if output.nil? || output.empty? JSON.parse(output) rescue StandardError {} end |