easyzpl 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/easyzpl.gemspec +4 -0
- data/lib/easyzpl/label.rb +36 -25
- data/lib/easyzpl/label_template.rb +22 -5
- data/lib/easyzpl/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cce1e37d7699ce5e0b48dbce06911ea5b34144c
|
4
|
+
data.tar.gz: 03ab6428bdd2b8f22ac4a7d9ed02eac013ab7988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a028a84b52aaaf05d189cc2c79a2da9be2eff41041eb6e190f738dfcb3bdc7ab2a94709d826ef9720b684397dcb7f8f8b2a47e80d396e6a68a35934efe544e1c
|
7
|
+
data.tar.gz: 6a28160fc30123c11c053ca9dcd373289968188d7d75835c9a276c3768bd8cd9b19db7febeaccfa47dbd662f38546193fe253e5f20af9c40a22ad6d486f28e06
|
data/easyzpl.gemspec
CHANGED
@@ -24,4 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_runtime_dependency 'prawn', '>= 1.0.0'
|
26
26
|
spec.add_runtime_dependency 'barby', '>= 0.6.1'
|
27
|
+
|
28
|
+
spec.required_ruby_version = '>= 1.9.3'
|
29
|
+
spec.requirements << 'Prawn, v1.0.0'
|
30
|
+
spec.requirements << 'Barby, v0.6.1'
|
27
31
|
end
|
data/lib/easyzpl/label.rb
CHANGED
@@ -17,23 +17,14 @@ module Easyzpl
|
|
17
17
|
def initialize(params = {})
|
18
18
|
# Create the array that will hold the data
|
19
19
|
self.label_data = []
|
20
|
-
|
21
|
-
# If we got parameters, store them
|
22
|
-
# Remember, we only need them for Prawn
|
23
|
-
self.label_width = params[:width] || 0
|
24
|
-
self.label_height = params[:height] || 0
|
25
|
-
|
26
20
|
# Set the default quantity to one
|
27
21
|
self.quantity = 1
|
28
22
|
|
29
|
-
# Start creating a Prawn document in memory,
|
30
|
-
# this can later be saved as a PDF and also
|
31
|
-
# an image
|
32
|
-
return unless label_height && label_width
|
33
|
-
self.pdf = Prawn::Document.new
|
34
|
-
|
35
23
|
# The start of the zpl label
|
36
24
|
label_data.push('^XA')
|
25
|
+
|
26
|
+
# Initialize Prawn
|
27
|
+
init_prawn(params)
|
37
28
|
end
|
38
29
|
|
39
30
|
# Set the number of labels to print
|
@@ -60,12 +51,7 @@ module Easyzpl
|
|
60
51
|
label_data.push('^FO' + x.to_s + ',' + y.to_s + '^GB' + height.to_s +
|
61
52
|
',' + width.to_s + ',1^FS')
|
62
53
|
|
63
|
-
|
64
|
-
return unless label_height && label_width
|
65
|
-
pdf.stroke_axis
|
66
|
-
pdf.stroke do
|
67
|
-
pdf.rectangle [x, label_width - y - width], height, width * -1
|
68
|
-
end
|
54
|
+
draw_rectangle(x, y, height, width)
|
69
55
|
end
|
70
56
|
|
71
57
|
# Prints text
|
@@ -77,8 +63,10 @@ module Easyzpl
|
|
77
63
|
options[:height].to_s + ',' + options[:width].to_s +
|
78
64
|
'^FD' + text + '^FS')
|
79
65
|
|
80
|
-
|
81
|
-
|
66
|
+
pdf.text_box text,
|
67
|
+
at: [x, label_width - y -
|
68
|
+
Integer(options[:height] / 10)],
|
69
|
+
size: options[:height] if label_height && label_width
|
82
70
|
end
|
83
71
|
|
84
72
|
# Prints a bar code in barcode39 font
|
@@ -90,11 +78,7 @@ module Easyzpl
|
|
90
78
|
|
91
79
|
return unless label_height && label_width
|
92
80
|
options = { height: 20 }.merge(params)
|
93
|
-
|
94
|
-
width: options[:height] do
|
95
|
-
barcode = Barby::Code39.new(bar_code_string)
|
96
|
-
barcode.annotate_pdf(pdf, height: options[:height])
|
97
|
-
end
|
81
|
+
draw_bar_code_39(bar_code_string, x, y, options[:height])
|
98
82
|
end
|
99
83
|
|
100
84
|
# Renders the ZPL code as a string
|
@@ -110,9 +94,36 @@ module Easyzpl
|
|
110
94
|
|
111
95
|
protected
|
112
96
|
|
97
|
+
def init_prawn(params)
|
98
|
+
self.label_width = params[:width] || 0
|
99
|
+
self.label_height = params[:height] || 0
|
100
|
+
|
101
|
+
return unless label_height > 0 && label_width > 0
|
102
|
+
self.pdf = Prawn::Document.new
|
103
|
+
end
|
104
|
+
|
113
105
|
# Returns true if a variable is number, false if not
|
114
106
|
def numeric?(variable)
|
115
107
|
true if Integer(variable) rescue false
|
116
108
|
end
|
109
|
+
|
110
|
+
# Draws the PDF rectangle (border)
|
111
|
+
def draw_rectangle(x, y, height, width)
|
112
|
+
return unless label_height > 0 && label_width > 0
|
113
|
+
pdf.stroke_axis
|
114
|
+
pdf.stroke do
|
115
|
+
pdf.rectangle [x, label_width - y - width], height, width * -1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Draws the PDF bar code 39
|
120
|
+
def draw_bar_code_39(bar_code_string, x, y, height)
|
121
|
+
return unless label_height > 0 && label_width > 0
|
122
|
+
pdf.bounding_box [x, Integer(label_width) - y - height],
|
123
|
+
width: height do
|
124
|
+
barcode = Barby::Code39.new(bar_code_string)
|
125
|
+
barcode.annotate_pdf(pdf, height: height)
|
126
|
+
end
|
127
|
+
end
|
117
128
|
end
|
118
129
|
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
require_relative 'label'
|
2
|
+
require 'prawn'
|
3
|
+
require 'barby'
|
4
|
+
require 'barby/barcode/code_39'
|
5
|
+
require 'barby/outputter/prawn_outputter'
|
2
6
|
|
3
7
|
# This module is a wrapper for writing confusing ZPL and ZPL2 code
|
4
8
|
module Easyzpl
|
@@ -8,7 +12,7 @@ module Easyzpl
|
|
8
12
|
attr_accessor :variable_fields_count
|
9
13
|
|
10
14
|
# Called when the new method is invoked
|
11
|
-
def initialize(name)
|
15
|
+
def initialize(name, params = {})
|
12
16
|
return if name.nil?
|
13
17
|
return if name.strip.empty?
|
14
18
|
|
@@ -23,22 +27,30 @@ module Easyzpl
|
|
23
27
|
|
24
28
|
# The start of the label
|
25
29
|
label_data.push('^XA^DF' + name + '^FS')
|
30
|
+
|
31
|
+
init_prawn(params)
|
26
32
|
end
|
27
33
|
|
28
34
|
# Sets a variable field that can be recalled
|
29
|
-
def variable_text_field(x, y)
|
35
|
+
def variable_text_field(x, y, params = {})
|
30
36
|
x = 0 unless numeric?(x)
|
31
37
|
y = 0 unless numeric?(y)
|
38
|
+
options = { height: 10, width: 10 }.merge(params)
|
32
39
|
|
33
40
|
# update the variable field count
|
34
41
|
self.variable_fields_count += 1
|
35
42
|
|
36
|
-
label_data.push('^FO' + x.to_s + ',' + y.to_s + '^
|
37
|
-
|
43
|
+
label_data.push('^FO' + x.to_s + ',' + y.to_s + '^AFN,' +
|
44
|
+
options[:height].to_s + ',' + options[:width].to_s +
|
45
|
+
'^FN' + variable_fields_count.to_s + '^FS')
|
46
|
+
|
47
|
+
pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}',
|
48
|
+
at: [x, label_width - y - Integer(options[:height] / 10)],
|
49
|
+
size: options[:height] if label_height && label_width
|
38
50
|
end
|
39
51
|
|
40
52
|
# Sets a variable bar code that can be recalled
|
41
|
-
def variable_bar_code_39(x, y)
|
53
|
+
def variable_bar_code_39(x, y, params = {})
|
42
54
|
x = 0 unless numeric?(x)
|
43
55
|
y = 0 unless numeric?(y)
|
44
56
|
|
@@ -47,6 +59,11 @@ module Easyzpl
|
|
47
59
|
|
48
60
|
label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FN' +
|
49
61
|
variable_fields_count.to_s + '^FS')
|
62
|
+
|
63
|
+
return unless label_height && label_width
|
64
|
+
options = { height: 20 }.merge(params)
|
65
|
+
draw_bar_code_39('VARIABLEFIELD' + variable_fields_count.to_s,
|
66
|
+
x, y, options[:height])
|
50
67
|
end
|
51
68
|
end
|
52
69
|
end
|
data/lib/easyzpl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyzpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Grigajtis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,13 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 1.9.3
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
|
-
requirements:
|
124
|
+
requirements:
|
125
|
+
- Prawn, v1.0.0
|
126
|
+
- Barby, v0.6.1
|
125
127
|
rubyforge_project:
|
126
128
|
rubygems_version: 2.2.2
|
127
129
|
signing_key:
|