Zpl 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS*
2
+ .yardoc/
3
+ ._*
4
+ coverage*
5
+ pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+
5
+ script: bundle exec rspec spec
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup-provider=redcarpet
2
+ --markup=markdown
3
+ --no-private
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in ZPL.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ZPL (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ coderay (1.0.5)
10
+ configatron (2.9.0)
11
+ yamler (>= 0.1.0)
12
+ cover_me (1.2.0)
13
+ configatron
14
+ hashie
15
+ diff-lcs (1.1.3)
16
+ github-markup (0.7.1)
17
+ hashie (1.2.0)
18
+ method_source (0.7.1)
19
+ pry (0.9.8.4)
20
+ coderay (~> 1.0.5)
21
+ method_source (~> 0.7.1)
22
+ slop (>= 2.4.4, < 3)
23
+ pry-nav (0.1.0)
24
+ pry (~> 0.9.8.1)
25
+ redcarpet (2.1.1)
26
+ rspec (2.8.0)
27
+ rspec-core (~> 2.8.0)
28
+ rspec-expectations (~> 2.8.0)
29
+ rspec-mocks (~> 2.8.0)
30
+ rspec-core (2.8.0)
31
+ rspec-expectations (2.8.0)
32
+ diff-lcs (~> 1.1.2)
33
+ rspec-mocks (2.8.0)
34
+ slop (2.4.4)
35
+ yamler (0.1.0)
36
+ yard (0.7.5)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ cover_me
43
+ github-markup
44
+ pry
45
+ pry-nav
46
+ redcarpet
47
+ rspec
48
+ yard
49
+ ZPL!
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ Zebra ZPL [![build status][status-image]][ci]
2
+ =============================================
3
+
4
+ Writing Zebra ZPL files shouldn't vomit raw ASCII in your code.
5
+
6
+ The goal is to provide a DSL for creating these files without mucking about with control codes.
7
+
8
+ Example of the desired usage:
9
+
10
+ ```ruby
11
+ label = ZebraZpl::Label.build do
12
+
13
+ orientation :n
14
+ home [20, 0]
15
+ default_width 0, 0
16
+ print_rate :a
17
+ quantity 4
18
+
19
+ field [5, 20] do
20
+ font :d, height: 60
21
+ width 1175
22
+ lines 5
23
+ data 'Test'
24
+ end
25
+
26
+ end
27
+
28
+ label.to_s # => ^XA^FWN^LH20,0^BY0,0^PRA^PQ4^FO5,20^ADN,60^FB1175,5,,^FDTest^FS^XZ
29
+ ```
30
+
31
+ <!-- links -->
32
+ [ci]: http://travis-ci.org/BM5k/ZPL "build status"
33
+
34
+ <!-- images -->
35
+ [status-image]: https://secure.travis-ci.org/BM5k/ZPL.png?branch=master
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = 'spec/**_spec.rb'
6
+ spec.rspec_opts = ['--backtrace']
7
+ end
8
+
9
+ namespace :cover_me do
10
+
11
+ desc 'Generates and opens code coverage report.'
12
+ task :report do
13
+ require 'cover_me'
14
+ CoverMe.complete!
15
+ end
16
+
17
+ end
18
+
19
+ task :test do
20
+ Rake::Task['cover_me:report'].invoke
21
+ end
22
+
23
+ task :spec do
24
+ Rake::Task['cover_me:report'].invoke
25
+ end
26
+
27
+ task :default => :spec
@@ -0,0 +1,121 @@
1
+ # maybe define re-usable stuffs?
2
+ # font :big_header, size: 12, foo: "D"
3
+
4
+ # Meh, if you want to make re-usable stuffs but don't want to
5
+ # define custom methods like "font", "lines", whatever ... maybe just
6
+ # define font: "Big Header", size: 12, foo: "D"
7
+ #
8
+ # field font: "Big Header" do
9
+ # font "Big Header"
10
+ # end
11
+
12
+ label do
13
+
14
+ orientation :n
15
+ home 20, 0
16
+ default_width 0, 0
17
+ print_rate :a
18
+ home 0, 0
19
+ quantity label_quantity
20
+
21
+ bar_code origin: [130, 75], type: 3 do
22
+ height 100
23
+ data bar_code_a
24
+ end
25
+
26
+ bar_code origin: [920, 2190], :type => :x do
27
+ orientation :n
28
+ height 9
29
+ quality 200
30
+ data bar_code_b
31
+ end
32
+
33
+ field origin: [75, 250] do
34
+ font :d, height: 60
35
+ width 1175
36
+ lines 5
37
+ data field_a
38
+ end
39
+
40
+ field origin: [75, 850] do
41
+ font :d, height: 60
42
+ data field_b
43
+ end
44
+
45
+ field origin: [75, 1050] do
46
+ font :d, height: 60
47
+ data field_c
48
+ end
49
+
50
+ field origin: [75, 1200] do
51
+ font name: 'D', height: 25
52
+ width 1100
53
+ lines 6
54
+ data field_d
55
+ end
56
+
57
+ field origin: [995, 1600] do
58
+ font :d, height: 36
59
+ orientation :n
60
+ data field_e
61
+ end
62
+
63
+ field origin: [895, 1600] do
64
+ font :d, height: 36
65
+ orientation :n
66
+ data field_f
67
+ end
68
+
69
+ field origin: [780, 1620] do
70
+ font :d, height: 36
71
+ orientation :n
72
+ data field_g
73
+ end
74
+
75
+ field origin: [660, 1620] do
76
+ font :d, height: 36
77
+ orientation :n
78
+ data field_h
79
+ end
80
+
81
+ field origin: [565, 1620] do
82
+ orientation :r
83
+ data field_i
84
+ end
85
+
86
+ field origin: [515, 1620] do
87
+ orientation :r
88
+ data field_j
89
+ end
90
+
91
+ field origin: [465, 1620] do
92
+ orientation :r
93
+ data field_k
94
+ end
95
+
96
+ field origin: [415, 1620] do
97
+ orientation :r
98
+ data field_l
99
+ end
100
+
101
+ field origin: [325, 1620] do
102
+ orientation :r
103
+ data field_m
104
+ end
105
+
106
+ field origin: [275, 1620] do
107
+ orientation :r
108
+ data field_n
109
+ end
110
+
111
+ field origin: [225, 1620] do
112
+ orientation :r
113
+ data field_o
114
+ end
115
+
116
+ field origin: [175, 1620] do
117
+ orientation :r
118
+ data field_p
119
+ end
120
+
121
+ end
@@ -0,0 +1,47 @@
1
+ # ### ^BY - Bar Code Field Default
2
+ #
3
+ # The ^BY command is used to change the default values for the module width (in dots), the wide bar to narrow bar width ratio, and the bar code height (in dots). It can be used as often as necessary within a label format.
4
+ #
5
+ # ## Format
6
+ #
7
+ # ^BYw,r,h
8
+ #
9
+ # ## Parameters
10
+ #
11
+ # ### w = module width (in dots)
12
+ # - Initial Value at power-up: 2
13
+ # - Accepted Values: 1 to 10
14
+ #
15
+ # ### r = wide bar to narrow bar width ratio
16
+ # - Default Value: 3.0
17
+ # - Accepted Values: 2.0 to 3.0, in 0.1 increments
18
+ # - This parameter has no effect on fixed-ratio bar codes.
19
+ #
20
+ # ### h = bar code height (in dots)
21
+ #
22
+ # ## Notes
23
+ #
24
+ # For parameter r, the actual ratio generated is a function of the number of dots in parameter w, module width.
25
+ #
26
+ # Once a ^BY command is entered into a label format ,it stays in effect until another ^BY command is encountered.
27
+ module Zpl::Commands::DefaultWidth
28
+
29
+ COMMAND = '^BY'
30
+
31
+ # specifies default values for the module width
32
+ #
33
+ # @overload default_width= w, r, h
34
+ # @param [Integer] w the module width (in dots)
35
+ # @param [Integer] r the wide bar to narrow bar width ratio
36
+ # @param [Integer] h the bar code height (in dots)
37
+ #
38
+ # @example using with builder
39
+ # Zpl::Label.build { default_width 3, 2, 10 }
40
+ #
41
+ # @example setting directly on a field
42
+ # f.default_width = 3, 2, 10
43
+ def default_width= *args
44
+ @data << "#{ COMMAND }#{ [*args].join ',' }"
45
+ end
46
+
47
+ end
@@ -0,0 +1,45 @@
1
+ # ### ^FO - Field Origin
2
+ #
3
+ # The ^FO command sets a field origin, relative to the label home (^LH) position. ^FO sets the upper-left corner of the field area by defining points along the x-axis and y-axis independent of the rotation.
4
+ #
5
+ # ## Format
6
+ #
7
+ # ^FOx,y
8
+ #
9
+ # ## Parameters
10
+ #
11
+ # ### x = x-axis location (in dots)
12
+ #
13
+ # - Default Value: 0
14
+ # - Accepted Values: 0 to 32000
15
+ #
16
+ # ###y = y-axis location (in dots)
17
+ #
18
+ # - Default Value: 0
19
+ # - Accepted Values: 0 to 32000
20
+ #
21
+ # ## Notes
22
+ #
23
+ # If the value entered for the x or y parameter is too high, it could position
24
+ # the field origin completely off the label.
25
+ module Zpl::Commands::FieldOrigin
26
+
27
+ COMMAND = '^FO'
28
+
29
+ # specifies a field origin, relative to the label home
30
+ #
31
+ # @overload origin= x, y
32
+ # @param [Integer] x the x position (in dots)
33
+ # @param [Integer] y the y position (in dots)
34
+ #
35
+ # @example using with builder
36
+ # Zpl::Label.build { origin 3, 2 }
37
+ #
38
+ # @example setting directly on a field
39
+ # f = Zpl::Label.new
40
+ # f.origin = 3, 2
41
+ def origin= *args
42
+ @data << "#{ COMMAND }#{ [*args].join ',' }"
43
+ end
44
+
45
+ end
@@ -0,0 +1,73 @@
1
+ # # ^A - Scalable/Bitmapped Font
2
+ #
3
+ # The ^A command specifies the font to use in a text field. ^A designates the font for the current ^FD statement or field. The font specified by ^A is used only once for that ^FD entry. If a value for ^A is not specified again, the default ^CF font is used for the next ^FD entry.
4
+ #
5
+ # ## Format
6
+ #
7
+ # ^Afo,h,w
8
+ #
9
+ # ## Parameters
10
+ #
11
+ # ### f = font name
12
+ #
13
+ # - Accepted Values: A through Z, and 0 to 9
14
+ # - f is required. If f is omitted it defaults to the last value of the ^CF command.
15
+ #
16
+ # ### o = field orientation
17
+ #
18
+ # - Default Value: the last accepted ^FW value or the ^FW default
19
+ # - Accepted Values
20
+ # - *N* normal
21
+ # - *R* rotated 90 degrees (clockwise)
22
+ # - *I* inverted 180 degrees
23
+ # - *B* read from bottom up, 270 degrees
24
+ #
25
+ # ### h = character height (in dots)
26
+ #
27
+ # - Default Value: last accepted ^CF
28
+ # - Accepted Values
29
+ # - Scalable: 10 to 32000
30
+ # - Bitmapped: multiples of height from 1 to 10 times the standard height, in increments of 1
31
+ #
32
+ # ### w = width (in dots)
33
+ #
34
+ # - Default Value: last accepted ^CF
35
+ # - Accepted Values
36
+ # - Scalable: 10 to 32000
37
+ # - Bitmapped: multiples of width from 1 to 10 times the standard height, in increments of 1
38
+ #
39
+ # ## Notes
40
+ #
41
+ # Fonts are built using a matrix that defines standard height-to-width ratios. If you specify only the height or width value standard matrix for that font automatically determines the other value. If the value is not given or a 0 (zero) is entered, the height or width is determined by the standard font matrix.
42
+ module Zpl::Commands::Font
43
+
44
+ COMMAND = '^A'
45
+
46
+ # specifies the font to use in a text field
47
+ #
48
+ # @overload font= name, opts
49
+ # @param [String] name the name of the font to use
50
+ # @option opts [String] :orientation the orientation
51
+ # @option opts [String] :height the height (in dots)
52
+ # @option opts [String] :width the width (in dots)
53
+ #
54
+ # @see Zpl::Commands::Orientation
55
+ #
56
+ # @example using with builder
57
+ # Zpl::Field.build { font :e, :orientation => :r, height: 15, width: 20 }
58
+ #
59
+ # @example setting directly on a field
60
+ # f.font = :e, :orientation => :r, height: 15, width: 20
61
+ def font= *args
62
+ name, options = args
63
+ options ||= {}
64
+
65
+ params = [options[:height], options[:width]]
66
+
67
+ data = "#{ COMMAND }#{ name }#{ options[:orientation] }".upcase
68
+ data += ",#{ params.join ',' }" if params.any?
69
+
70
+ @data << data
71
+ end
72
+
73
+ end
@@ -0,0 +1,51 @@
1
+ # # ^LH - Label Home
2
+ #
3
+ # The ^LH command sets the label home position. The default home position of a label is the upper-left corner (position 0, 0 along the x and y axis). This is the axis reference point for labels. Any area below and to the right of this point is available for printing. The ^LH command changes this reference point. For instance, when working with preprinted labels, use this command to move the reference point below the preprinted area.
4
+ #
5
+ # This command affects only fields that come after it. It is recommended to use ^LH as one of the first commands in the label format.
6
+ #
7
+ # ## Format
8
+ #
9
+ # ^LHx,y
10
+ #
11
+ # ## Parameters
12
+ #
13
+ # ### x = x-axis position (in dots)
14
+ # - Initial Value at Power-up: 0 or last permanently saved value
15
+ # - Accepted Values: 0 to 32000
16
+ #
17
+ # ### y = y-axis position (in dots)
18
+ # - Initial Value at Power-up: 0 or last permanently saved value
19
+ # - Accepted Values: 0 to 32000
20
+ #
21
+ # ## Notes
22
+ #
23
+ # Depending on the printhead used in your printer, use one of these when figuring the values for x and y:
24
+ #
25
+ # - 6 dots = 1 mm, 152 dots = 1 inch
26
+ # - 8 dots = 1 mm, 203 dots = 1 inch
27
+ # - 11.8 dots = 1 mm, 300 dots = 1 inch
28
+ # - 24 dots = 1 mm, 608 dots = 1 inch
29
+ #
30
+ # To be compatible with existing printers, this command must come before the first ^FS (Field Separator) command. Once you have issued an ^LH command, the setting is retained until you turn off the printer or send a new ^LH command to the printer.
31
+ module Zpl::Commands::Home
32
+
33
+ COMMAND = '^LH'
34
+
35
+ # specifies the label home position
36
+ #
37
+ # @overload home= x, y
38
+ # @param [Integer] x the x position (in dots)
39
+ # @param [Integer] y the y position (in dots)
40
+ #
41
+ # @example using with builder
42
+ # Zpl::Label.build { home 3, 2 }
43
+ #
44
+ # @example setting directly on a label
45
+ # f = Zpl::Label.new
46
+ # f.home = 3, 2
47
+ def home= *args
48
+ @data << "#{ COMMAND }#{ [*args].join ',' }"
49
+ end
50
+
51
+ end
@@ -0,0 +1,40 @@
1
+ # ### ^FW Field Orientation
2
+ #
3
+ # The ^FW command sets the default orientation for all command fields that have an orientation (rotation) parameter. Fields can be rotated 0, 90, 180, or 270 degrees clockwise by using this command.
4
+ #
5
+ # The ^FW command affects only fields that follow it. Once you have issued a ^FW command, the setting is retained until you turn off the printer or send a new ^FW command to the printer.
6
+ #
7
+ # ## Format
8
+ #
9
+ # ^FWr
10
+ #
11
+ # ## Parameters
12
+ #
13
+ # ### r = rotate field
14
+ #
15
+ # - Initial Value at Power-up: **N**
16
+ #
17
+ # - Accepted Values:
18
+ # - **N** = normal
19
+ # - **R** = rotated 90 degrees
20
+ # - **I** = inverted 180 degrees
21
+ # - **B** = bottom-up 270 degrees, read from bottom up
22
+ module Zpl::Commands::Orientation
23
+
24
+ COMMAND = '^FW'
25
+
26
+ # specifies the default orientation for all command fields
27
+ #
28
+ # @param orientation [String] the direction identifier
29
+ #
30
+ # @example using with builder
31
+ # Zpl::Label.build { orientation :r }
32
+ #
33
+ # @example setting directly on a label
34
+ # f = Zpl::Label.new
35
+ # f.orientation = :r
36
+ def orientation= rotation
37
+ @data << "#{ COMMAND }#{ rotation.to_s.upcase }"
38
+ end
39
+
40
+ end
@@ -0,0 +1,89 @@
1
+ # # ^PR Print Rate
2
+ #
3
+ # The ^PR command determines the media and slew speed (feeding a blank label) during printing.
4
+ #
5
+ # The printer operates with the selected speeds until the setting is reissued or the printer is turned off.
6
+ #
7
+ # The print speed is application-specific. Because print quality is affected by media, ribbon, printing speeds, and printer operating modes, it is very important to run tests for your applications. Some models go to default print speed when power is turned off.
8
+ #
9
+ # ## Format
10
+ #
11
+ # ^PRp,s,b
12
+ #
13
+ # ## Parameters
14
+ #
15
+ # ### p = print speed
16
+ #
17
+ # - Default Value: A
18
+ # - Accepted Values:
19
+ # - A or 2 = 50.8 mm/sec. ( 2 inches/sec.)
20
+ # - B or 3 = 76.2 mm/sec. ( 3 inches/sec.)
21
+ # - C or 4 = 101.6 mm/sec. ( 4 inches/sec.)
22
+ # - 5 = 127 mm/sec. ( 5 inches/sec.)
23
+ # - D or 6 = 152.4 mm/sec. ( 6 inches/sec.)
24
+ # - E or 8 = 203.2 mm/sec. ( 8 inches/sec.)
25
+ # - 9 = 220.5 mm/sec. ( 9 inches/sec.)
26
+ # - 10 = 245 mm/sec. (10 inches/sec.)
27
+ # - 11 = 269.5 mm/sec. (11 inches/sec.)
28
+ # - 12 = 304.8 mm/sec. (12 inches/sec.)
29
+ #
30
+ # ### s = slew speed
31
+ #
32
+ # - Default Value: D
33
+ # - Accepted Values:
34
+ # - A or 2 = 50.8 mm/sec. ( 2 inches/sec.)
35
+ # - B or 3 = 76.2 mm/sec. ( 3 inches/sec.)
36
+ # - C or 4 = 101.6 mm/sec. ( 4 inches/sec.)
37
+ # - 5 = 127 mm/sec. ( 5 inches/sec.)
38
+ # - D or 6 = 152.4 mm/sec. ( 6 inches/sec.)
39
+ # - E or 8 = 203.2 mm/sec. ( 8 inches/sec.)
40
+ # - 9 = 220.5 mm/sec. ( 9 inches/sec.)
41
+ # - 10 = 245 mm/sec. (10 inches/sec.)
42
+ # - 11 = 269.5 mm/sec. (11 inches/sec.)
43
+ # - 12 = 304.8 mm/sec. (12 inches/sec.)
44
+ #
45
+ # ### b = backfeed speed
46
+ #
47
+ # - Default Value: A
48
+ # - Accepted Values:
49
+ # - A or 2 = 50.8 mm/sec. ( 2 inches/sec.)
50
+ # - B or 3 = 76.2 mm/sec. ( 3 inches/sec.)
51
+ # - C or 4 = 101.6 mm/sec. ( 4 inches/sec.)
52
+ # - 5 = 127 mm/sec. ( 5 inches/sec.)
53
+ # - D or 6 = 152.4 mm/sec. ( 6 inches/sec.)
54
+ # - E or 8 = 203.2 mm/sec. ( 8 inches/sec.)
55
+ # - 9 = 220.5 mm/sec. ( 9 inches/sec.)
56
+ # - 10 = 245 mm/sec. (10 inches/sec.)
57
+ # - 11 = 269.5 mm/sec. (11 inches/sec.)
58
+ # - 12 = 304.8 mm/sec. (12 inches/sec.)
59
+ #
60
+ # ## Notes
61
+ #
62
+ # The speed setting for p, s, and b is dependent on the limitations of the printer. If a particular printer is limited to a rate of 6 ips (inches per second), a value of 12 can be entered but the printer performs only at a 6 ips rate. See your printer’s User Guide for specifics on performance.
63
+ module Zpl::Commands::PrintRate
64
+
65
+ COMMAND = '^PR'
66
+
67
+ # specifies the media and slew speed
68
+ #
69
+ # @overload print_rate= print_speed, slew_speed, backfeed_speed
70
+ # @param [Integer] print_speed the speed to print
71
+ # @param [Integer] slew_speed the speed to feed blank labels
72
+ # @param [Integer] backfeed_speed the reverse speed
73
+ #
74
+ # @example using with builder
75
+ # Zpl::Label.build { print_rate :a }
76
+ #
77
+ # @example setting directly on a label
78
+ # f = Zpl::Label.new
79
+ # f.print_rate = :a
80
+ def print_rate= *args
81
+ print_speed, slew_speed, backfeed_speed = [*args]
82
+
83
+ print_speed = print_speed.to_s.upcase
84
+ params = [print_speed, slew_speed, backfeed_speed]
85
+
86
+ @data << "#{ COMMAND }#{ params.join ',' }"
87
+ end
88
+
89
+ end
@@ -0,0 +1,54 @@
1
+ # # ^PQ - Print Quantity
2
+ #
3
+ # The ^PQ command gives control over several printing operations. It controls the number of labels to print, the number of labels printed before printer pauses, and the number of replications of each serial number.
4
+ #
5
+ # ## Format
6
+ #
7
+ # ^PQq,p,r,o
8
+ #
9
+ # ## Parameters
10
+ #
11
+ # ### q = total quantity of labels to print
12
+ #
13
+ # - Default Value: 1
14
+ # - Accepted Value: 1 to 99,999,999
15
+ #
16
+ # ### p = pause and cut value (labels between pauses)
17
+ #
18
+ # - Default Value: 0 (no pause)
19
+ # - Accepted Value: 1 to 99,999,999
20
+ #
21
+ # ### r = replicates of each serial number
22
+ #
23
+ # - Default Value: 0 (no replicates)
24
+ # - Accepted Value: 0 to 99,999,999 replicates
25
+ #
26
+ # ### o = override pause count
27
+ #
28
+ # - Accepted Values:
29
+ # - N = no
30
+ # - Y = yes Default Value: N
31
+ #
32
+ # ## Notes
33
+ #
34
+ # If the o parameter is set to Y, the printer cuts but does not pause, and the printer does not pause after every group count of labels has been printed. With the o parameter set to N (default), the printer pauses after every group count of labels has been printed.
35
+ module Zpl::Commands::Quantity
36
+
37
+ COMMAND = '^PQ'
38
+
39
+ # specifies the number of labels to print
40
+ #
41
+ # @overload quantity= qty
42
+ # @param [Integer] qty the number of labels to print
43
+ #
44
+ # @example using with builder
45
+ # Zpl::Label.build { quantity 2 }
46
+ #
47
+ # @example setting directly on a label
48
+ # f = Zpl::Label.new
49
+ # f.quantity = 2
50
+ def quantity= *args
51
+ @data << "#{ COMMAND }#{ args.join ',' }"
52
+ end
53
+
54
+ end
@@ -0,0 +1,12 @@
1
+ module Zpl::Commands
2
+ end
3
+
4
+ %w[
5
+ default_width
6
+ field_origin
7
+ font
8
+ home
9
+ orientation
10
+ print_rate
11
+ quantity
12
+ ].each { |f| require "ZPL/commands/#{ f }"}
data/lib/zpl/field.rb ADDED
@@ -0,0 +1,24 @@
1
+ class Zpl::Field
2
+
3
+ include Zpl::Commands::FieldOrigin
4
+ include Zpl::Commands::Font
5
+
6
+ attr_accessor :data
7
+
8
+ def initialize
9
+ @data = []
10
+ end
11
+
12
+ SUFFIX = '^FS'
13
+
14
+ def self.build &block
15
+ builder = Zpl::FieldBuilder.new
16
+ builder.instance_eval &block
17
+ builder.field
18
+ end
19
+
20
+ def to_s
21
+ "#{ data.join '' }#{ SUFFIX }"
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ class Zpl::FieldBuilder
2
+
3
+ attr_accessor :field
4
+
5
+ def initialize
6
+ @field = Zpl::Field.new
7
+ end
8
+
9
+ def method_missing name, *args
10
+ return super unless field.respond_to? "#{ name }="
11
+
12
+ self.class.send :define_method, "#{ name }" do |*args|
13
+ field.send "#{ name }=", *args
14
+ end
15
+
16
+ send "#{ name }", *args
17
+ end
18
+
19
+ end
data/lib/zpl/label.rb ADDED
@@ -0,0 +1,28 @@
1
+ class Zpl::Label
2
+
3
+ include Zpl::Commands::DefaultWidth
4
+ include Zpl::Commands::Home
5
+ include Zpl::Commands::Orientation
6
+ include Zpl::Commands::PrintRate
7
+ include Zpl::Commands::Quantity
8
+
9
+ attr_accessor :data
10
+
11
+ def initialize
12
+ @data = []
13
+ end
14
+
15
+ PREFIX = '^XA'
16
+ SUFFIX = '^XZ'
17
+
18
+ def self.build &block
19
+ builder = Zpl::LabelBuilder.new
20
+ builder.instance_eval &block
21
+ builder.label
22
+ end
23
+
24
+ def to_s
25
+ "#{ PREFIX }#{ data.join '' }#{ SUFFIX }"
26
+ end
27
+
28
+ end
@@ -0,0 +1,19 @@
1
+ class Zpl::LabelBuilder
2
+
3
+ attr_accessor :label
4
+
5
+ def initialize
6
+ @label = Zpl::Label.new
7
+ end
8
+
9
+ def method_missing name, *args
10
+ return super unless label.respond_to? "#{ name }="
11
+
12
+ self.class.send :define_method, "#{ name }" do |*args|
13
+ label.send "#{ name }=", *args
14
+ end
15
+
16
+ send "#{ name }", *args
17
+ end
18
+
19
+ end
@@ -0,0 +1,3 @@
1
+ module Zpl
2
+ VERSION = '0.0.2'
3
+ end
data/lib/zpl.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Zpl
2
+ end
3
+
4
+ require 'Zpl/commands'
5
+
6
+ %w[ field label ].each do |lib|
7
+ require "Zpl/#{ lib }"
8
+ require "Zpl/#{ lib }_builder"
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zpl::FieldBuilder do
4
+
5
+ it 'returns a field' do
6
+ Zpl::Field.build {}.should be_a(Zpl::Field)
7
+ end
8
+
9
+ describe '#default_width' do
10
+
11
+ it 'adds an Field Origin to the field' do
12
+ Zpl::Field.build { origin [46, 2] }.to_s.should =~ /\^FO46,2/
13
+ end
14
+
15
+ it 'adds a Scalable/Bitmapped Font to the field' do
16
+ Zpl::Field.build { font :a }.to_s.should =~ /\^AA/
17
+ Zpl::Field.build { font :b, :orientation => :n }.to_s.should =~ /\^ABN/
18
+ Zpl::Field.build { font :c, height: 30 }.to_s.should =~ /\^AC,30/
19
+ Zpl::Field.build { font :d, height: 15, width: 20 }.to_s.should =~ /\^AD,15,20/
20
+ Zpl::Field.build { font :e, :orientation => :r, height: 15, width: 20 }.to_s.should =~ /\^AER,15,20/
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zpl::Field do
4
+
5
+ describe 'constants' do
6
+
7
+ it 'SUFFIX' do
8
+ Zpl::Field::SUFFIX.should == '^FS'
9
+ end
10
+
11
+ end
12
+
13
+ describe 'commands' do
14
+
15
+ let(:field) { Zpl::Field.new }
16
+
17
+ describe '#origin=' do
18
+
19
+ it 'adds an Field Origin to the field' do
20
+ field.origin = [46, 2]
21
+ field.data.should include('^FO46,2')
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ its(:to_s) { should =~ /\^FS$/ }
29
+
30
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zpl::LabelBuilder do
4
+
5
+ it 'returns a label' do
6
+ Zpl::Label.build {}.should be_a(Zpl::Label)
7
+ end
8
+
9
+ describe '#default_width' do
10
+
11
+ it 'adds an Bar Code Field Default to the label' do
12
+ Zpl::Label.build { default_width 3 }.to_s.should =~ /\^BY3/
13
+ end
14
+
15
+ end
16
+
17
+ describe '#home' do
18
+
19
+ it 'adds a Label Home command to the label' do
20
+ Zpl::Label.build { home [5, 10] }.to_s.should =~ /\^LH5,10/
21
+ end
22
+
23
+ end
24
+
25
+ describe '#orientation' do
26
+
27
+ it 'adds a Field Orientation command to the label' do
28
+ Zpl::Label.build { orientation :n }.to_s.should =~ /\^FWN/
29
+ end
30
+
31
+ end
32
+
33
+ describe '#print_rate' do
34
+
35
+ it 'adds an Bar Code Field Default to the label' do
36
+ Zpl::Label.build { print_rate :a }.to_s.should =~ /\^PRA,,/
37
+ end
38
+
39
+ end
40
+
41
+ describe '#quantity' do
42
+
43
+ it 'adds an Bar Code Field Default to the label' do
44
+ Zpl::Label.build { quantity 4 }.to_s.should =~ /\^PQ4/
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zpl::Label do
4
+
5
+ describe 'constants' do
6
+
7
+ it 'PREFIX' do
8
+ Zpl::Label::PREFIX.should == '^XA'
9
+ end
10
+
11
+ it 'SUFFIX' do
12
+ Zpl::Label::SUFFIX.should == '^XZ'
13
+ end
14
+
15
+ end
16
+
17
+ describe 'commands' do
18
+
19
+ let(:label) { Zpl::Label.new }
20
+
21
+ describe '#default_width=' do
22
+
23
+ it 'adds an Bar Code Field Default to the label' do
24
+ label.default_width = 3
25
+ label.data.should include('^BY3')
26
+ end
27
+
28
+ end
29
+
30
+ describe '#home=' do
31
+
32
+ it 'adds a Label Home command to the label' do
33
+ label.home = [5, 10]
34
+ label.data.should include('^LH5,10')
35
+ end
36
+
37
+ end
38
+
39
+ describe '#orientation=' do
40
+
41
+ it 'adds a Field Orientation command to the label' do
42
+ label.orientation = :n
43
+ label.data.should include('^FWN')
44
+ end
45
+
46
+ end
47
+
48
+ describe '#print_rate=' do
49
+
50
+ it 'adds an Bar Code Field Default to the label' do
51
+ label.print_rate = :a
52
+ label.data.should include('^PRA,,')
53
+ end
54
+
55
+ end
56
+
57
+ describe '#quantity=' do
58
+
59
+ it 'adds an Bar Code Field Default to the label' do
60
+ label.quantity = 4
61
+ label.data.should include('^PQ4')
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ its(:to_s) { should =~ /^\^XA/ }
69
+ its(:to_s) { should =~ /\^XZ$/ }
70
+
71
+ end
@@ -0,0 +1 @@
1
+ %w[ cover_me ZPL pry pry-nav ].each { |lib| require lib }
data/zpl.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'zpl/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'Zpl'
7
+ s.version = Zpl::VERSION
8
+ s.authors = ['Scott deVries']
9
+ s.email = ['scottd@itempath.com']
10
+ s.homepage = 'https://github.com/scottdevries/Zpl'
11
+ s.summary = 'Create ZPL label strings.'
12
+ s.description = 'Use ruby to describe labels, fields, and barcodes for printing via ZPL II.'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename f }
17
+ s.require_paths = ['lib']
18
+
19
+ %w[ cover_me zpl rspec pry pry-nav yard redcarpet github-markup ].each { |lib| s.add_development_dependency lib }
20
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Zpl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott deVries
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cover_me
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: zpl
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-nav
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: redcarpet
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: github-markup
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Use ruby to describe labels, fields, and barcodes for printing via ZPL
143
+ II.
144
+ email:
145
+ - scottd@itempath.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .rspec
152
+ - .travis.yml
153
+ - .yardopts
154
+ - Gemfile
155
+ - Gemfile.lock
156
+ - README.md
157
+ - Rakefile
158
+ - lib/brainstorming.rb
159
+ - lib/zpl.rb
160
+ - lib/zpl/commands.rb
161
+ - lib/zpl/commands/default_width.rb
162
+ - lib/zpl/commands/field_origin.rb
163
+ - lib/zpl/commands/font.rb
164
+ - lib/zpl/commands/home.rb
165
+ - lib/zpl/commands/orientation.rb
166
+ - lib/zpl/commands/print_rate.rb
167
+ - lib/zpl/commands/quantity.rb
168
+ - lib/zpl/field.rb
169
+ - lib/zpl/field_builder.rb
170
+ - lib/zpl/label.rb
171
+ - lib/zpl/label_builder.rb
172
+ - lib/zpl/version.rb
173
+ - spec/field_builder_spec.rb
174
+ - spec/field_spec.rb
175
+ - spec/label_builder_spec.rb
176
+ - spec/label_spec.rb
177
+ - spec/spec_helper.rb
178
+ - zpl.gemspec
179
+ homepage: https://github.com/scottdevries/Zpl
180
+ licenses: []
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 1.8.24
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: Create ZPL label strings.
203
+ test_files:
204
+ - spec/field_builder_spec.rb
205
+ - spec/field_spec.rb
206
+ - spec/label_builder_spec.rb
207
+ - spec/label_spec.rb
208
+ - spec/spec_helper.rb