Module: LiquidDiagrams::Rendering
- Included in:
- BasicRenderer
- Defined in:
- lib/liquid_diagrams/rendering.rb
Class Method Summary collapse
- .render_with_command(command, output = :stdout, **options) ⇒ Object
- .render_with_stdin_stdout(command, content) ⇒ Object
- .render_with_tempfile(command, content) ⇒ Object
Class Method Details
.render_with_command(command, output = :stdout, **options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/liquid_diagrams/rendering.rb', line 33 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? msg = "#{command}: #{stderr.empty? ? stdout : stderr}" raise Errors::RenderingFailedError, msg end output == :stdout ? stdout : File.read(output) end |
.render_with_stdin_stdout(command, content) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/liquid_diagrams/rendering.rb', line 11 def render_with_stdin_stdout(command, content) = yield command if block_given? command = "#{command} #{}".strip render_with_command(command, :stdout, stdin_data: content) end |
.render_with_tempfile(command, content) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/liquid_diagrams/rendering.rb', line 18 def render_with_tempfile(command, content) input = Tempfile.new('input') output = Tempfile.new(%w[output .svg]) File.write(input.path, content) = yield input.path, output.path command = "#{command} #{}".strip render_with_command(command, output.path) ensure input.close! output.close! end |