lib/liquid_diagrams/renderers/vega_renderer.rb in liquid-diagrams-0.1.0 vs lib/liquid_diagrams/renderers/vega_renderer.rb in liquid-diagrams-0.2.0

- old
+ new

@@ -1,25 +1,33 @@ # frozen_string_literal: true module LiquidDiagrams module Renderers - class VegaRenderer < BasicRenderer - OPTIONS = %w[ - scale - ].freeze + %i[Vega Vegalite].each do |diagram| + renderer = Class.new(BasicRenderer) do + const_set :OPTIONS, %w[ + scale + ].freeze - def render - Rendering.render_with_stdin_stdout(build_command, @content) - end + define_method :render do + if diagram.downcase == 'vegalite' + @content = Rendering.render_with_stdin_stdout('vl2vg', @content) + end - def build_command - command = +'vg2svg' - - @config.slice(*OPTIONS).each do |opt, value| - command << " --#{opt} #{value}" + Rendering.render_with_stdin_stdout(build_command, @content) end - command + def build_command + command = +'vg2svg' + + @config.slice(*self.class.const_get(:OPTIONS)).each do |opt, value| + command << " --#{opt} #{value}" + end + + command + end end + + const_set("#{diagram}Renderer", renderer) end end end