Module: Jekyll::Diagrams::Renderer
Instance Method Summary collapse
- #render_with_command(command, output, options = {}) ⇒ Object
- #render_with_stdin(command, content) ⇒ Object
- #render_with_stdin_stdout(command, content) ⇒ Object
- #render_with_stdout(command, content) ⇒ Object
- #render_with_tempfile(command, content) ⇒ Object
Instance Method Details
#render_with_command(command, output, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/jekyll-diagrams/renderer.rb', line 47 def render_with_command(command, output, = {}) stdout, stderr, status = Open3.capture3(command, ) if !status.success? raise "#{command} failed: #{stdout.empty? ? stderr : stdout}" end output == :stdout ? stdout : File.read(output) end |
#render_with_stdin(command, content) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/jekyll-diagrams/renderer.rb', line 15 def render_with_stdin(command, content) Tempfile.open(['jekyll_diagrams_output', ".svg"]) do |output| output.close command = yield command, output.path if block_given? render_with_command(command, output.path, stdin_data: content) end end |
#render_with_stdin_stdout(command, content) ⇒ Object
9 10 11 12 13 |
# File 'lib/jekyll-diagrams/renderer.rb', line 9 def render_with_stdin_stdout(command, content) command = yield command if block_given? render_with_command(command, :stdout, stdin_data: content, binmode: true) end |
#render_with_stdout(command, content) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll-diagrams/renderer.rb', line 24 def render_with_stdout(command, content) Tempfile.open('jekyll_diagrams_input') do |input| File.write(input.path, content) command = yield command, input.path if block_given? render_with_command(command, :stdout) end end |
#render_with_tempfile(command, content) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jekyll-diagrams/renderer.rb', line 34 def render_with_tempfile(command, content) Tempfile.open('jekyll_diagrams_input') do |input| File.write(input.path, content) Tempfile.open(['jekyll_diagrams_output', ".svg"]) do |output| output.close command = yield command, input.path, output.path if block_given? render_with_command(command, output.path) end end end |