From d43223b591065789b1d9c500c343154d7cd61d4b Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Sat, 13 Mar 2021 05:25:53 +0100 Subject: [PATCH] labelmaker: Make label size configurable at runtime --- labelmaker/main.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/labelmaker/main.rb b/labelmaker/main.rb index dff9564..c2bdf54 100644 --- a/labelmaker/main.rb +++ b/labelmaker/main.rb @@ -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