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



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

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



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

def validate_template(template)
  allowed = %w[cli dsl standalone]
  unless allowed.include? template
    raise "Template not found #{template}\nAvailable templates: #{allowed.join ', '}"
  end
end