class CabPrinter

Public Instance Methods

do_print(print_job, args) click to toggle source

CAB print last command is “A n” where n is the number of copies - an information which we add at print time

Calls superclass method ActionPrinter#do_print
# File lib/oxen_printer/cab_printer.rb, line 35
def do_print print_job, args
  result = nil
  prn = printer
  unless prn.command.blank?
    if prn.command=="email"
      return super print_job, args
    else
      if args[:copies].to_i > 0
        cpcmd = `echo 'A #{args[:copies].to_i}\n' >> #{label_file_path}`
        label_path =  label_file_path.split("/")[-1]
        pap = paper || prn.paper
        cmd = prn.command.gsub(/\$1/, prn.cups_printer).gsub(/\$2/, label_file_path)
        # Here we start actually printing
        # $1 is the CUPS printer
        # $2 is the PDF file_path_and_name
        # $3 is the PDF filename
        # the command being something along the lines of: lp -d $1 -o media=a4 $2
        result = `#{cmd}`
      end
    end
  end
  !result.blank?
rescue
  false
end
do_render(print_job,*args) click to toggle source

J Job start S Set label size H Heat, speed, and printing method O Set print options T Text field definition B Barcode field definition G Graphic field definition I Image field definition A Amount of labels

# File lib/oxen_printer/cab_printer.rb, line 11
def do_render(print_job,*args)
  path = print_job.view_template_path
  #TODO vi får en fejl her når vi begynder at mixe modellerne f.eks. Employee.find_by_sql('select * from products')
  locals = { resource_class: print_job.printing_class.constantize, collection: print_job.printing_class.constantize.find_by_sql( print_job.print_sql)  }
  #
  # TODO args must be mergeable ;)
  # if args.flatten.compact.any?
  #   locals.merge! args
  # end
  if (path =~/^---/) # this will return falsy if found
    of = text_file render_string_in path.gsub( /^---/, ''), locals
  else
    of = text_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
  end
  logit :info, "created a label file: #{of.path}"
  var = %x[ mv #{of.path} #{label_file_path} ]
  logit :info, "moved it to: #{label_file_path}"
  true
rescue => e
  logit :error, "Rendering to TXT failed! The error was #{e.message}"
  false
end
file_path() click to toggle source
# File lib/oxen_printer/cab_printer.rb, line 61
def file_path
  label_file_path
end