Class: Victor::CLI::Commands::Convert

Inherits:
Base
  • Object
show all
Defined in:
lib/victor/cli/commands/convert.rb

Instance Method Summary collapse

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/victor/cli/commands/convert.rb', line 22

def run
  svg_file = args['SVG_FILE']
  template = args['--template']
  svg_node = SVGNode.load_file svg_file, layout: template

  validate_template template if template

  code = svg_node.render
  ruby_file = args['RUBY_FILE']

  if ruby_file
    File.write ruby_file, code
    say "Saved #{ruby_file}"
  else
    puts code
  end
end

#validate_template(template) ⇒ Object



40
41
42
43
44
45
# File 'lib/victor/cli/commands/convert.rb', line 40

def validate_template(template)
  allowed = %w[cli dsl standalone]
  return if allowed.include? template

  raise "Template not found #{template}\nAvailable templates: #{allowed.join ', '}"
end