labels 0.0.6 → 0.0.7
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/dtd/label.dtd +10 -9
- data/example/label.xml +6 -6
- data/lib/labels/database.rb +19 -0
- data/lib/labels/document.rb +10 -4
- data/lib/labels/pdf/builder.rb +7 -6
- data/lib/labels/version.rb +1 -1
- data/lib/labels/xml/builder.rb +4 -4
- data/lib/labels/xml/parser.rb +18 -10
- data/spec/labels/database_spec.rb +17 -0
- metadata +7 -4
data/dtd/label.dtd
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
<!ELEMENT label (paper,template,layers,data)>
|
2
2
|
|
3
|
-
<!ATTLIST paper title CDATA #
|
3
|
+
<!ATTLIST paper title CDATA #REQUIRED>
|
4
4
|
<!ELEMENT paper (width,height)>
|
5
5
|
|
6
|
-
<!ATTLIST template title CDATA #
|
7
|
-
<!ATTLIST template description CDATA #
|
8
|
-
<!ATTLIST template manufacturer CDATA #
|
9
|
-
<!ATTLIST template category CDATA #
|
6
|
+
<!ATTLIST template title CDATA #REQUIRED>
|
7
|
+
<!ATTLIST template description CDATA #REQUIRED>
|
8
|
+
<!ATTLIST template manufacturer CDATA #REQUIRED>
|
9
|
+
<!ATTLIST template category CDATA #REQUIRED>
|
10
10
|
<!ATTLIST template visible (false|true) #REQUIRED>
|
11
11
|
<!ELEMENT template (width,height,columns,rows,left-margin,right-margin,top-margin,bottom-margin,horizontal-gutter,vertical-gutter,elliptical,corner-radius)>
|
12
12
|
|
13
13
|
<!ELEMENT layers (layer+)>
|
14
14
|
|
15
|
-
<!ATTLIST layer title CDATA #
|
15
|
+
<!ATTLIST layer title CDATA #REQUIRED>
|
16
16
|
<!ATTLIST layer type CDATA #REQUIRED>
|
17
|
-
<!ATTLIST layer column CDATA #
|
17
|
+
<!ATTLIST layer column CDATA #REQUIRED>
|
18
18
|
<!ATTLIST layer locked (false|true) #REQUIRED>
|
19
19
|
<!ATTLIST layer visible (false|true) #REQUIRED>
|
20
20
|
<!ELEMENT layer (x,y,width,height,alpha,rotation,content,corner-radius?,elliptical?,fill?,stroke?,fill-color?,stroke-color?,stroke-weight?,font-family?,font-size?,font-color?,bold?,italic?,justification?,fit?,stretch?,symbology?,bar-width?,bar-height?,color?,caption-height?,caption-size?,captioned?,format?)>
|
21
21
|
|
22
|
-
<!
|
22
|
+
<!ATTLIST database title CDATA #REQUIRED>
|
23
|
+
<!ELEMENT database (row+)>
|
23
24
|
|
24
|
-
<!ELEMENT
|
25
|
+
<!ELEMENT row (key+)>
|
25
26
|
|
26
27
|
<!ATTLIST key name CDATA #REQUIRED>
|
27
28
|
<!ATTLIST key type (string|integer|float|boolean|date) #REQUIRED>
|
data/example/label.xml
CHANGED
@@ -151,18 +151,18 @@
|
|
151
151
|
</layers>
|
152
152
|
|
153
153
|
<!-- Data -->
|
154
|
-
<
|
154
|
+
<database title="DB">
|
155
155
|
|
156
|
-
<!--
|
157
|
-
<
|
156
|
+
<!-- Row -->
|
157
|
+
<row>
|
158
158
|
<key name="string">000222111</key>
|
159
159
|
<key name="data">iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==</key>
|
160
160
|
<key name="date">2007-06-01T13:00:00Z</key>
|
161
161
|
<key name="integer">123</key>
|
162
162
|
<key name="float">1.23</key>
|
163
163
|
<key name="boolean">false</key>
|
164
|
-
</
|
164
|
+
</row>
|
165
165
|
|
166
|
-
<!-- More
|
167
|
-
</
|
166
|
+
<!-- More rows... -->
|
167
|
+
</database>
|
168
168
|
</label>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# A RubyGem for creating mailing, shipping, address, barcode and other labels and rendering as PDF's.
|
2
|
+
#
|
3
|
+
# Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
|
4
|
+
# Copyright:: Copyright (c) 2012 Infinite Token LLC
|
5
|
+
# License:: MIT License
|
6
|
+
|
7
|
+
require 'labels/element'
|
8
|
+
|
9
|
+
module Labels
|
10
|
+
|
11
|
+
# This class represents template types and properties
|
12
|
+
class Database < Element
|
13
|
+
# Title of database
|
14
|
+
attr_accessor :title
|
15
|
+
|
16
|
+
# Array of database data
|
17
|
+
attr_accessor :data
|
18
|
+
end
|
19
|
+
end
|
data/lib/labels/document.rb
CHANGED
@@ -8,6 +8,7 @@ require 'fileutils'
|
|
8
8
|
|
9
9
|
require 'labels/paper'
|
10
10
|
require 'labels/template'
|
11
|
+
require 'labels/database'
|
11
12
|
require 'labels/xml/builder'
|
12
13
|
require 'labels/pdf/builder'
|
13
14
|
|
@@ -25,11 +26,11 @@ module Labels
|
|
25
26
|
# An array of document Labels::Layer instances
|
26
27
|
attr_accessor :layers
|
27
28
|
|
28
|
-
#
|
29
|
-
attr_accessor :
|
29
|
+
# The document Labels::Database instance
|
30
|
+
attr_accessor :database
|
30
31
|
|
31
32
|
# Creates a new Labels::Document instance with optional content
|
32
|
-
def initialize(paper=nil, template=nil, layers=[],
|
33
|
+
def initialize(paper=nil, template=nil, layers=[], database=nil)
|
33
34
|
unless paper.nil?
|
34
35
|
@paper = paper
|
35
36
|
else
|
@@ -43,7 +44,12 @@ module Labels
|
|
43
44
|
end
|
44
45
|
|
45
46
|
@layers = layers
|
46
|
-
|
47
|
+
|
48
|
+
unless database.nil?
|
49
|
+
@database = database
|
50
|
+
else
|
51
|
+
@database = Labels::Database.new
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
# Writes document to filename as XML
|
data/lib/labels/pdf/builder.rb
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
require 'labels/document'
|
8
8
|
require 'labels/paper'
|
9
9
|
require 'labels/template'
|
10
|
+
require 'labels/database'
|
10
11
|
require 'labels/shape'
|
11
12
|
require 'labels/text'
|
12
13
|
require 'labels/image'
|
@@ -43,7 +44,7 @@ module Labels
|
|
43
44
|
unless @document.nil?
|
44
45
|
paper = @document.paper
|
45
46
|
template = @document.template
|
46
|
-
|
47
|
+
database = @document.database
|
47
48
|
|
48
49
|
if paper && template
|
49
50
|
document_options = {
|
@@ -55,7 +56,7 @@ module Labels
|
|
55
56
|
}
|
56
57
|
|
57
58
|
page_cell_count = template.columns * template.rows
|
58
|
-
page_number_count = (data.length / page_cell_count).ceil
|
59
|
+
page_number_count = (database.data.length / page_cell_count).ceil
|
59
60
|
cell = 0
|
60
61
|
|
61
62
|
if page_number_count == 0
|
@@ -95,10 +96,10 @@ module Labels
|
|
95
96
|
|
96
97
|
draw = false
|
97
98
|
content = nil
|
98
|
-
if data.length > 0
|
99
|
-
if cell < data.length
|
100
|
-
if data[cell].has_key?(layer.column)
|
101
|
-
content = data[cell][layer.column]
|
99
|
+
if database.data.length > 0
|
100
|
+
if cell < database.data.length
|
101
|
+
if database.data[cell].has_key?(layer.column)
|
102
|
+
content = database.data[cell][layer.column]
|
102
103
|
end
|
103
104
|
draw = true
|
104
105
|
end
|
data/lib/labels/version.rb
CHANGED
data/lib/labels/xml/builder.rb
CHANGED
@@ -111,10 +111,10 @@ module Labels
|
|
111
111
|
}
|
112
112
|
end
|
113
113
|
}
|
114
|
-
xml.
|
115
|
-
@document.data.each do |
|
116
|
-
xml.
|
117
|
-
|
114
|
+
xml.database(:title => @document.database.title) {
|
115
|
+
@document.database.data.each do |row|
|
116
|
+
xml.row {
|
117
|
+
row.each do |key, value|
|
118
118
|
case value
|
119
119
|
when Fixnum
|
120
120
|
xml.key value, :name => key, :type => 'integer'
|
data/lib/labels/xml/parser.rb
CHANGED
@@ -12,6 +12,7 @@ require 'core_ext/string'
|
|
12
12
|
require 'labels/document'
|
13
13
|
require 'labels/paper'
|
14
14
|
require 'labels/template'
|
15
|
+
require 'labels/database'
|
15
16
|
require 'labels/shape'
|
16
17
|
require 'labels/text'
|
17
18
|
require 'labels/image'
|
@@ -38,7 +39,8 @@ module Labels
|
|
38
39
|
paper_node = root_node.at_xpath('paper')
|
39
40
|
template_node = root_node.at_xpath('template')
|
40
41
|
layer_nodes = root_node.xpath('layers/layer')
|
41
|
-
|
42
|
+
database_node = root_node.at_xpath('database')
|
43
|
+
row_nodes = root_node.xpath('database/row')
|
42
44
|
|
43
45
|
unless paper_node.nil?
|
44
46
|
paper = Labels::Paper.new({
|
@@ -142,19 +144,25 @@ module Labels
|
|
142
144
|
end
|
143
145
|
end
|
144
146
|
|
145
|
-
unless
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
unless database_node.nil?
|
148
|
+
database = Labels::Database.new({
|
149
|
+
:title => database_node['title']
|
150
|
+
})
|
151
|
+
unless row_nodes.nil?
|
152
|
+
data = []
|
153
|
+
row_nodes.each do |row_node|
|
154
|
+
row = {}
|
155
|
+
keys_node = row_node.xpath('key')
|
156
|
+
keys_node.each do |key_node|
|
157
|
+
row[key_node['name']] = key_node.text
|
158
|
+
end
|
159
|
+
data.push(row)
|
152
160
|
end
|
153
|
-
data
|
161
|
+
database.data = data
|
154
162
|
end
|
155
163
|
end
|
156
164
|
|
157
|
-
Labels::Document.new(paper, template, layers,
|
165
|
+
Labels::Document.new(paper, template, layers, database)
|
158
166
|
end
|
159
167
|
end
|
160
168
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# A RubyGem for creating mailing, shipping, address, barcode and other labels and rendering as PDF's.
|
2
|
+
#
|
3
|
+
# Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
|
4
|
+
# Copyright:: Copyright (c) 2012 Infinite Token LLC
|
5
|
+
# License:: MIT License
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'labels/database'
|
9
|
+
|
10
|
+
describe Labels::Database do
|
11
|
+
describe "#new" do
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#run" do
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: labels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/core_ext/string.rb
|
129
129
|
- lib/labels.rb
|
130
130
|
- lib/labels/barcode.rb
|
131
|
+
- lib/labels/database.rb
|
131
132
|
- lib/labels/date.rb
|
132
133
|
- lib/labels/document.rb
|
133
134
|
- lib/labels/element.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- lib/labels/xml/builder.rb
|
144
145
|
- lib/labels/xml/parser.rb
|
145
146
|
- spec/labels/barcode_spec.rb
|
147
|
+
- spec/labels/database_spec.rb
|
146
148
|
- spec/labels/date_spec.rb
|
147
149
|
- spec/labels/document_spec.rb
|
148
150
|
- spec/labels/element_spec.rb
|
@@ -172,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
174
|
version: '0'
|
173
175
|
segments:
|
174
176
|
- 0
|
175
|
-
hash:
|
177
|
+
hash: 2236236549244294766
|
176
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
179
|
none: false
|
178
180
|
requirements:
|
@@ -181,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
183
|
version: '0'
|
182
184
|
segments:
|
183
185
|
- 0
|
184
|
-
hash:
|
186
|
+
hash: 2236236549244294766
|
185
187
|
requirements: []
|
186
188
|
rubyforge_project: labels
|
187
189
|
rubygems_version: 1.8.24
|
@@ -190,6 +192,7 @@ specification_version: 3
|
|
190
192
|
summary: PDF label creation using Ruby
|
191
193
|
test_files:
|
192
194
|
- spec/labels/barcode_spec.rb
|
195
|
+
- spec/labels/database_spec.rb
|
193
196
|
- spec/labels/date_spec.rb
|
194
197
|
- spec/labels/document_spec.rb
|
195
198
|
- spec/labels/element_spec.rb
|