prawn-icon 1.0.0 → 2.0.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -1
  3. data/GPLv2 +21 -22
  4. data/README.md +10 -10
  5. data/data/fonts/fab/LICENSE +34 -0
  6. data/data/fonts/fab/fa-brands.ttf +0 -0
  7. data/data/fonts/fab/fab.yml +333 -0
  8. data/data/fonts/far/LICENSE +34 -0
  9. data/data/fonts/far/fa-regular.ttf +0 -0
  10. data/data/fonts/far/far.yml +119 -0
  11. data/data/fonts/fas/LICENSE +34 -0
  12. data/data/fonts/fas/fa-solid.ttf +0 -0
  13. data/data/fonts/fas/fas.yml +503 -0
  14. data/data/fonts/pf/paymentfont-webfont.ttf +0 -0
  15. data/data/fonts/pf/pf.yml +118 -97
  16. data/examples/fas-beer-inline.png +0 -0
  17. data/examples/fas-beer.png +0 -0
  18. data/examples/fontawesome.rb +28 -20
  19. data/examples/foundation_icons.rb +1 -1
  20. data/examples/paymentfont.rb +1 -1
  21. data/lib/prawn/icon.rb +3 -200
  22. data/lib/prawn/icon/base.rb +19 -0
  23. data/lib/prawn/icon/errors.rb +21 -0
  24. data/lib/prawn/icon/font_data.rb +11 -13
  25. data/lib/prawn/icon/interface.rb +208 -0
  26. data/lib/prawn/icon/parser.rb +45 -53
  27. data/lib/prawn/icon/version.rb +1 -1
  28. data/prawn-icon.gemspec +8 -9
  29. data/spec/integration/icon_spec.rb +80 -60
  30. data/spec/spec_helper.rb +4 -0
  31. data/spec/support/parser_helper.rb +1 -1
  32. data/spec/support/pdf_helper.rb +1 -1
  33. data/spec/unit/base_spec.rb +15 -0
  34. data/spec/unit/errors/icon_key_empty_spec.rb +19 -0
  35. data/spec/unit/errors/icon_not_found_spec.rb +19 -0
  36. data/spec/unit/font_data_spec.rb +54 -73
  37. data/spec/unit/icon_spec.rb +20 -27
  38. data/spec/unit/parser_spec.rb +66 -63
  39. metadata +35 -41
  40. data/data/fonts/fa/LICENSE +0 -4
  41. data/data/fonts/fa/fa.yml +0 -676
  42. data/data/fonts/fa/fontawesome.ttf +0 -0
  43. data/data/fonts/octicon/LICENSE +0 -9
  44. data/data/fonts/octicon/octicon.yml +0 -192
  45. data/data/fonts/octicon/octicons.ttf +0 -0
  46. data/examples/fa-beer-inline.png +0 -0
  47. data/examples/fa-beer.png +0 -0
  48. data/examples/octicons.rb +0 -35
@@ -7,12 +7,13 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe Prawn::Icon::Interface do
10
+ let(:pdf) { create_pdf }
11
+
10
12
  describe '::icon' do
11
13
  context 'valid icon key' do
12
14
  context 'with options' do
13
15
  it 'should handle text options (size)' do
14
- pdf = create_pdf
15
- pdf.icon 'fa-arrows', size: 60
16
+ pdf.icon 'far-address-book', size: 60
16
17
  text = PDF::Inspector::Text.analyze(pdf.render)
17
18
 
18
19
  expect(text.font_settings.first[:size]).to eq(60)
@@ -21,50 +22,69 @@ describe Prawn::Icon::Interface do
21
22
 
22
23
  context 'inline_format: true' do
23
24
  it 'should handle text options (size)' do
24
- pdf = create_pdf
25
- pdf.icon '<icon size="60">fa-arrows</icon>', inline_format: true
25
+ pdf.icon '<icon size="60">far-address-book</icon>', inline_format: true
26
26
  text = PDF::Inspector::Text.analyze(pdf.render)
27
27
 
28
- expect(text.strings.first).to eq("\uf047")
28
+ expect(text.strings.first).to eq('')
29
29
  expect(text.font_settings.first[:size]).to eq(60.0)
30
30
  end
31
31
 
32
32
  it 'should be able to render on multiple documents' do
33
33
  pdf1 = create_pdf
34
34
  pdf2 = create_pdf
35
- pdf1.icon '<icon>fa-arrows</icon>', inline_format: true
36
- pdf2.icon '<icon>fa-arrows</icon>', inline_format: true
35
+ pdf1.icon '<icon>far-address-book</icon>', inline_format: true
36
+ pdf2.icon '<icon>far-address-book</icon>', inline_format: true
37
37
  text1 = PDF::Inspector::Text.analyze(pdf1.render)
38
38
  text2 = PDF::Inspector::Text.analyze(pdf2.render)
39
39
 
40
- expect(text1.strings.first).to eq("\uf047")
41
- expect(text2.strings.first).to eq("\uf047")
40
+ expect(text1.strings.first).to eq('')
41
+ expect(text2.strings.first).to eq('')
42
+ end
43
+
44
+ it 'renders the icon at the proper cursor position (#24)' do
45
+ icon_text = '<icon>fas-info-circle</icon> icon here!'
46
+ pdf.text 'Start'
47
+ pdf.move_down 10
48
+ pdf.text 'More'
49
+ pdf.move_down 20
50
+ icon = pdf.icon icon_text, inline_format: true
51
+ pdf.move_down 30
52
+ pdf.text 'End'
53
+
54
+ expect(icon.at.first).to eq(0)
55
+ expect(icon.at.last.round).to eq(734)
56
+ end
57
+
58
+ context 'with final_gap: false' do
59
+ it 'renders the icon without a final gap' do
60
+ icon = pdf.icon '<icon size="60">far-address-book</icon>',
61
+ inline_format: true,
62
+ final_gap: false
63
+ expect(icon.at.last.round).to eq(792)
64
+ end
42
65
  end
43
66
  end
44
67
 
45
68
  context 'without options' do
46
69
  it 'should render an icon to document' do
47
- pdf = create_pdf
48
- pdf.icon 'fa-arrows'
70
+ pdf.icon 'far-address-book'
49
71
  text = PDF::Inspector::Text.analyze(pdf.render)
50
72
 
51
- expect(text.strings.first).to eq("\uf047")
73
+ expect(text.strings.first).to eq('')
52
74
  end
53
75
  end
54
76
  end
55
77
 
56
78
  context 'invalid icon key' do
57
79
  it 'should raise IconNotFound' do
58
- pdf = create_pdf
59
- proc = Proc.new { pdf.icon 'fa-__INVALID' }
80
+ proc = Proc.new { pdf.icon 'far-__INVALID' }
60
81
 
61
- expect(proc).to raise_error(Prawn::Errors::IconNotFound)
82
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
62
83
  end
63
84
  end
64
85
 
65
86
  context 'invalid specifier' do
66
87
  it 'should raise UnknownFont' do
67
- pdf = create_pdf
68
88
  proc = Proc.new { pdf.icon '__INVALID__' }
69
89
 
70
90
  expect(proc).to raise_error(Prawn::Errors::UnknownFont)
@@ -75,74 +95,67 @@ describe Prawn::Icon::Interface do
75
95
  describe '::make_icon' do
76
96
  context ':inline_format => false (default)' do
77
97
  it 'should return a Prawn::Icon instance' do
78
- pdf = create_pdf
79
- icon = pdf.make_icon 'fa-arrows'
98
+ icon = pdf.make_icon 'far-address-book'
80
99
 
81
- expect(icon.class).to eq(Prawn::Icon)
100
+ expect(icon).to be_a(Prawn::Icon)
82
101
  end
83
102
  end
84
103
 
85
104
  context ':inline_format => true' do
86
105
  it 'should return a Prawn::::Text::Formatted::Box instance' do
87
- pdf = create_pdf
88
- icon = pdf.make_icon '<icon>fa-arrows</icon>', inline_format: true
106
+ icon = pdf.make_icon '<icon>far-address-book</icon>', inline_format: true
89
107
 
90
- expect(icon.class).to eq(Prawn::Text::Formatted::Box)
108
+ expect(icon).to be_a(Prawn::Text::Formatted::Box)
91
109
  end
92
110
  end
93
111
  end
94
112
 
95
113
  describe '::inline_icon' do
96
114
  it 'should return a Prawn::Text::Formatted::Box instance' do
97
- pdf = create_pdf
98
- icon = pdf.inline_icon '<icon>fa-arrows</icon>'
115
+ icon = pdf.inline_icon '<icon>far-address-book</icon>'
99
116
 
100
- expect(icon.class).to eq(Prawn::Text::Formatted::Box)
117
+ expect(icon).to be_a(Prawn::Text::Formatted::Box)
101
118
  end
102
119
  end
103
120
 
104
121
  describe '::table_icon' do
105
122
  context 'inline_format: false (default)' do
106
123
  it 'should return a hash with font and content keys' do
107
- pdf = create_pdf
108
- icon = pdf.table_icon 'fa-arrows'
124
+ icon = pdf.table_icon 'far-address-book'
109
125
 
110
- expect(icon.class).to eq(Hash)
111
- expect(icon[:font]).to eq('fa')
112
- expect(icon[:content]).to eq("\uf047")
126
+ expect(icon).to be_a(Hash)
127
+ expect(icon[:font]).to eq('far')
128
+ expect(icon[:content]).to eq('')
113
129
  end
114
130
  end
115
131
 
116
132
  context 'inline_format: true' do
117
133
  it 'should convert <icon> to <font> tags' do
118
- pdf = create_pdf
119
- icon = pdf.table_icon '<icon>fa-user</icon>', inline_format: true
134
+ icon = pdf.table_icon '<icon>fas-user</icon>', inline_format: true
120
135
 
121
- expect(icon.class).to eq(Hash)
122
- expect(icon[:content]).to eq('<font name="fa"></font>')
123
- expect(icon[:inline_format]).to be_true
136
+ expect(icon).to be_a(Hash)
137
+ expect(icon[:content]).to eq('<font name="fas"></font>')
138
+ expect(icon[:inline_format]).to be true
124
139
  end
125
140
 
126
141
  it 'should ignore all other tags' do
127
- pdf = create_pdf
128
142
  a = ['<b>BOLD</b> <color rgb="0099FF">BLUE</color>', inline_format: true]
129
143
  icon = pdf.table_icon(*a)
130
144
 
131
- expect(icon.class).to eq(Hash)
145
+ expect(icon).to be_a(Hash)
132
146
  expect(icon[:content]).to eq(a[0])
133
- expect(icon[:inline_format]).to be_true
147
+ expect(icon[:inline_format]).to be true
134
148
  end
135
149
 
136
150
  context 'multiple icons' do
137
151
  it 'should ignore any text not in an icon tag' do
138
- pdf = create_pdf
139
- a = ['<icon>fa-user</icon> Some Text <icon>fi-laptop</icon>', inline_format: true]
140
- out = '<font name="fa"></font> Some Text <font name="fi"></font>'
152
+ a = ['<icon>fas-user</icon> Some Text <icon>fi-laptop</icon>', inline_format: true]
153
+ out = '<font name="fas"></font> Some Text <font name="fi"></font>'
141
154
  icon = pdf.table_icon(*a)
142
155
 
143
- expect(icon.class).to eq(Hash)
156
+ expect(icon).to be_a(Hash)
144
157
  expect(icon[:content]).to eq(out)
145
- expect(icon[:inline_format]).to be_true
158
+ expect(icon[:inline_format]).to be true
146
159
  end
147
160
  end
148
161
  end
@@ -150,43 +163,50 @@ describe Prawn::Icon::Interface do
150
163
  end
151
164
 
152
165
  describe Prawn::Icon do
153
- context 'FontAwesome' do
154
- it 'should render FontAwesome glyphs' do
155
- pdf = create_pdf
156
- pdf.icon 'fa-user'
166
+ let(:pdf) { create_pdf }
167
+
168
+ context 'FontAwesome | Regular' do
169
+ it 'should render regular glyphs' do
170
+ pdf.icon 'far-user'
157
171
  text = PDF::Inspector::Text.analyze(pdf.render)
158
172
 
159
- expect(text.strings.first).to eq("")
173
+ expect(text.strings.first).to eq('')
160
174
  end
161
175
  end
162
176
 
163
- context 'Foundation Icons' do
164
- it 'should render Foundation glyphs' do
165
- pdf = create_pdf
166
- pdf.icon 'fi-laptop'
177
+ context 'FontAwesome | Solid' do
178
+ it 'should render solid glyphs' do
179
+ pdf.icon 'fas-user'
167
180
  text = PDF::Inspector::Text.analyze(pdf.render)
168
181
 
169
- expect(text.strings.first).to eq("")
182
+ expect(text.strings.first).to eq('')
170
183
  end
171
184
  end
172
185
 
173
- context 'GitHub Octicons' do
174
- it 'should render GitHub Octicon glyphs' do
175
- pdf = create_pdf
176
- pdf.icon 'octicon-logo-github'
186
+ context 'FontAwesome | Brands' do
187
+ it 'should render FontAwesome glyphs' do
188
+ pdf.icon 'fab-amazon'
189
+ text = PDF::Inspector::Text.analyze(pdf.render)
190
+
191
+ expect(text.strings.first).to eq('')
192
+ end
193
+ end
194
+
195
+ context 'Foundation Icons' do
196
+ it 'should render Foundation glyphs' do
197
+ pdf.icon 'fi-laptop'
177
198
  text = PDF::Inspector::Text.analyze(pdf.render)
178
199
 
179
- expect(text.strings.first).to eq("")
200
+ expect(text.strings.first).to eq('')
180
201
  end
181
202
  end
182
203
 
183
204
  context 'PaymentFont' do
184
205
  it 'should render PaymentFont glyphs' do
185
- pdf = create_pdf
186
206
  pdf.icon 'pf-amazon'
187
207
  text = PDF::Inspector::Text.analyze(pdf.render)
188
208
 
189
- expect(text.strings.first).to eq("")
209
+ expect(text.strings.first).to eq('')
190
210
  end
191
211
  end
192
212
  end
@@ -3,6 +3,10 @@
3
3
  # Copyright October 2014, Jesse Doyle. All rights reserved.
4
4
  #
5
5
  # This is free software. Please see the LICENSE and COPYING files for details.
6
+ #
7
+ #
8
+ require 'simplecov'
9
+ SimpleCov.start
6
10
 
7
11
  require "bundler"
8
12
  Bundler.setup
@@ -14,4 +14,4 @@ module ParserHelper
14
14
  regex = Prawn::Icon::Parser::CONTENT_REGEX
15
15
  string.scan(regex).flatten
16
16
  end
17
- end
17
+ end
@@ -12,4 +12,4 @@ module PDFHelper
12
12
  def valid_unicode?(string)
13
13
  string.force_encoding('UTF-8').valid_encoding?
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Base do
8
+ describe 'FONTDIR' do
9
+ it 'returns the data/fonts directory' do
10
+ path = File.expand_path '../../..', __FILE__
11
+ path = File.join path, 'data/fonts'
12
+ expect(Prawn::Icon::Base::FONTDIR).to eq(path)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Errors::IconKeyEmpty do
8
+ let(:pdf) { create_pdf }
9
+
10
+ it 'is a StandardError' do
11
+ expect(subject).to be_a(StandardError)
12
+ end
13
+
14
+ it 'is thrown on a missing icon key' do
15
+ proc = Proc.new { pdf.icon '' }
16
+
17
+ expect(proc).to raise_error(described_class)
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Errors::IconNotFound do
8
+ let(:pdf) { create_pdf }
9
+
10
+ it 'is a StandardError' do
11
+ expect(subject).to be_a(StandardError)
12
+ end
13
+
14
+ it 'is thrown on an invalid icon key' do
15
+ proc = Proc.new { pdf.icon 'far-an invalid key' }
16
+
17
+ expect(proc).to raise_error(described_class)
18
+ end
19
+ end
@@ -7,47 +7,49 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe Prawn::Icon::FontData do
10
+ let(:pdf) { create_pdf }
11
+ let(:fontawesome) { Prawn::Icon::FontData.new(pdf, set: :far) }
12
+
13
+ before { Prawn::Icon::FontData.release_data }
14
+
10
15
  describe '#initialize' do
11
- it 'should update font_families on initialization' do
12
- pdf = create_pdf
13
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
16
+ before { Prawn::Icon::FontData.new(pdf, set: :far) }
14
17
 
15
- expect(pdf.font_families['fa']).not_to be_nil
18
+ it 'should update font_families on initialization' do
19
+ expect(pdf.font_families['far']).not_to be_nil
16
20
  end
17
21
  end
18
22
 
19
23
  describe '::load' do
20
- it 'should only load a single object for multiple documents' do
21
- pdf = create_pdf
22
- data = Prawn::Icon::FontData.load(pdf, 'fa')
23
- obj_id_1 = data.__id__
24
- data = Prawn::Icon::FontData.load(pdf, 'fa')
25
- obj_id_2 = data.__id__
24
+ context 'specifier is a string' do
25
+ let(:data) { Prawn::Icon::FontData.load(pdf, 'far') }
26
26
 
27
- expect(obj_id_1).to eq(obj_id_2)
28
- end
27
+ it 'should load the font' do
28
+ expect(data).not_to be_nil
29
+ end
29
30
 
30
- it 'should accept a string as a specifier' do
31
- pdf = create_pdf
32
- data = Prawn::Icon::FontData.load(pdf, 'fa')
31
+ it 'should only load a single object for multiple documents' do
32
+ obj_id_1 = data.object_id
33
+ second = Prawn::Icon::FontData.load(pdf, 'far')
34
+ obj_id_2 = second.object_id
33
35
 
34
- expect(data).not_to be_nil
36
+ expect(obj_id_1).to eq(obj_id_2)
37
+ end
35
38
  end
36
39
 
37
- it 'should accept a symbol as a specifer' do
38
- pdf = create_pdf
39
- data = Prawn::Icon::FontData.load(pdf, :fa)
40
+ context 'specifier is a symbol' do
41
+ let(:data) { Prawn::Icon::FontData.load(pdf, :far) }
40
42
 
41
- expect(data).not_to be_nil
43
+ it 'should load the font' do
44
+ expect(data).not_to be_nil
45
+ end
42
46
  end
43
47
  end
44
48
 
45
49
  describe '::release_data' do
46
50
  it 'should remove all data references if requested' do
47
- pdf = create_pdf
48
- Prawn::Icon::FontData.load(pdf, :fa)
51
+ Prawn::Icon::FontData.load(pdf, :far)
49
52
  Prawn::Icon::FontData.load(pdf, :fi)
50
- Prawn::Icon::FontData.load(pdf, :octicon)
51
53
  data = Prawn::Icon::FontData.release_data
52
54
 
53
55
  expect(data).to be_empty
@@ -56,30 +58,29 @@ describe Prawn::Icon::FontData do
56
58
 
57
59
  describe '::unicode_from_key' do
58
60
  it 'should provide a UTF-8 string for a valid key' do
59
- pdf = create_pdf
60
- unicode = Prawn::Icon::FontData.unicode_from_key(pdf, 'fa-arrows')
61
+ unicode = Prawn::Icon::FontData.unicode_from_key(pdf, 'far-address-book')
61
62
  valid = unicode.force_encoding('UTF-8').valid_encoding?
62
63
 
63
- expect(valid).to be_true
64
+ expect(valid).to be true
64
65
  end
65
66
  end
66
67
 
67
68
  describe '::specifier_from_key' do
68
69
  it 'should provide the font specifier from a valid key' do
69
- specifier = Prawn::Icon::FontData.specifier_from_key('fa-arrows')
70
- expect(specifier).to eq(:fa)
70
+ specifier = Prawn::Icon::FontData.specifier_from_key('far-address-book')
71
+ expect(specifier).to eq(:far)
71
72
  end
72
73
 
73
74
  it 'should error when key is nil' do
74
75
  proc = Proc.new { Prawn::Icon::FontData.specifier_from_key nil }
75
76
 
76
- expect(proc).to raise_error(Prawn::Errors::IconKeyEmpty)
77
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconKeyEmpty)
77
78
  end
78
79
 
79
80
  it 'should error when key is an empty string' do
80
81
  proc = Proc.new { Prawn::Icon::FontData.specifier_from_key '' }
81
82
 
82
- expect(proc).to raise_error(Prawn::Errors::IconKeyEmpty)
83
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconKeyEmpty)
83
84
  end
84
85
 
85
86
  it 'should handle strings without any dashes properly' do
@@ -91,19 +92,15 @@ describe Prawn::Icon::FontData do
91
92
 
92
93
  describe '#font_version' do
93
94
  it 'should have a font version as a string' do
94
- pdf = create_pdf
95
- data = Prawn::Icon::FontData.new(pdf)
96
- version = data.font_version
95
+ version = fontawesome.font_version
97
96
 
98
- expect(version.is_a? String).to be_true
97
+ expect(version).to be_a(String)
99
98
  end
100
99
  end
101
100
 
102
101
  describe '#legend_path' do
103
102
  it 'should have a valid path to a yml file for legend' do
104
- pdf = create_pdf
105
- data = Prawn::Icon::FontData.new(pdf)
106
- path = data.legend_path
103
+ path = fontawesome.legend_path
107
104
  extname = File.extname(path)
108
105
 
109
106
  expect(extname).to eq('.yml')
@@ -112,19 +109,15 @@ describe Prawn::Icon::FontData do
112
109
 
113
110
  describe '#load_fonts' do
114
111
  it 'should return a FontData object' do
115
- pdf = create_pdf
116
- data = Prawn::Icon::FontData.new(pdf)
117
- ret_val = data.load_fonts(pdf)
112
+ ret_val = fontawesome.load_fonts(pdf)
118
113
 
119
- expect(ret_val.is_a? Prawn::Icon::FontData).to be_true
114
+ expect(ret_val).to be_a(Prawn::Icon::FontData)
120
115
  end
121
116
  end
122
117
 
123
118
  describe '#path' do
124
119
  it 'should have a valid path to a TTF file' do
125
- pdf = create_pdf
126
- data = Prawn::Icon::FontData.new(pdf)
127
- path = data.path
120
+ path = fontawesome.path
128
121
  extname = File.extname(path)
129
122
 
130
123
  expect(extname).to eq('.ttf')
@@ -133,68 +126,56 @@ describe Prawn::Icon::FontData do
133
126
 
134
127
  describe '#specifier' do
135
128
  it 'should retrieve the string specifier from the yaml legend file' do
136
- pdf = create_pdf
137
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
138
- specifier = data.specifier
129
+ specifier = fontawesome.specifier
139
130
 
140
- expect(specifier).to eq('fa')
131
+ expect(specifier).to eq('far')
141
132
  end
142
133
  end
143
134
 
144
135
  describe '#unicode' do
145
136
  it 'should provide a valid UTF-8 encoded string for a valid key' do
146
- pdf = create_pdf
147
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
148
- unicode = data.unicode('arrows')
137
+ unicode = fontawesome.unicode('address-book')
149
138
  valid = unicode.force_encoding('UTF-8').valid_encoding?
150
139
 
151
- expect(valid).to be_true
140
+ expect(valid).to be true
152
141
  end
153
142
 
154
143
  it 'should raise an error if unable to match a key' do
155
- pdf = create_pdf
156
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
157
- proc = Proc.new { data.unicode('an invalid sequence') }
144
+ proc = Proc.new { fontawesome.unicode('an invalid sequence') }
158
145
 
159
- expect(proc).to raise_error(Prawn::Errors::IconNotFound)
146
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
160
147
  end
161
148
  end
162
149
 
163
150
  describe '#keys' do
164
151
  it 'should return a non-empty array of strings' do
165
- pdf = create_pdf
166
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
167
- keys = data.keys
152
+ keys = fontawesome.keys
168
153
 
169
154
  expect(keys).not_to be_empty
170
- expect(keys.first.is_a? String).to be_true
155
+ expect(keys.first).to be_a(String)
171
156
  end
172
157
 
173
158
  it 'should not contain the version as a key' do
174
- pdf = create_pdf
175
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
176
- keys = data.keys
159
+ keys = fontawesome.keys
177
160
 
178
- expect(keys.include?('__font_version__')).to be_false
161
+ expect(keys.include?('__font_version__')).to be false
179
162
  end
180
163
  end
181
164
 
182
165
  describe '#yaml' do
183
166
  it 'should return a hash with the specifier as the first key' do
184
- pdf = create_pdf
185
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
186
- yaml = data.yaml
167
+ yaml = fontawesome.yaml
187
168
  key = yaml.keys.first
188
- mapping = yaml['fa']
169
+ mapping = yaml['far']
189
170
  inner_key = mapping.keys.last
190
171
  inner_value = mapping.values.last
191
172
  proc = Proc.new { inner_value.force_encoding('UTF-8').valid_encoding? }
192
173
 
193
- expect(yaml.is_a? Hash).to be_true
194
- expect(key).to eq('fa')
195
- expect(inner_key.is_a? String).to be_true
196
- expect(inner_value.is_a? String).to be_true
197
- expect(proc).to be_true
174
+ expect(yaml).to be_a(Hash)
175
+ expect(key).to eq('far')
176
+ expect(inner_key).to be_a(String)
177
+ expect(inner_value).to be_a(String)
178
+ expect(proc.call).to be true
198
179
  end
199
180
  end
200
181
  end