refactor
This commit is contained in:
parent
7e0be269af
commit
c4656b8292
28
main.rb
28
main.rb
|
@ -84,7 +84,7 @@ end
|
||||||
DYMO_LABEL_SIZE = [89, 36]
|
DYMO_LABEL_SIZE = [89, 36]
|
||||||
ZEBRA_LABEL_SIZE = [50, 30]
|
ZEBRA_LABEL_SIZE = [50, 30]
|
||||||
|
|
||||||
def render_test(dict_or_api, extra, item_or_label_id, size: ZEBRA_LABEL_SIZE)
|
def render_label(dict_or_api, extra, item_or_label_id, size: ZEBRA_LABEL_SIZE)
|
||||||
if dict_or_api
|
if dict_or_api
|
||||||
item = item_or_label_id
|
item = item_or_label_id
|
||||||
else
|
else
|
||||||
|
@ -139,14 +139,14 @@ set :bind, '0.0.0.0'
|
||||||
|
|
||||||
get '/api/1/preview/:id.pdf' do
|
get '/api/1/preview/:id.pdf' do
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(false,"qr",params["id"])
|
render_label(false,"qr",params["id"])
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/preview/:id.png' do
|
get '/api/1/preview/:id.png' do
|
||||||
headers["Content-Type"] = "image/png"
|
headers["Content-Type"] = "image/png"
|
||||||
img = Magick::ImageList.new()
|
img = Magick::ImageList.new()
|
||||||
img = img.from_blob(render_test(false,"qr",params["id"])){ self.density = 200 }.first
|
img = img.from_blob(render_label(false,"qr",params["id"])){ self.density = 200 }.first
|
||||||
img.format = 'png'
|
img.format = 'png'
|
||||||
img.background_color = 'white'
|
img.background_color = 'white'
|
||||||
img.to_blob
|
img.to_blob
|
||||||
|
@ -154,14 +154,14 @@ end
|
||||||
|
|
||||||
post '/api/1/print/:id' do
|
post '/api/1/print/:id' do
|
||||||
temp = Tempfile.new('labelmaker')
|
temp = Tempfile.new('labelmaker')
|
||||||
temp.write(render_test(false,"qr", params["id"]))
|
temp.write(render_label(false,"qr", params["id"]))
|
||||||
temp.close
|
temp.close
|
||||||
system("lpr -P Zebra #{temp.path}")
|
system("lpr -P Zebra #{temp.path}")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/templates/preview/:id' do
|
get '/api/1/templates/preview/:id' do
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(true, "img", templates[params["id"]])
|
render_label(true, "img", templates[params["id"]])
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/templates/print/:id' do
|
get '/api/1/templates/print/:id' do
|
||||||
|
@ -174,12 +174,12 @@ end
|
||||||
get '/api/1/nametag/preview/:id' do
|
get '/api/1/nametag/preview/:id' do
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
|
|
||||||
render_test(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"})
|
render_label(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"})
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/nametag/print/:id' do
|
get '/api/1/nametag/print/:id' do
|
||||||
temp = Tempfile.new('labelmaker')
|
temp = Tempfile.new('labelmaker')
|
||||||
temp.write(render_test(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"}))
|
temp.write(render_label(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"}))
|
||||||
temp.close
|
temp.close
|
||||||
system("lpr -P Zebra #{temp.path}")
|
system("lpr -P Zebra #{temp.path}")
|
||||||
end
|
end
|
||||||
|
@ -187,13 +187,13 @@ end
|
||||||
get '/api/1/customitem/preview/:owner/:name' do
|
get '/api/1/customitem/preview/:owner/:name' do
|
||||||
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
|
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(true,"blank",test)
|
render_label(true,"blank",test)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/customitem/print/:owner/:name' do
|
get '/api/1/customitem/print/:owner/:name' do
|
||||||
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
|
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
|
||||||
temp = Tempfile.new('labelmaker')
|
temp = Tempfile.new('labelmaker')
|
||||||
temp.write(render_test(true,"blank",test))
|
temp.write(render_label(true,"blank",test))
|
||||||
temp.close
|
temp.close
|
||||||
system("lpr -P Zebra #{temp.path}")
|
system("lpr -P Zebra #{temp.path}")
|
||||||
end
|
end
|
||||||
|
@ -203,19 +203,19 @@ end
|
||||||
get '/api/1/dupatest/preview' do
|
get '/api/1/dupatest/preview' do
|
||||||
test = {"owner" => "test", "short_id" => "test", "name" => "test", "image" => "assets/glider.svg"}
|
test = {"owner" => "test", "short_id" => "test", "name" => "test", "image" => "assets/glider.svg"}
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(true,"img",test)
|
render_label(true,"img",test)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/testgift/preview' do
|
get '/api/1/testgift/preview' do
|
||||||
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
|
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(true,"img",test)
|
render_label(true,"img",test)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/testgift/print' do
|
get '/api/1/testgift/print' do
|
||||||
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
|
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
|
||||||
temp = Tempfile.new('labelmaker')
|
temp = Tempfile.new('labelmaker')
|
||||||
temp.write(render_test(true, "img",test))
|
temp.write(render_label(true, "img",test))
|
||||||
temp.close
|
temp.close
|
||||||
system("lpr -P Zebra #{temp.path}")
|
system("lpr -P Zebra #{temp.path}")
|
||||||
end
|
end
|
||||||
|
@ -223,13 +223,13 @@ end
|
||||||
get '/api/1/testshow' do
|
get '/api/1/testshow' do
|
||||||
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
|
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
|
||||||
headers["Content-Type"] = "application/pdf; charset=utf8"
|
headers["Content-Type"] = "application/pdf; charset=utf8"
|
||||||
render_test(true, "qr", test)
|
render_label(true, "qr", test)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/1/testprint' do
|
get '/api/1/testprint' do
|
||||||
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
|
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
|
||||||
temp = Tempfile.new('labelmaker')
|
temp = Tempfile.new('labelmaker')
|
||||||
temp.write(render_test(true,"qr",test))
|
temp.write(render_label(true,"qr",test))
|
||||||
temp.close
|
temp.close
|
||||||
system("lpr -P Zebra #{temp.path}")
|
system("lpr -P Zebra #{temp.path}")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue