Class: ActionPrinter

Inherits:
ActionView::Base
  • Object
show all
Defined in:
lib/action_printer.rb

Overview

AbstractController::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer, paper) ⇒ ActionPrinter



18
19
20
21
22
# File 'lib/action_printer.rb', line 18

def initialize(printer,paper)
  @printer=printer
  @paper=paper
  super(Rails.configuration.paths['app/views'])
end

Instance Attribute Details

#paperObject

prepend_view_path ViewTemplate::Resolver.instance



16
17
18
# File 'lib/action_printer.rb', line 16

def paper
  @paper
end

#printerObject

prepend_view_path ViewTemplate::Resolver.instance



16
17
18
# File 'lib/action_printer.rb', line 16

def printer
  @printer
end

Instance Method Details

#commandObject



24
25
26
# File 'lib/action_printer.rb', line 24

def command
  @printer.command
end

#file_pathObject



52
53
54
# File 'lib/action_printer.rb', line 52

def file_path
  raise "must be implemented on the driver!!"
end

#get_file_typeObject



64
65
66
# File 'lib/action_printer.rb', line 64

def get_file_type
  raise "you must implement this on the driver!!"
end

#html_file(str, type = 'html') ⇒ Object

build a temp file with the HTML string rendered and provided as argument str



40
41
42
43
44
45
46
# File 'lib/action_printer.rb', line 40

def html_file str, type='html'
  f = Tempfile.new(['print', ".#{type}"])
  f.puts str
  f.close
  Rails.logger.info "oxen: wrote #{f.path}"
  f
end

#label_file_pathObject



56
57
58
# File 'lib/action_printer.rb', line 56

def label_file_path
  @label_file_path ||= `mktemp -t lblXXXX`[0..-2]
end

#logit(log_type, msg) ⇒ Object



76
77
78
# File 'lib/action_printer.rb', line 76

def logit( log_type, msg )
  Rails.logger.send(log_type, "[OXEN] #{Time.now} [#{log_type.to_s}] #{msg}")
end

#pdf_file_pathObject



60
61
62
# File 'lib/action_printer.rb', line 60

def pdf_file_path
  @pdf_file_path ||= `mktemp -t pdfXXXX`[0..-2]
end

#send_print_file(context) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/action_printer.rb', line 68

def send_print_file context
  context.send_file pdf_file_path, filename: 'oxen_file', type: get_file_type, disposition: "attachment"
  # context.cookies['fileDownload'] = 'true'
  # File.open(pdf_file_path, 'r') do |fp|
  #   context.send_data fp.read.force_encoding('BINARY'), filename: 'oxen_file', type: "application/pdf", disposition: "attachment"
  # end
end

#text_file(str) ⇒ Object



48
49
50
# File 'lib/action_printer.rb', line 48

def text_file str
  html_file str, 'label'
end