HSWro retrofitting

This commit is contained in:
wiktor 2022-05-22 00:57:16 +02:00
parent b49426a9df
commit 89f5a68ee6
12 changed files with 405 additions and 14 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM ruby:latest
RUN mkdir /code
WORKDIR /code
ADD Gemfile /code/
ADD . /code/
RUN bundle install
CMD bundle exec ruby main.rb

View File

@ -8,3 +8,10 @@ gem 'color'
gem 'excon' gem 'excon'
gem 'rmagick' gem 'rmagick'
gem 'json' gem 'json'
gem 'matrix'
gem 'thin'
gem 'puma'
gem 'reel'
gem 'http'
gem 'webrick'
gem 'rest-client'

View File

@ -11,14 +11,47 @@ GEM
specs: specs:
addressable (2.7.0) addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
celluloid (0.18.0)
timers (~> 4)
celluloid-io (0.17.3)
celluloid (>= 0.17.2)
nio4r (>= 1.1)
timers (>= 4.1.1)
chunky_png (1.3.11) chunky_png (1.3.11)
color (1.8) color (1.8)
css_parser (1.7.1) css_parser (1.7.1)
addressable addressable
daemons (1.4.1)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
eventmachine (1.2.7)
excon (0.73.0) excon (0.73.0)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
http (5.0.1)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.3.0)
http-accept (1.7.0)
http-cookie (1.0.4)
domain_name (~> 0.5)
http-form_data (2.3.0)
http_parser.rb (0.8.0)
json (2.3.0) json (2.3.0)
llhttp-ffi (0.3.1)
ffi-compiler (~> 1.0)
rake (~> 13.0)
matrix (0.4.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mustermann (1.1.1) mustermann (1.1.1)
ruby2_keywords (~> 0.0.1) ruby2_keywords (~> 0.0.1)
netrc (0.11.0)
nio4r (2.5.8)
pdf-core (0.7.0) pdf-core (0.7.0)
prawn (2.2.2) prawn (2.2.2)
pdf-core (~> 0.7.0) pdf-core (~> 0.7.0)
@ -27,9 +60,23 @@ GEM
css_parser (~> 1.6) css_parser (~> 1.6)
prawn (>= 0.11.1, < 3) prawn (>= 0.11.1, < 3)
public_suffix (4.0.5) public_suffix (4.0.5)
puma (5.6.4)
nio4r (~> 2.0)
rack (2.2.2) rack (2.2.2)
rack-protection (2.0.8.1) rack-protection (2.0.8.1)
rack rack
rake (13.0.6)
reel (0.6.1)
celluloid (>= 0.15.1)
celluloid-io (>= 0.15.0)
http (>= 0.6.0.pre)
http_parser.rb (>= 0.6.0)
websocket-driver (>= 0.5.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rmagick (4.1.2) rmagick (4.1.2)
rqrcode (1.1.2) rqrcode (1.1.2)
chunky_png (~> 1.0) chunky_png (~> 1.0)
@ -41,8 +88,20 @@ GEM
rack (~> 2.0) rack (~> 2.0)
rack-protection (= 2.0.8.1) rack-protection (= 2.0.8.1)
tilt (~> 2.0) tilt (~> 2.0)
thin (1.8.1)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
tilt (2.0.10) tilt (2.0.10)
timers (4.3.3)
ttfunk (1.6.2.1) ttfunk (1.6.2.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.1)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
PLATFORMS PLATFORMS
ruby ruby
@ -50,12 +109,19 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
color color
excon excon
http
json json
matrix
prawn prawn
prawn-qrcode! prawn-qrcode!
prawn-svg prawn-svg
puma
reel
rest-client
rmagick rmagick
sinatra sinatra
thin
webrick
BUNDLED WITH BUNDLED WITH
1.17.2 1.17.2

16
assets/clean.svg Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" width="800px" height="800px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg">
<defs>
<style>
.cls-1 {
fill: none;
}
</style>
</defs>
<title>clean</title>
<rect x="20" y="18" width="6" height="2" transform="translate(46 38) rotate(-180)"/>
<rect x="24" y="26" width="6" height="2" transform="translate(54 54) rotate(-180)"/>
<rect x="22" y="22" width="6" height="2" transform="translate(50 46) rotate(-180)"/>
<path d="M17.0029,20a4.8952,4.8952,0,0,0-2.4044-4.1729L22,3,20.2691,2,12.6933,15.126A5.6988,5.6988,0,0,0,7.45,16.6289C3.7064,20.24,3.9963,28.6821,4.01,29.04a1,1,0,0,0,1,.96H20.0012a1,1,0,0,0,.6-1.8C17.0615,25.5439,17.0029,20.0537,17.0029,20ZM11.93,16.9971A3.11,3.11,0,0,1,15.0041,20c0,.0381.0019.208.0168.4688L9.1215,17.8452A3.8,3.8,0,0,1,11.93,16.9971ZM15.4494,28A5.2,5.2,0,0,1,14,25H12a6.4993,6.4993,0,0,0,.9684,3H10.7451A16.6166,16.6166,0,0,1,10,24H8a17.3424,17.3424,0,0,0,.6652,4H6c.031-1.8364.29-5.8921,1.8027-8.5527l7.533,3.35A13.0253,13.0253,0,0,0,17.5968,28Z"/>
<rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32" height="32"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
assets/dead.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" ?><svg width="64px" height="64px" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"><g data-name="Layer 27" id="Layer_27"><path d="M32,3A29,29,0,1,0,61,32,29,29,0,0,0,32,3Zm0,56A27,27,0,1,1,59,32,27,27,0,0,1,32,59ZM47.71,17.71,43.41,22l4.3,4.29a1,1,0,0,1,0,1.42,1,1,0,0,1-1.42,0L42,23.41l-4.29,4.3a1,1,0,0,1-1.42,0,1,1,0,0,1,0-1.42L40.59,22l-4.3-4.29a1,1,0,0,1,1.42-1.42L42,20.59l4.29-4.3a1,1,0,0,1,1.42,1.42ZM22,23.41l-4.29,4.3a1,1,0,0,1-1.42,0,1,1,0,0,1,0-1.42L20.59,22l-4.3-4.29a1,1,0,0,1,1.42-1.42L22,20.59l4.29-4.3a1,1,0,0,1,1.42,1.42L23.41,22l4.3,4.29a1,1,0,0,1,0,1.42,1,1,0,0,1-1.42,0ZM32,33c-3.31,0-6,3.36-6,7.5S28.69,48,32,48s6-3.36,6-7.5S35.31,33,32,33Zm0,13c-2.21,0-4-2.47-4-5.5S29.79,35,32,35s4,2.47,4,5.5S34.21,46,32,46Z"/></g></svg>

After

Width:  |  Height:  |  Size: 771 B

9
assets/gift.svg Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.1" d="M4 12.5V16C4 17.8856 4 18.8284 4.58579 19.4142C5.17157 20 6.11438 20 8 20H9H15H16C17.8856 20 18.8284 20 19.4142 19.4142C20 18.8284 20 17.8856 20 16V12.5C20 12.2239 19.7761 12 19.5 12H4.5C4.22386 12 4 12.2239 4 12.5Z" fill="#000000"/>
<path d="M3 9.5C3 9.03534 3 8.80302 3.03843 8.60982C3.19624 7.81644 3.81644 7.19624 4.60982 7.03843C4.80302 7 5.03534 7 5.5 7H12H18.5C18.9647 7 19.197 7 19.3902 7.03843C20.1836 7.19624 20.8038 7.81644 20.9616 8.60982C21 8.80302 21 9.03534 21 9.5V9.5V9.5C21 9.96466 21 10.197 20.9616 10.3902C20.8038 11.1836 20.1836 11.8038 19.3902 11.9616C19.197 12 18.9647 12 18.5 12H12H5.5C5.03534 12 4.80302 12 4.60982 11.9616C3.81644 11.8038 3.19624 11.1836 3.03843 10.3902C3 10.197 3 9.96466 3 9.5V9.5V9.5Z" stroke="#000000" stroke-width="2" stroke-linejoin="round"/>
<path d="M4 12V16C4 17.8856 4 18.8284 4.58579 19.4142C5.17157 20 6.11438 20 8 20H9H15H16C17.8856 20 18.8284 20 19.4142 19.4142C20 18.8284 20 17.8856 20 16V12" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 7V20" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11.3753 6.21913L9.3959 3.74487C8.65125 2.81406 7.26102 2.73898 6.41813 3.58187C5.1582 4.8418 6.04662 7 7.82843 7L11 7C11.403 7 11.6271 6.53383 11.3753 6.21913Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12.6247 6.21913L14.6041 3.74487C15.3488 2.81406 16.739 2.73898 17.5819 3.58187C18.8418 4.8418 17.9534 7 16.1716 7L13 7C12.597 7 12.3729 6.53383 12.6247 6.21913Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

1
assets/glider.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="140" height="140"><g transform="matrix(20,0,0,20,10,10)"><path d="m0 0h6v6h-6zm0 2h6m-6 2h6m-4-4v6m2-6v6" style="fill:none;stroke:#000;stroke-width:.1;"/><circle cx="3" cy="1" r=".8"/><circle cx="5" cy="3" r=".8"/><circle cx="1" cy="5" r=".8"/><circle cx="3" cy="5" r=".8"/><circle cx="5" cy="5" r=".8"/></g></svg>

After

Width:  |  Height:  |  Size: 412 B

51
assets/hswro.svg Executable file
View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
width="100"
height="100"
viewBox="0 0 99.999998 99.999998"
enable-background="new 0 0 595.28 841.89"
xml:space="preserve"
sodipodi:docname="hswro.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><metadata
id="metadata941"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs939">
</defs><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1027"
id="namedview937"
showgrid="false"
inkscape:zoom="2.8590332"
inkscape:cx="95.237875"
inkscape:cy="137.49347"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Layer_1" />
<path
d="m 72.207,33.822 5.733,-1.434 2.004,-20.054 h -29.143 -1 -9.233 l 0.816,29.389 -3.892,-1.245 -1.563,-28.144 h -8.99 -0.462 -6.421 l 6.043,58.737 0.023,0.225 5.458,3.898 7.323,-3.675 -0.71,-15.638 12.109,5.39 11.807,-5.294 -0.348,7.586 -4.04,2.103 -7.418,-3.604 -7.94,3.813 0.46,16.886 7.486,4.905 23.666,-16.522 3.162,-30.573 -8.386,-1.699 -9.732,2.948 0.537,-15.876 4.069,-0.606 -0.229,7.37 z M 34.982,13.334 36.49,40.465 29.323,42.257 27.018,13.334 Z m -2.924,60.5 -1.897,-21.528 7.009,3.12 0.704,15.49 z m -1.409,-30.878 6.346,-1.586 4.418,1.413 0.106,3.828 z m 27.649,23.536 4.434,-2.309 0.003,-0.073 5.993,2.912 -10.739,6.665 z m -7.998,-3.32 6.316,3.068 -6.314,3.287 -6.317,-3.321 z m 18.501,-23.27 5.902,1.196 -15.844,5.494 0.126,-3.717 z M 58.584,25.077 57.972,43.181 h 10e-4 L 57.808,48.014 76.014,41.701 73.027,70.587 50.799,86.105 V 70.397 l 6.474,-3.371 -0.364,8.51 12.826,-7.96 L 71.279,50.769 50.8,59.952 V 13.334 h 28.039 l -1.824,18.254 -4.288,1.073 0.731,-9.801 -9.389,1.399 v 0 z"
id="path932" />
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

1
assets/money.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"><g><path fill-rule="evenodd" clip-rule="evenodd" d="M27.629,77.803c0-4.808,3.903-8.711,8.711-8.711c4.796,0,8.699,3.903,8.699,8.711 c0,4.797-3.903,8.698-8.699,8.698C31.532,86.501,27.629,82.6,27.629,77.803z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M83.373,58.725l-7.477,12.952l-16.203-9.354c-2.117,3.223-5.76,5.358-9.894,5.358 c-5.466,0-10.063-3.721-11.427-8.752L12.3,65.918L20.094,95l68.111-18.244L83.373,58.725z M36.34,89.64 c-6.536,0-11.85-5.313-11.85-11.837c0-6.536,5.313-11.838,11.85-11.838c6.524,0,11.838,5.302,11.838,11.838 C48.178,84.326,42.864,89.64,36.34,89.64z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M41.089,55.843c0-4.808,3.902-8.711,8.71-8.711c4.796,0,8.7,3.903,8.7,8.711 c0,4.797-3.904,8.698-8.7,8.698C44.992,64.541,41.089,60.64,41.089,55.843z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M31.026,50.294c0,5.679-4.608,10.275-10.274,10.275 c-5.678,0-10.274-4.597-10.274-10.275c0-5.666,4.596-10.274,10.274-10.274C26.418,40.02,31.026,44.628,31.026,50.294z"></path><g><path fill-rule="evenodd" clip-rule="evenodd" d="M51.281,36.246l-1.846,3.198c0.635,0.199,1.164,0.234,1.6,0.094 c0.434-0.141,0.75-0.388,0.951-0.752c0.188-0.307,0.236-0.659,0.176-1.047C52.092,37.352,51.799,36.847,51.281,36.246z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M28.464,5L13.405,31.074l28.164,16.262c2.133-2.065,5.034-3.343,8.231-3.343 c6.524,0,11.839,5.313,11.839,11.85c0,0.99-0.137,1.948-0.369,2.869l13.193,7.617l15.059-26.086L28.464,5z M59.463,33.483 l-4.02-1.551c0.082-0.564,0.094-0.987,0.045-1.258c-0.045-0.271-0.188-0.6-0.422-0.976l-1.668,2.879 c1.715,1.705,2.738,3.046,3.066,4.033c0.436,1.316,0.295,2.598-0.422,3.832c-0.412,0.717-0.965,1.293-1.635,1.704 c-0.67,0.423-1.363,0.682-2.104,0.8c-0.73,0.117-1.435,0.105-2.105-0.047c-0.67-0.142-1.422-0.436-2.257-0.87l-1.093,1.893 l-1.446-0.835l1.093-1.893c-0.917-0.646-1.623-1.258-2.092-1.834c-0.482-0.575-0.823-1.199-1.023-1.857 c-0.211-0.657-0.294-1.281-0.271-1.893c0.036-0.599,0.176-1.27,0.447-1.998l4.268,1.846c-0.259,0.729-0.365,1.293-0.33,1.705 c0.036,0.41,0.223,0.857,0.553,1.352L50.082,35c-1.128-1.151-1.893-2.021-2.292-2.609c-0.399-0.6-0.635-1.316-0.706-2.151 c-0.059-0.834,0.153-1.692,0.659-2.551c0.682-1.188,1.658-1.928,2.938-2.245c1.293-0.317,2.776-0.047,4.456,0.8l0.553-0.977 l1.445,0.835l-0.564,0.976c1.436,0.952,2.363,1.963,2.799,3.021C59.803,31.156,59.84,32.284,59.463,33.483z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M52.467,28.829c-0.281,0.105-0.504,0.306-0.656,0.576 c-0.176,0.294-0.236,0.599-0.188,0.905c0.033,0.317,0.223,0.669,0.551,1.045l1.469-2.538C53.15,28.711,52.75,28.711,52.467,28.829 z"></path></g></g></svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

4
assets/person.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48">
<path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"/>
<path d="M0 0h48v48h-48z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 279 B

32
assets/warning.svg Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1"
id="svg2" xmlns:svg="http://www.w3.org/2000/svg" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:cc="http://creativecommons.org/ns#" inkscape:version="0.48.3.1 r9886" sodipodi:docname="warning_sign_font_awesome.svg"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="603px" height="555.25px"
viewBox="137.445 6.89 603 555.25" enable-background="new 137.445 6.89 603 555.25" xml:space="preserve">
<sodipodi:namedview inkscape:cy="243.77216" inkscape:cx="156.80493" guidetolerance="10" showgrid="false" borderopacity="1" inkscape:zoom="0.13169643" gridtolerance="10" pagecolor="#ffffff" bordercolor="#666666" objecttolerance="10" id="namedview8" inkscape:current-layer="svg2" inkscape:window-maximized="1" inkscape:window-y="25" inkscape:window-x="0" inkscape:pageopacity="0" inkscape:window-height="719" inkscape:pageshadow="2" inkscape:window-width="1024">
</sodipodi:namedview>
<g id="g4" transform="matrix(1,0,0,-1,7.5932254,1333.7966)">
<g id="path6" inkscape:connector-curvature="0">
<path d="M431.547,1293.104c2.243,0,4.021-0.492,5.942-1.645c2.004-1.202,3.416-2.683,4.58-4.802l252.559-463.022l0.056-0.103
l0.057-0.101c2.502-4.505,2.438-7.015-0.316-11.703c-1.087-1.854-2.439-3.181-4.392-4.306c-1.899-1.095-3.721-1.583-5.903-1.583
H178.964c-2.183,0-4.003,0.488-5.908,1.587c-1.947,1.121-3.3,2.448-4.401,4.327c-2.739,4.663-2.804,7.173-0.301,11.678
l0.056,0.101l0.056,0.103l252.572,463.047c1.162,2.105,2.572,3.58,4.567,4.777
C427.525,1292.612,429.303,1293.104,431.547,1293.104 M431.547,1323.104c-7.674,0-14.8-1.973-21.377-5.92
c-6.578-3.947-11.73-9.318-15.458-16.115L142.128,838c-7.674-13.813-7.455-27.627,0.658-41.439
c3.727-6.359,8.825-11.402,15.293-15.129c6.468-3.729,13.429-5.592,20.884-5.592h505.165c7.455,0,14.416,1.863,20.885,5.592
c6.469,3.727,11.566,8.77,15.293,15.129c8.113,13.813,8.332,27.626,0.658,41.439l-252.584,463.068
c-3.727,6.797-8.879,12.168-15.457,16.115S439.221,1323.104,431.547,1323.104L431.547,1323.104z"/>
</g>
</g>
<g id="g4_1_" transform="matrix(1,0,0,-1,7.5932254,1333.7966)">
<path id="path6_1_" inkscape:connector-curvature="0" d="M473.645,870.749v62.488c0,3.069-1.043,5.646-3.125,7.729
c-2.084,2.083-4.549,3.124-7.4,3.124h-63.146c-2.851,0-5.317-1.041-7.399-3.124c-2.084-2.083-3.125-4.659-3.125-7.729v-62.488
c0-3.069,1.041-5.646,3.125-7.729c2.082-2.083,4.549-3.124,7.399-3.124h63.146c2.852,0,5.316,1.041,7.4,3.124
C472.602,865.104,473.645,867.68,473.645,870.749z M472.986,993.752l5.92,150.958c0,2.631-1.096,4.714-3.289,6.249
c-2.85,2.412-5.482,3.618-7.893,3.618h-72.355c-2.412,0-5.043-1.206-7.893-3.618c-2.193-1.535-3.289-3.837-3.289-6.907l5.591-150.3
c0-2.193,1.097-4.002,3.289-5.427s4.823-2.138,7.894-2.138h60.844c3.068,0,5.645,0.713,7.729,2.138
C471.615,989.75,472.768,991.559,472.986,993.752z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

223
main.rb
View File

@ -7,6 +7,7 @@ require 'prawn/qrcode'
require 'prawn-svg' require 'prawn-svg'
require 'color' require 'color'
require 'excon' require 'excon'
require 'rest-client'
require 'rmagick' require 'rmagick'
require 'json' require 'json'
require 'zlib' require 'zlib'
@ -28,7 +29,7 @@ include Prawn::Measurements
# end # end
# end # end
module Excon module RestClient
class Response class Response
def json!() def json!()
# Convenience function # Convenience function
@ -37,11 +38,26 @@ module Excon
end end
end end
BACKEND_URL = 'https://inventory.waw.hackerspace.pl/api/1/' BACKEND_URL = 'http://inventory.lokal.hswro.org/api/1/'
CODE_PREFIX = "HTTP://I/" CODE_PREFIX = "HTTP://I/"
WIKI_PREFIX = "http://wiki.hswro.org/"
$templates = {
"prywatne" => { "name" => "Ten przedmiot jest własnością prywatną", "image" => "assets/person.svg"},
"hsowe" => { "name" => "Ten przedmiot należy do HSWro", "image" => "assets/hswro.svg"},
"hackuj" => { "name" => "Hackuj ile dusza zapragnie", "image" => "assets/glider.svg"},
"zepsute" => { "name" => "Ten przedmiot jest zepsuty", "image" => "assets/dead.svg"},
"eksploatuje" => { "name" => "Ten przedmiot eksploatuje materiały", "image" => "assets/money.svg"},
"niehackuj" => { "name" => "Nie hackuj tego przedmiotu", "image" => "assets/glider.svg"},
"blaty" => { "name" => "Utrzymuj czystość na blatach", "image" => "assets/clean.svg"},
# meme
"bhp" => { "name" => "Gdy ci smutno, gdy ci źle, użyj pasty BHP", "image" => "assets/hswro.svg"},
}
def api(uri) def api(uri)
Excon.get(BACKEND_URL + uri + "/").json! RestClient.get(BACKEND_URL + uri + ".json", :debug => true).json!
end end
def render_identicode(data, id, extent) def render_identicode(data, id, extent)
@ -68,13 +84,55 @@ def render_identicode(data, id, extent)
end end
DYMO_LABEL_SIZE = [89, 36] DYMO_LABEL_SIZE = [89, 36]
ZEBRA_LABEL_SIZE = [100, 60] ZEBRA_LABEL_SIZE = [50, 30]
def render_label(item_or_label_id, size: DYMO_LABEL_SIZE) NORMAL_LABEL_MARGIN = [2, 2, 2, 6]
item = api("items/#{item_or_label_id}") DRAWER_LABEL_MARGIN = [15, 2, 2, 3]
IS_DRAWER = false
def get_item_from_api(item)
return api("items/#{item}")
end
def prepare_normal_label(item)
result = item
result['qr'] = CODE_PREFIX + item['short_id']
return result
end
def prepare_custom_hs(text)
return {"name" => text, "image" => "assets/hswro.svg"}
end
def prepare_custom_item(name, owner)
return {"name" => name, "owner" => owner}
end
def prepare_templated(template)
return $templates[template]
end
def prepare_gifted(item)
donor = item['props']['donor'] ? item['props']['donor'] : ""
result = {"name" => "Przedmiot podarował: #{donor}", "image" => "assets/gift.svg"}
return result
end
def prepare_wiki(item)
wikiaddr = item['props']['wiki'] ? WIKI_PREFIX + item['props']['wiki'] : ""
result = {"name" => "Wiki: #{item['props']['wiki']}", "qr" => wikiaddr}
return result
end
def render_label(item, size: ZEBRA_LABEL_SIZE)
labelmargin = IS_DRAWER ? DRAWER_LABEL_MARGIN : NORMAL_LABEL_MARGIN
pdf = Prawn::Document.new(page_size: size.map { |x| mm2pt(x) }, pdf = Prawn::Document.new(page_size: size.map { |x| mm2pt(x) },
margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do margin: labelmargin.map { |x| mm2pt(x) }) do
font_families.update("DejaVuSans" => { font_families.update("DejaVuSans" => {
normal: "fonts/DejaVuSans.ttf", normal: "fonts/DejaVuSans.ttf",
italic: "fonts/DejaVuSans-Oblique.ttf", italic: "fonts/DejaVuSans-Oblique.ttf",
@ -84,14 +142,27 @@ def render_label(item_or_label_id, size: DYMO_LABEL_SIZE)
font 'DejaVuSans' font 'DejaVuSans'
# Width of right side # Width of right side
# qr_size = [bounds.height / 2, 27].max
qr_size = [bounds.height / 2, 27].max qr_size = [bounds.height / 2, 27].max
image_size = [bounds.height / 2, 27].max
# Right side # Right side
# bounding_box([bounds.right - qr_size, bounds.top], width: qr_size) do
bounding_box([bounds.right - qr_size, bounds.top], width: qr_size) do bounding_box([bounds.right - qr_size, bounds.top], width: qr_size) do
print_qr_code CODE_PREFIX + item['short_id'], stroke: false,
foreground_color: '000000',
extent: bounds.width, margin: 0, pos: bounds.top_left if item['qr']
print_qr_code item['qr'], stroke: false,
foreground_color: '000000',
extent: bounds.width, margin: 0, pos: bounds.top_left
end
if item['image']
svg IO.read(item['image']), width: image_size, position: :right
end
owner_text = item["owner"] ? "owner: #{item['owner']}\n\n" : "" owner_text = item["owner"] ? "owner: #{item['owner']}\n\n" : ""
metadata_text = owner_text # todo: creation date? metadata_text = owner_text # todo: creation date?
@ -113,15 +184,27 @@ end
set :bind, '0.0.0.0' 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_label params["id"] render_label(prepare_normal_label(get_item_from_api(params["id"])))
end
get '/api/1/preview/:id/gift.pdf' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_gifted(get_item_from_api(params["id"])))
end
get '/api/1/preview/:id/wiki.pdf' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_wiki(get_item_from_api(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_label(params["id"])){ self.density = 200 }.first img = img.from_blob(render_label(prepare_normal_label(get_item_from_api(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
@ -129,7 +212,119 @@ end
post '/api/1/print/:id' do post '/api/1/print/:id' do
temp = Tempfile.new('labelmaker') temp = Tempfile.new('labelmaker')
temp.write(render_label(params["id"])) temp.write(render_label(prepare_normal_label(get_item_from_api(params["id"]))))
temp.close temp.close
system("lpr -P DYMO_LabelWriter_450 #{temp.path}") system("lpr -P Zebra #{temp.path}")
end
post '/api/1/print/:id/wiki' do
temp = Tempfile.new('labelmaker')
temp.write(render_label(prepare_wiki(get_item_from_api(params["id"]))))
temp.close
system("lpr -P Zebra #{temp.path}")
end
get '/api/1/test/:id' do
get_item_from_api(params["id"])
prepare_wiki(get_item_from_api(params["id"]))
end
#####################################################
get '/api/1/list/templates' do
headers["Content-Type"] = "application/json"
$templates.to_json
end
get '/api/1/preview/templates/:id' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_templated(params['id']))
end
get '/api/1/templates/preview/:id' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_templated(params['id']))
end
get '/api/1/templates/print/:id' do
temp = Tempfile.new('labelmaker')
temp.write(render_label(prepare_templated(params['id'])))
temp.close
system("lpr -P Zebra #{temp.path}")
end
get '/api/1/nametag/preview/:id' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_custom_hs(params['id']))
end
get '/api/1/nametag/print/:id' do
temp = Tempfile.new('labelmaker')
temp.write(render_label(prepare_custom_hs(params['id'])))
temp.close
system("lpr -P Zebra #{temp.path}")
end
get '/api/1/customitem/preview/:owner/:name' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(prepare_custom_item(params["name"],params["owner"]))
end
get '/api/1/customitem/print/:owner/:name' do
temp = Tempfile.new('labelmaker')
temp.write(render_label(prepare_custom_item(params["name"],params["owner"])))
temp.close
system("lpr -P Zebra #{temp.path}")
end
get '/api/1/gift/preview' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(false,"img",test)
end
get '/api/1/testgift/print' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
temp = Tempfile.new('labelmaker')
temp.write(render_label(false, "img",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end
# TESTY
get '/api/1/dupatest/preview' do
test = {"owner" => "test", "short_id" => "test", "name" => "test", "image" => "assets/glider.svg"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(false,"img",test)
end
get '/api/1/testgift/preview' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(false,"img",test)
end
get '/api/1/testgift/print' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
temp = Tempfile.new('labelmaker')
temp.write(render_label(false, "img",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end
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"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_label(false, "qr", test)
end
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"}
temp = Tempfile.new('labelmaker')
temp.write(render_label(false,"qr",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end end