Module: Jekyll::Diagrams::Rendering
- Included in:
- BasicRenderer
- Defined in:
- lib/jekyll-diagrams/rendering.rb
Class Method Summary collapse
-
.render_with_command(command, output = :stdout, **options) ⇒ Object
Render SVG with command.
-
.render_with_stdin_stdout(command, content) ⇒ Object
Render SVG with stdin and stdout.
-
.render_with_tempfile(command, content) ⇒ Object
Render SVG with tempfile.
Class Method Details
.render_with_command(command, output = :stdout, **options) ⇒ Object
Render SVG with command
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll-diagrams/rendering.rb', line 50 def render_with_command(command, output = :stdout, **) begin stdout, stderr, status = Open3.capture3(command, **) rescue Errno::ENOENT raise Errors::CommandNotFoundError, command.split(' ')[0] end unless status.success? raise Errors::RenderingFailedError, <<~MSG #{command}: #{stderr.empty? ? stdout : stderr} MSG end output == :stdout ? stdout : File.read(output) end |
.render_with_stdin_stdout(command, content) ⇒ Object
Render SVG with stdin and stdout
17 18 19 |
# File 'lib/jekyll-diagrams/rendering.rb', line 17 def render_with_stdin_stdout(command, content) render_with_command(command, :stdout, stdin_data: content) end |
.render_with_tempfile(command, content) ⇒ Object
Render SVG with tempfile
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jekyll-diagrams/rendering.rb', line 27 def render_with_tempfile(command, content) Dir.mktmpdir('jekyll-diagrams-rendering') do |dir| input = Tempfile.new('input', tmpdir: dir) output = Tempfile.new(%w[output .svg], tmpdir: dir) File.write(input.path, content) extra = yield input.path, output.path command = "#{command} #{extra}" render_with_command(command, output.path) ensure input.close! output.close! end end |