Class: CabPrinter

Inherits:
ActionPrinter show all
Defined in:
lib/oxen_printer/cab_printer.rb

Instance Attribute Summary

Attributes inherited from ActionPrinter

#paper, #printer

Instance Method Summary collapse

Methods inherited from ActionPrinter

#build_print_cmd, #command, #command=, #get_file_type, #html_file, #initialize, #label_file_path, #logit, #mail_print, #pdf_file_path, #print_print, #render_string_in, #send_print_file, #text_file

Constructor Details

This class inherits a constructor from ActionPrinter

Instance Method Details

#do_print(print_job, args) ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Object

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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_pathObject



61
62
63
# File 'lib/oxen_printer/cab_printer.rb', line 61

def file_path
  label_file_path
end