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

#command, #get_file_type, #html_file, #initialize, #label_file_path, #logit, #pdf_file_path, #send_print_file, #text_file

Constructor Details

This class inherits a constructor from ActionPrinter

Instance Method Details

#do_print(copies = 1) ⇒ Object

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



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 39

def do_print copies=1
  result = nil
  prn = printer
  unless prn.command.blank?
    if copies.to_i > 0
      cpcmd = `echo 'A #{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
  !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
33
34
35
36
# 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
    # html = ActionView::Base.new(Rails.configuration.paths['app/views']).render(
    #   file: 'accounts/record.html.haml',
    #   # partial: 'test',
    #   formats: [:html],
    #   handlers: [:erb,:haml],
    #   locals: { variable: 'value' }
    # )
    #
  of = text_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
  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