labelmaker: Make label size configurable at runtime
parent
e3e0bb068a
commit
d43223b591
|
@ -29,8 +29,6 @@ include Prawn::Measurements
|
|||
# end
|
||||
# end
|
||||
|
||||
system("echo PATH = $PATH")
|
||||
|
||||
module Excon
|
||||
class Response
|
||||
def json!()
|
||||
|
@ -40,6 +38,19 @@ module Excon
|
|||
end
|
||||
end
|
||||
|
||||
# name -> height, width in millimeters
|
||||
LABEL_SIZES = {
|
||||
"11354" => [32 , 57],
|
||||
"99012" => [89 , 36],
|
||||
"zebra_large" => [100 , 60],
|
||||
}
|
||||
|
||||
LABEL_SIZE= ENV['LABEL_SIZE'] || "11354"
|
||||
|
||||
if !LABEL_SIZES[LABEL_SIZE]
|
||||
abort("Bruh moment - not printing, undefined LABEL_SIZE=#{LABEL_SIZE} fails to match any of\n#{LABEL_SIZES}")
|
||||
end
|
||||
|
||||
LPR_CMD_PATH = ENV['LPR_CMD_PATH'] || 'lpr'
|
||||
LPR_PRINTER_NAME = ENV['LPR_PRINTER_NAME'] || 'DYMO_LabelWriter_450'
|
||||
|
||||
|
@ -70,7 +81,7 @@ DYMO_11354_LABEL_SIZE = [32, 57]
|
|||
DYMO_LABEL_SIZE = [89, 36]
|
||||
ZEBRA_LABEL_SIZE = [100, 60]
|
||||
|
||||
def render_label(name, qr_text, metadata_text, size: DYMO_LABEL_SIZE)
|
||||
def render_label(name, qr_text, metadata_text, size: LABEL_SIZES[LABEL_SIZE])
|
||||
portrait = size[0] > size[1] # Decide if which orientation prints horizontally on the label
|
||||
pdf = Prawn::Document.new(:page_layout => portrait ? :portrait : :landscape, page_size: size.map { |x| mm2pt(x) },
|
||||
margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do
|
||||
|
|
Loading…
Reference in New Issue