lib/inkscape_merge/processor.rb
def run
        validate_options

        # Open the files
        @svg = File.read options.svg_file
        @data_file = DataParser.detect(options)

        count = 0
        headers = @data_file.headers
        pattern = /%VAR_(#{headers.map(&:to_s).join("|")})%/
        @data_file.each{|row|
          break if @options.limit > 0 && count >= @options.limit
          count += 1
          puts "Row: #{count}"
          tmp_file = Tempfile.new('inkscape_merge')
          begin
            (outfile,merged_svg) = [@options.output,@svg].map{|s|
                s.gsub(pattern){|m|
                  puts $1 if @options.verbose
                  # return corresponding value from current row
                  CGI.escapeHTML(row[$1])
              }
            }

            # Write merged SVG out
            tmp_file.puts merged_svg
            tmp_file.close

            # Sprintf outfile with current row number
            outfile %= count

            # Generate output path
            FileUtils.mkdir_p(File.dirname outfile)

            # Generate the file itself
            ink_generate tmp_file.path, Shellwords.escape(outfile), @options.format, @options.dpi
          rescue => e
            $stderr.puts "ERROR: #{e}"
            $stderr.puts e.backtrace if @options.verbose
          ensure
            tmp_file.unlink
          end
        }
      end
# Iterate over all data rows and generate output files
# Optionally stop when LIMIT is reached
Iterate over all data rows and generate output files
Optionally stop when LIMIT is reached
Iterate over all data rows and generate output files Optionally stop when LIMIT is reached
def run
        validate_options
        @svg = File.read options.svg_file
        @data_file = DataParser.detect(options)
        count = 0
        headers = @data_file.headers
        pattern = /%VAR_(#{headers.map(&:to_s).join("|")})%/
        @data_file.each{|row|
          break if @options.limit > 0 && count >= @options.limit
          count += 1
          puts "Row: #{count}"
          tmp_file = Tempfile.new('inkscape_merge')
          begin
            (outfile,merged_svg) = [@options.output,@svg].map{|s|
                s.gsub(pattern){|m|
                  puts $1 if @options.verbose
                  CGI.escapeHTML(row[$1])
              }
            }
            tmp_file.puts merged_svg
            tmp_file.close
            outfile %= count
            FileUtils.mkdir_p(File.dirname outfile)
            ink_generate tmp_file.path, Shellwords.escape(outfile), @options.format, @options.dpi
          rescue => e
            $stderr.puts "ERROR: #{e}"
            $stderr.puts e.backtrace if @options.verbose
          ensure
            tmp_file.unlink
          end
        }
      end
def run validate_options @svg = File . read options . svg_file @data_file = DataParser . detect ( options ) count = 0 headers = @data_file . headers pattern = / %VAR_( #{ headers . map ( & :to_s ) . join ( "|" ) } )% / @data_file . each { | row | break if @options . limit > 0 && count >= @options . limit count += 1 puts "Row: #{count}" tmp_file = Tempfile . new ( 'inkscape_merge' ) begin ( outfile , merged_svg ) = [ @options . output , @svg ] . map { | s | s . gsub ( pattern ) { | m | puts $1 if @options . verbose CGI . escapeHTML ( row [ $1 ] ) } } tmp_file . puts merged_svg tmp_file . close outfile %= count FileUtils . mkdir_p ( File . dirname outfile ) ink_generate tmp_file . path , Shellwords . escape ( outfile ) , @options . format , @options . dpi rescue => e $stderr . puts "ERROR: #{e}" $stderr . puts e . backtrace if @options . verbose ensure tmp_file . unlink end } end
Iterate over all data rows and generate output files
Optionally stop when LIMIT is reached
Iterate over all data rows and generate output files Optionally stop when LIMIT is reached
# Open the files # return corresponding value from current row # Write merged SVG out # Sprintf outfile with current row number # Generate output path # Generate the file itself