Class: Rasem::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rasem/application.rb

Class Method Summary collapse

Class Method Details

.run!(*argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rasem/application.rb', line 2

def self.run!(*argv)
  if argv.empty?
    source_files = Dir.glob(File.expand_path("*.rasem"))
  else
    source_files = argv
  end

  if source_files.empty?
    puts "No input files"
    return 1
  end

  for source_file in source_files
    if source_file =~ /\.rasem$/
      svg_file = source_file.sub(/\.rasem$/, '.svg')
    else
      svg_file = source_file + ".svg"
    end
    img = Rasem::SVGImage.new("100%", "100%") do
      eval(File.read(source_file), binding)
    end
    File.open(svg_file, "w") do |f|
      f << img.output
    end
  end
  
  return 0
end