prawn-icon 1.1.1 → 1.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/data/fonts/fa/LICENSE +1 -1
- data/data/fonts/fa/fa.yml +137 -101
- data/data/fonts/fa/fontawesome.ttf +0 -0
- data/examples/fontawesome.rb +1 -1
- data/examples/foundation_icons.rb +1 -1
- data/examples/octicons.rb +1 -1
- data/examples/paymentfont.rb +1 -1
- data/lib/prawn/icon.rb +3 -14
- data/lib/prawn/icon/base.rb +19 -0
- data/lib/prawn/icon/errors.rb +13 -0
- data/lib/prawn/icon/font_data.rb +6 -6
- data/lib/prawn/icon/version.rb +1 -1
- data/prawn-icon.gemspec +1 -1
- data/spec/integration/icon_spec.rb +21 -25
- data/spec/support/parser_helper.rb +1 -1
- data/spec/support/pdf_helper.rb +1 -1
- data/spec/unit/base_spec.rb +15 -0
- data/spec/unit/errors/icon_key_empty_spec.rb +19 -0
- data/spec/unit/errors/icon_not_found_spec.rb +19 -0
- data/spec/unit/font_data_spec.rb +42 -60
- data/spec/unit/icon_spec.rb +5 -12
- data/spec/unit/parser_spec.rb +47 -44
- metadata +9 -4
data/spec/unit/icon_spec.rb
CHANGED
@@ -7,26 +7,26 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe Prawn::Icon do
|
10
|
+
let(:errors) { described_class::Errors }
|
11
|
+
let(:pdf) { create_pdf }
|
12
|
+
|
10
13
|
describe '#initialize' do
|
11
14
|
context 'valid icon family specifier' do
|
12
15
|
it 'should be capable of creating icon instances' do
|
13
|
-
pdf = create_pdf
|
14
16
|
icon = Prawn::Icon.new 'fa-arrows', pdf
|
15
17
|
|
16
18
|
expect(icon.unicode).to eq("\uf047")
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'should raise an error if icon key is not found' do
|
20
|
-
pdf = create_pdf
|
21
22
|
proc = Proc.new { Prawn::Icon.new 'fa-__INVALID__', pdf }
|
22
23
|
|
23
|
-
expect(proc).to raise_error(
|
24
|
+
expect(proc).to raise_error(errors::IconNotFound)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'invalid icon specifier' do
|
28
29
|
it 'should raise an error' do
|
29
|
-
pdf = create_pdf
|
30
30
|
proc = Proc.new { pdf.icon '__INVALID__ some text' }
|
31
31
|
|
32
32
|
expect(proc).to raise_error(Prawn::Errors::UnknownFont)
|
@@ -44,7 +44,6 @@ describe Prawn::Icon do
|
|
44
44
|
|
45
45
|
describe '#format_hash' do
|
46
46
|
it 'should add :font and :content keys' do
|
47
|
-
pdf = create_pdf
|
48
47
|
icon = Prawn::Icon.new 'fa-arrows', pdf
|
49
48
|
hash = icon.format_hash
|
50
49
|
|
@@ -53,7 +52,6 @@ describe Prawn::Icon do
|
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'should rename key :color to :text_color' do
|
56
|
-
pdf = create_pdf
|
57
55
|
icon = Prawn::Icon.new 'fa-arrows', pdf, color: '0099ff'
|
58
56
|
hash = icon.format_hash
|
59
57
|
|
@@ -64,7 +62,6 @@ describe Prawn::Icon do
|
|
64
62
|
|
65
63
|
describe '#render' do
|
66
64
|
it 'should render an icon to the page' do
|
67
|
-
pdf = create_pdf
|
68
65
|
pdf.icon('fa-arrows').render
|
69
66
|
text = PDF::Inspector::Text.analyze(pdf.render)
|
70
67
|
|
@@ -75,7 +72,6 @@ describe Prawn::Icon do
|
|
75
72
|
describe '#set' do
|
76
73
|
context 'with dashes in key' do
|
77
74
|
it 'should return the set as a symbol from key' do
|
78
|
-
pdf = create_pdf
|
79
75
|
set = Prawn::Icon.new('fa-arrows', pdf).set
|
80
76
|
|
81
77
|
expect(set).to eq(:fa)
|
@@ -84,7 +80,6 @@ describe Prawn::Icon do
|
|
84
80
|
|
85
81
|
context 'without dashes in key' do
|
86
82
|
it 'raise an error about invalid keys' do
|
87
|
-
pdf = create_pdf
|
88
83
|
proc = Proc.new { Prawn::Icon.new 'some invalid key', pdf }
|
89
84
|
|
90
85
|
expect(proc).to raise_error(Prawn::Errors::UnknownFont)
|
@@ -95,7 +90,6 @@ describe Prawn::Icon do
|
|
95
90
|
describe '#unicode' do
|
96
91
|
context 'valid icon key' do
|
97
92
|
it 'should return a unicode character' do
|
98
|
-
pdf = create_pdf
|
99
93
|
icon = Prawn::Icon.new 'fa-arrows', pdf
|
100
94
|
|
101
95
|
expect(valid_unicode?(icon.unicode)).to be true
|
@@ -104,10 +98,9 @@ describe Prawn::Icon do
|
|
104
98
|
|
105
99
|
context 'invalid icon key' do
|
106
100
|
it 'should raise IconNotFound' do
|
107
|
-
pdf = create_pdf
|
108
101
|
proc = Proc.new { Prawn::Icon.new 'fa-__INVALID__', pdf }
|
109
102
|
|
110
|
-
expect(proc).to raise_error(
|
103
|
+
expect(proc).to raise_error(errors::IconNotFound)
|
111
104
|
end
|
112
105
|
end
|
113
106
|
end
|
data/spec/unit/parser_spec.rb
CHANGED
@@ -7,10 +7,11 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe Prawn::Icon::Parser do
|
10
|
+
let(:pdf) { create_pdf }
|
11
|
+
|
10
12
|
describe '::format' do
|
11
13
|
it 'should return a raw prawn-formatted string on valid input' do
|
12
14
|
string = '<icon>fa-arrows</icon>'
|
13
|
-
pdf = create_pdf
|
14
15
|
formatted = Prawn::Icon::Parser.format(pdf, string)
|
15
16
|
match = "<font name=\"fa\"></font>"
|
16
17
|
|
@@ -23,7 +24,6 @@ describe Prawn::Icon::Parser do
|
|
23
24
|
Here's some sample text.
|
24
25
|
<i>more text</i>
|
25
26
|
EOS
|
26
|
-
pdf = create_pdf
|
27
27
|
formatted = Prawn::Icon::Parser.format(pdf, string)
|
28
28
|
|
29
29
|
expect(formatted).to eq(string)
|
@@ -31,7 +31,6 @@ describe Prawn::Icon::Parser do
|
|
31
31
|
|
32
32
|
it 'should return the empty string if given the empty string' do
|
33
33
|
string = ''
|
34
|
-
pdf = create_pdf
|
35
34
|
formatted = Prawn::Icon::Parser.format(pdf, string)
|
36
35
|
|
37
36
|
expect(formatted).to be_empty
|
@@ -39,7 +38,6 @@ describe Prawn::Icon::Parser do
|
|
39
38
|
|
40
39
|
it 'should raise an error when an icon key is invalid' do
|
41
40
|
string = '<icon>an invalid key</icon>'
|
42
|
-
pdf = create_pdf
|
43
41
|
proc = Proc.new { Prawn::Icon::Parser.format(pdf, string) }
|
44
42
|
|
45
43
|
expect(proc).to raise_error(Prawn::Errors::UnknownFont)
|
@@ -47,10 +45,9 @@ describe Prawn::Icon::Parser do
|
|
47
45
|
|
48
46
|
it 'should raise an error when an icon is not found for valid set' do
|
49
47
|
string = '<icon>fa-__INVALID__</icon>'
|
50
|
-
pdf = create_pdf
|
51
48
|
proc = Proc.new { Prawn::Icon::Parser.format(pdf, string) }
|
52
49
|
|
53
|
-
expect(proc).to raise_error(Prawn::Errors::IconNotFound)
|
50
|
+
expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
@@ -122,7 +119,6 @@ describe Prawn::Icon::Parser do
|
|
122
119
|
string = ''
|
123
120
|
config = []
|
124
121
|
content = contentize_string(string)
|
125
|
-
pdf = create_pdf
|
126
122
|
icons = Prawn::Icon::Parser.keys_to_unicode(pdf, content, config)
|
127
123
|
|
128
124
|
expect(icons).to be_empty
|
@@ -133,7 +129,6 @@ describe Prawn::Icon::Parser do
|
|
133
129
|
tokens = tokenize_string(string)
|
134
130
|
content = contentize_string(string)
|
135
131
|
config = Prawn::Icon::Parser.config_from_tokens(tokens)
|
136
|
-
pdf = create_pdf
|
137
132
|
icons = Prawn::Icon::Parser.keys_to_unicode(pdf, content, config)
|
138
133
|
icon = icons.first[:content]
|
139
134
|
|
@@ -146,7 +141,6 @@ describe Prawn::Icon::Parser do
|
|
146
141
|
tokens = tokenize_string(string)
|
147
142
|
content = contentize_string(string)
|
148
143
|
config = Prawn::Icon::Parser.config_from_tokens(tokens)
|
149
|
-
pdf = create_pdf
|
150
144
|
icons = Prawn::Icon::Parser.keys_to_unicode(pdf, content, config)
|
151
145
|
icon = icons.first
|
152
146
|
|
@@ -164,7 +158,6 @@ describe Prawn::Icon::Parser do
|
|
164
158
|
tokens = tokenize_string(string)
|
165
159
|
content = contentize_string(string)
|
166
160
|
config = Prawn::Icon::Parser.config_from_tokens(tokens)
|
167
|
-
pdf = create_pdf
|
168
161
|
icons = Prawn::Icon::Parser.keys_to_unicode(pdf, content, config)
|
169
162
|
first = icons.first
|
170
163
|
second = icons[1]
|
@@ -179,40 +172,50 @@ describe Prawn::Icon::Parser do
|
|
179
172
|
end
|
180
173
|
|
181
174
|
describe '::icon_tags' do
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
175
|
+
let(:tags) { Prawn::Icon::Parser.icon_tags(icons) }
|
176
|
+
|
177
|
+
context 'with color attribute' do
|
178
|
+
let(:icons) do
|
179
|
+
[
|
180
|
+
{ set: :fa, color: 'CCCCCC', content: "\uf001" }
|
181
|
+
]
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should return valid input as prawn formatted text tags wrapping color tags' do
|
185
|
+
match = "<font name=\"fa\"><color rgb=\"CCCCCC\">\uf001</color></font>"
|
186
|
+
|
187
|
+
expect(tags).to eq([match])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'without the color attribute' do
|
192
|
+
let(:icons) do
|
193
|
+
[
|
194
|
+
{ set: :fa, content: "\uf001" }
|
195
|
+
]
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should return valid input as prawn formatted text tags without color' do
|
199
|
+
match = "<font name=\"fa\">\uf001</font>"
|
200
|
+
|
201
|
+
expect(tags).to eq([match])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'with multiple icon fonts' do
|
206
|
+
let(:icons) do
|
207
|
+
[
|
208
|
+
{ set: :fa, content: "\uf001" },
|
209
|
+
{ set: :fi, content: "\uf001" }
|
210
|
+
]
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should be capable of handling multiple icon fonts' do
|
214
|
+
match1 = "<font name=\"fa\">\uf001</font>"
|
215
|
+
match2 = "<font name=\"fi\">\uf001</font>"
|
216
|
+
|
217
|
+
expect(tags).to eq([match1, match2])
|
218
|
+
end
|
216
219
|
end
|
217
220
|
end
|
218
221
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-icon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 3.
|
53
|
+
version: 3.5.0
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 3.
|
60
|
+
version: 3.5.0
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rubocop
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,8 @@ files:
|
|
139
139
|
- examples/octicons.rb
|
140
140
|
- examples/paymentfont.rb
|
141
141
|
- lib/prawn/icon.rb
|
142
|
+
- lib/prawn/icon/base.rb
|
143
|
+
- lib/prawn/icon/errors.rb
|
142
144
|
- lib/prawn/icon/font_data.rb
|
143
145
|
- lib/prawn/icon/parser.rb
|
144
146
|
- lib/prawn/icon/version.rb
|
@@ -147,6 +149,9 @@ files:
|
|
147
149
|
- spec/spec_helper.rb
|
148
150
|
- spec/support/parser_helper.rb
|
149
151
|
- spec/support/pdf_helper.rb
|
152
|
+
- spec/unit/base_spec.rb
|
153
|
+
- spec/unit/errors/icon_key_empty_spec.rb
|
154
|
+
- spec/unit/errors/icon_not_found_spec.rb
|
150
155
|
- spec/unit/font_data_spec.rb
|
151
156
|
- spec/unit/icon_spec.rb
|
152
157
|
- spec/unit/parser_spec.rb
|