Fix render after update, support new spejstore short_id lookup

This commit is contained in:
radex 2020-05-21 00:12:16 +02:00 committed by Piotr Dobrowolski
parent 56321627a6
commit c43b83282a
3 changed files with 26 additions and 29 deletions

View File

@ -1,7 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'prawn' gem 'prawn'
gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode', :ref => 'd492904' gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode'
gem 'prawn-svg' gem 'prawn-svg'
gem 'sinatra' gem 'sinatra'
gem 'color' gem 'color'

View File

@ -1,11 +1,10 @@
GIT GIT
remote: https://github.com/jabbrwcky/prawn-qrcode remote: https://github.com/jabbrwcky/prawn-qrcode
revision: d4929043950962f299cb16873fc500bc4682bbed revision: 08e457af2d6661ede3346a3a3dc3b99a9df9fd9b
ref: d492904
specs: specs:
prawn-qrcode (0.3.0) prawn-qrcode (0.5.1)
prawn (>= 1) prawn (>= 1)
rqrcode (>= 0.4.1) rqrcode (>= 1.0.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/

46
main.rb
View File

@ -1,5 +1,6 @@
require 'rubygems' require 'rubygems'
require 'sinatra' require 'sinatra'
require 'rqrcode'
require 'prawn' require 'prawn'
require 'prawn/measurements' require 'prawn/measurements'
require 'prawn/qrcode' require 'prawn/qrcode'
@ -12,21 +13,20 @@ require 'zlib'
include Prawn::Measurements include Prawn::Measurements
module Prawn # module Prawn
module Text # module Text
module Formatted #:nodoc: # module Formatted #:nodoc:
# @private # # @private
class LineWrap #:nodoc: # class LineWrap #:nodoc:
def whitespace() # def whitespace()
# Wrap by these special characters as well # # Wrap by these special characters as well
"&:/\\" + # "&:/\\" +
"\s\t#{zero_width_space()}" # "\s\t#{zero_width_space()}"
end # end
end # end
end # end
end # end
end # end
module Excon module Excon
class Response class Response
@ -67,11 +67,10 @@ def render_identicode(data, id, extent)
fill_color '000000' fill_color '000000'
end end
def render_label(label) def render_label(item_or_label_id, size = [89, 36])
item = api("items/#{item_or_label_id}")
label = api("labels/#{label}") pdf = Prawn::Document.new(page_size: size.map { |x| mm2pt(x) },
pdf = Prawn::Document.new(page_size: [89, 36].map { |x| mm2pt(x) },
margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do
font_families.update("DejaVuSans" => { font_families.update("DejaVuSans" => {
normal: "fonts/DejaVuSans.ttf", normal: "fonts/DejaVuSans.ttf",
@ -82,20 +81,19 @@ def render_label(label)
font 'DejaVuSans' font 'DejaVuSans'
# Width of right side # Width of right side
rw = bounds.height/2 rw = bounds.height/2
# Right side # Right side
bounding_box([bounds.right - rw, bounds.top], :width => rw) do bounding_box([bounds.right - rw, bounds.top], width: rw) do
print_qr_code CODE_PREFIX + label['id'], stroke: false, print_qr_code CODE_PREFIX + item['short_id'], stroke: false,
foreground_color: '000000', foreground_color: '000000',
extent: bounds.width, margin: 0, pos: bounds.top_left extent: bounds.width, margin: 0, pos: bounds.top_left
end end
# Left side # Left side
bounding_box(bounds.top_left, :width => bounds.width-rw) do bounding_box(bounds.top_left, width: bounds.width - rw) do
text_box label['item']['name'], text_box item['name'],
size: 40, align: :center, valign: :center, width: bounds.width-10, size: 40, align: :center, valign: :center, width: bounds.width-10,
inline_format: true, overflow: :shrink_to_fit, disable_wrap_by_char: true inline_format: true, overflow: :shrink_to_fit, disable_wrap_by_char: true
end end