Method: Inkmake::InkFile#initialize

Defined in:
lib/inkmake.rb

#initialize(file, opts) ⇒ InkFile



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/inkmake.rb', line 333

def initialize(file, opts)
  @file = file
  @images = []
  @force = opts[:force]

  svg_path = nil
  out_path = nil
  File.read(file).lines.each_with_index do |line, index|
    line.strip!
    next if line.empty? or line.start_with? "#"
    begin
      case line
      when /^svg:(.*)/i then svg_path = File.expand_path($1.strip, File.dirname(file))
      when /^out:(.*)/i then out_path = File.expand_path($1.strip, File.dirname(file))
      else
        @images << InkImage.new(self, parse_line(line))
      end
    rescue SyntaxError => e
      puts "#{file}:#{index+1}: #{e.message}"
      exit
    end
  end

  # order is: argument, config in inkfile, inkfile directory
  @svg_path = opts[:svg_path] || svg_path || File.dirname(file)
  @out_path = opts[:out_path] || out_path || File.dirname(file)
end