prawn-icon 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9efb0b74b59e669ba8755dc2768d156b798eafb7
4
- data.tar.gz: b4ac081cd8e32226989e4a1372ecbc02bdcd025e
3
+ metadata.gz: 75952245471e90a37af57ae8ee7040a64c3c4117
4
+ data.tar.gz: b965941ea1799196938334e90cfab8b5d473f0e8
5
5
  SHA512:
6
- metadata.gz: a1af37c3f257d7f1904365049e43c98079fbcf8731a04d20b8aceebfff92d2e49d9a720284a1c468a79b58d248fae9571f5fdd2b5627e68e5f924ad3e63e0ff3
7
- data.tar.gz: 62c35e08a09d709dfc60996404224083c2206ac208039c6943a1379c5b3affa98d39f52f79b15a8c68b575da3bb85b12a79a3f2fb552a6984296a1c2b026aaae
6
+ metadata.gz: 924dac06a25fb32e2eb85144ab7b0a0f9eb0b16042a6dad2daca3320d120a7e7526cd0cc612f328f8617523c13b5ab33e7eaef50ee9fa102c054dfd1f76fe1cf
7
+ data.tar.gz: 5b1ad4c25e1bda070c38856fa2796ff8cfb8e2ca7a79d96f277b875f718fb6ef19011b34153e23552be3e56bbb80c3b16c63e1e8c1f7474a78898d4ebb507cd8
@@ -1,3 +1,13 @@
1
+ # 2.1.0 - April 1, 2018
2
+
3
+ * Introduce backwards compatibility with FontAwesome 4 icon keys by dynamically
4
+ rewriting all instances of `fa-*` to their appropriate FontAwesome 5 equivalent
5
+ key. This is achieved by implementing a shim generated from the FontAwesome metadata.
6
+ * Introduce a deprecation warning written to `STDERR` when any `fa-*` key is
7
+ encountered. The compatibility shim will be removed in the next major version
8
+ of `Prawn::Icon` (`3.0.0`).
9
+ * See the [discussion here](https://github.com/jessedoyle/prawn-icon/pull/33) for more details.
10
+
1
11
  # 2.0.0 - March 7, 2018
2
12
 
3
13
  * [**breaking change**] Update to FontAwesome 5.0.8. FontAwesome 5 now provides 3 different font families: `brands`, `regular` and `solid`. The specifiers for these font icons are now: `fab`, `far` and `fas`.
@@ -11,5 +11,6 @@ require_relative 'icon/base'
11
11
  require_relative 'icon/font_data'
12
12
  require_relative 'icon/parser'
13
13
  require_relative 'icon/interface'
14
+ require_relative 'icon/compatibility'
14
15
 
15
16
  Prawn::Document.extensions << Prawn::Icon::Interface
@@ -0,0 +1,178 @@
1
+ # encoding: utf-8
2
+ #
3
+ # compatibility.rb - Prawn::Icon FontAwesome 4/5 compatibility shim.
4
+ #
5
+ # Copyright March 2018, Jesse Doyle. All rights reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+
9
+ # rubocop:disable Metrics/ClassLength
10
+ module Prawn
11
+ class Icon
12
+ class Compatibility
13
+ SHIMS = {
14
+ 'fa-area-chart' => 'fas-chart-area',
15
+ 'fa-arrow-circle-o-down' => 'far-arrow-alt-circle-down',
16
+ 'fa-arrow-circle-o-left' => 'far-arrow-alt-circle-left',
17
+ 'fa-arrow-circle-o-right' => 'far-arrow-alt-circle-right',
18
+ 'fa-arrow-circle-o-up' => 'far-arrow-alt-circle-up',
19
+ 'fa-arrows' => 'fas-arrows-alt',
20
+ 'fa-arrows-alt' => 'fas-expand-arrows-alt',
21
+ 'fa-arrows-h' => 'fas-arrows-alt-h',
22
+ 'fa-arrows-v' => 'fas-arrows-alt-v',
23
+ 'fa-bar-chart' => 'far-chart-bar',
24
+ 'fa-bitbucket-square' => 'fab-bitbucket',
25
+ 'fa-calendar' => 'fas-calendar-alt',
26
+ 'fa-calendar-o' => 'far-calendar',
27
+ 'fa-caret-square-o-down' => 'far-caret-square-down',
28
+ 'fa-caret-square-o-left' => 'far-caret-square-left',
29
+ 'fa-caret-square-o-right' => 'far-caret-square-right',
30
+ 'fa-caret-square-o-up' => 'far-caret-square-up',
31
+ 'fa-cc' => 'far-closed-captioning',
32
+ 'fa-chain-broken' => 'fas-unlink',
33
+ 'fa-circle-o-notch' => 'fas-circle-notch',
34
+ 'fa-circle-thin' => 'far-circle',
35
+ 'fa-clipboard' => 'far-clipboard',
36
+ 'fa-clone' => 'far-clone',
37
+ 'fa-cloud-download' => 'fas-cloud-download-alt',
38
+ 'fa-cloud-upload' => 'fas-cloud-upload-alt',
39
+ 'fa-code-fork' => 'fas-code-branch',
40
+ 'fa-commenting' => 'fas-comment-alt',
41
+ 'fa-compass' => 'far-compass',
42
+ 'fa-copyright' => 'far-copyright',
43
+ 'fa-creative-commons' => 'fab-creative-commons',
44
+ 'fa-credit-card' => 'far-credit-card',
45
+ 'fa-credit-card-alt' => 'fas-credit-card',
46
+ 'fa-cutlery' => 'fas-utensils',
47
+ 'fa-diamond' => 'far-gem',
48
+ 'fa-eercast' => 'fab-sellcast',
49
+ 'fa-eur' => 'fas-euro-sign',
50
+ 'fa-exchange' => 'fas-exchange-alt',
51
+ 'fa-external-link' => 'fas-external-link-alt',
52
+ 'fa-external-link-square' => 'fas-external-link-square-alt',
53
+ 'fa-eye-dropper' => 'far-eye-dropper',
54
+ 'fa-eye-slash' => 'far-eye-slash',
55
+ 'fa-eyedropper' => 'fas-eye-dropper',
56
+ 'fa-facebook' => 'fab-facebook-f',
57
+ 'fa-facebook-official' => 'fab-facebook',
58
+ 'fa-file-text' => 'fas-file-alt',
59
+ 'fa-files-o' => 'far-copy',
60
+ 'fa-floppy-o' => 'far-save',
61
+ 'fa-gbp' => 'fas-pound-sign',
62
+ 'fa-glass' => 'fas-glass-martini',
63
+ 'fa-google-plus' => 'fab-google-plus-g',
64
+ 'fa-google-plus-circle' => 'fab-google-plus',
65
+ 'fa-google-plus-official' => 'fab-google-plus',
66
+ 'fa-hand-o-down' => 'far-hand-point-down',
67
+ 'fa-hand-o-left' => 'far-hand-point-left',
68
+ 'fa-hand-o-right' => 'far-hand-point-right',
69
+ 'fa-hand-o-up' => 'far-hand-point-up',
70
+ 'fa-header' => 'fas-heading',
71
+ 'fa-id-badge' => 'far-id-badge',
72
+ 'fa-ils' => 'fas-shekel-sign',
73
+ 'fa-inr' => 'fas-rupee-sign',
74
+ 'fa-intersex' => 'fas-transgender',
75
+ 'fa-jpy' => 'fas-yen-sign',
76
+ 'fa-krw' => 'fas-won-sign',
77
+ 'fa-level-down' => 'fas-level-down-alt',
78
+ 'fa-level-up' => 'fas-level-up-alt',
79
+ 'fa-life-ring' => 'far-life-ring',
80
+ 'fa-line-chart' => 'fas-chart-line',
81
+ 'fa-linkedin' => 'fab-linkedin-in',
82
+ 'fa-linkedin-square' => 'fab-linkedin',
83
+ 'fa-list-alt' => 'far-list-alt',
84
+ 'fa-long-arrow-down' => 'fas-long-arrow-alt-down',
85
+ 'fa-long-arrow-left' => 'fas-long-arrow-alt-left',
86
+ 'fa-long-arrow-right' => 'fas-long-arrow-alt-right',
87
+ 'fa-long-arrow-up' => 'fas-long-arrow-alt-up',
88
+ 'fa-map-marker' => 'fas-map-marker-alt',
89
+ 'fa-meanpath' => 'fab-font-awesome',
90
+ 'fa-mobile' => 'fas-mobile-alt',
91
+ 'fa-money' => 'far-money-bill-alt',
92
+ 'fa-object-group' => 'far-object-group',
93
+ 'fa-object-ungroup' => 'far-object-ungroup',
94
+ 'fa-paste' => 'far-paste',
95
+ 'fa-pencil' => 'fas-pencil-alt',
96
+ 'fa-pencil-square' => 'fas-pen-square',
97
+ 'fa-pencil-square-o' => 'far-edit',
98
+ 'fa-picture' => 'fas-image',
99
+ 'fa-pie-chart' => 'fas-chart-pie',
100
+ 'fa-refresh' => 'fas-sync',
101
+ 'fa-registered' => 'far-registered',
102
+ 'fa-repeat' => 'fas-redo',
103
+ 'fa-rub' => 'fas-ruble-sign',
104
+ 'fa-scissors' => 'fas-cut',
105
+ 'fa-shield' => 'fas-shield-alt',
106
+ 'fa-sign-in' => 'fas-sign-in-alt',
107
+ 'fa-sign-out' => 'fas-sign-out-alt',
108
+ 'fa-sliders' => 'fas-sliders-h',
109
+ 'fa-sort-alpha-asc' => 'fas-sort-alpha-down',
110
+ 'fa-sort-alpha-desc' => 'fas-sort-alpha-up',
111
+ 'fa-sort-amount-asc' => 'fas-sort-amount-down',
112
+ 'fa-sort-amount-desc' => 'fas-sort-amount-up',
113
+ 'fa-sort-asc' => 'fas-sort-up',
114
+ 'fa-sort-desc' => 'fas-sort-down',
115
+ 'fa-sort-numeric-asc' => 'fas-sort-numeric-down',
116
+ 'fa-sort-numeric-desc' => 'fas-sort-numeric-up',
117
+ 'fa-spoon' => 'fas-utensil-spoon',
118
+ 'fa-star-half-empty' => 'fas-star-half',
119
+ 'fa-star-half-full' => 'fas-star-half',
120
+ 'fa-support' => 'far-life-ring',
121
+ 'fa-tablet' => 'fas-tablet-alt',
122
+ 'fa-tachometer' => 'fas-tachometer-alt',
123
+ 'fa-television' => 'fas-tv',
124
+ 'fa-thumb-tack' => 'fas-thumbtack',
125
+ 'fa-thumbs-o-down' => 'far-thumbs-down',
126
+ 'fa-thumbs-o-up' => 'far-thumbs-up',
127
+ 'fa-ticket' => 'fas-ticket-alt',
128
+ 'fa-trash' => 'fas-trash-alt',
129
+ 'fa-trash-o' => 'far-trash-alt',
130
+ 'fa-try' => 'fas-lira-sign',
131
+ 'fa-usd' => 'fas-dollar-sign',
132
+ 'fa-video-camera' => 'fas-video',
133
+ 'fa-vimeo' => 'fab-vimeo-v',
134
+ 'fa-volume-control-phone' => 'fas-phone-volume',
135
+ 'fa-wheelchair-alt' => 'fab-accessible-icon',
136
+ 'fa-window-maximize' => 'far-window-maximize',
137
+ 'fa-window-restore' => 'far-window-restore',
138
+ 'fa-youtube-play' => 'fab-youtube'
139
+ }.freeze
140
+
141
+ attr_accessor :key
142
+
143
+ def initialize(opts = {})
144
+ self.key = opts.fetch(:key)
145
+ end
146
+
147
+ def translate(io = STDERR)
148
+ @translate ||= begin
149
+ if key.start_with?('fa-')
150
+ map.tap { |replaced| warning(replaced, key, io) }
151
+ else
152
+ key
153
+ end
154
+ end
155
+ end
156
+
157
+ private
158
+
159
+ def map
160
+ SHIMS.fetch(key) do
161
+ # FontAwesome shim metadata assumes "fas" as the default
162
+ # font family if not explicity referenced.
163
+ "fas-#{key.sub(/fa-/, '')}"
164
+ end
165
+ end
166
+
167
+ def warning(new_key, old_key, io)
168
+ io.puts <<-DEPRECATION
169
+ [Prawn::Icon - DEPRECATION WARNING]
170
+ FontAwesome 4 icon was referenced as '#{old_key}'.
171
+ Use the FontAwesome 5 icon '#{new_key}' instead.
172
+ This compatibility layer will be removed in Prawn::Icon 3.0.0.
173
+ DEPRECATION
174
+ end
175
+ end
176
+ end
177
+ end
178
+ # rubocop:enable Metrics/ClassLength
@@ -62,6 +62,7 @@ module Prawn
62
62
  # inline_format: true
63
63
  #
64
64
  def icon(key, opts = {})
65
+ key = translate_key(key)
65
66
  make_icon(key, opts).tap(&:render)
66
67
  end
67
68
 
@@ -81,7 +82,8 @@ module Prawn
81
82
  # the underlying text method call.
82
83
  #
83
84
  def make_icon(key, opts = {})
84
- if opts[:inline_format]
85
+ key = translate_key(key)
86
+ if opts.fetch(:inline_format, false)
85
87
  inline_icon(key, opts)
86
88
  else
87
89
  Icon.new(key, self, opts)
@@ -151,6 +153,7 @@ module Prawn
151
153
  # pdf.table(data) => (2 x 2 table)
152
154
  #
153
155
  def table_icon(key, opts = {})
156
+ key = translate_key(key)
154
157
  if opts[:inline_format]
155
158
  content = Icon::Parser.format(self, key)
156
159
  opts.merge(content: content)
@@ -161,6 +164,10 @@ module Prawn
161
164
 
162
165
  private
163
166
 
167
+ def translate_key(key)
168
+ Compatibility.new(key: key).translate
169
+ end
170
+
164
171
  def icon_box(content, opts = {}) # :nodoc:
165
172
  Text::Formatted::Box.new(content, opts).tap do |box|
166
173
  box.render(dry_run: true)
@@ -176,8 +183,7 @@ module Prawn
176
183
 
177
184
  def initialize(key, document, opts = {})
178
185
  @pdf = document
179
- @set = opts[:set] ||
180
- FontData.specifier_from_key(key)
186
+ @set = opts.fetch(:set) { FontData.specifier_from_key(key) }
181
187
  @data = FontData.load(document, @set)
182
188
  @key = strip_specifier_from_key(key)
183
189
  @unicode = @data.unicode(@key)
@@ -57,7 +57,6 @@ module Prawn
57
57
  tokens.each do |token|
58
58
  # Skip the closing tag
59
59
  next if token =~ /<\/icon>/i
60
- icon = {}
61
60
 
62
61
  # Convert [[1,2], [3,4]] to { :1 => 2, :3 => 4 }
63
62
  attrs = token.scan(ATTR_REGEX).inject({}) do |k, v|
@@ -65,8 +64,7 @@ module Prawn
65
64
  k.merge!(val)
66
65
  end
67
66
 
68
- icon.merge!(attrs)
69
- array << icon
67
+ array << attrs
70
68
  end
71
69
  end
72
70
  end
@@ -101,13 +99,14 @@ module Prawn
101
99
  def keys_to_unicode(document, content, config)
102
100
  [].tap do |icons|
103
101
  content.each_with_index do |icon, index|
102
+ key = Compatibility.new(key: icon).translate
104
103
  options ||= {}
105
104
  options = config[index] if config.any?
106
105
  info = {
107
- set: FontData.specifier_from_key(icon),
106
+ set: FontData.specifier_from_key(key),
108
107
  size: options[:size],
109
108
  color: options[:color],
110
- content: FontData.unicode_from_key(document, icon)
109
+ content: FontData.unicode_from_key(document, key)
111
110
  }
112
111
  icons << info
113
112
  end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '2.0.0'.freeze
11
+ VERSION = '2.1.0'.freeze
12
12
  end
13
13
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright March 2018, 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::Compatibility do
8
+ describe '#translate' do
9
+ let(:stderr) { StringIO.new }
10
+ subject { described_class.new(key: key) }
11
+
12
+ context 'with a non-deprecated key' do
13
+ let(:key) { 'fas-adjust' }
14
+
15
+ it 'does not write to STDERR' do
16
+ value = subject.translate(stderr)
17
+ stderr.rewind
18
+ expect(stderr.read).to be_empty
19
+ end
20
+
21
+ it 'returns the original key' do
22
+ expect(subject.translate(stderr)).to eq(key)
23
+ end
24
+ end
25
+
26
+ context 'with a depreacted FontAwesome key' do
27
+ let(:key) { 'fa-birthday-cake' }
28
+ let(:mapped_key) { 'fas-birthday-cake' }
29
+
30
+ it 'writes a deprecation warning to STDERR' do
31
+ subject.translate(stderr)
32
+ stderr.rewind
33
+ errors = stderr.read
34
+ expect(errors).to include('DEPRECATION')
35
+ expect(errors).to include(key)
36
+ expect(errors).to include(mapped_key)
37
+ end
38
+
39
+ it 'returns the mapped key' do
40
+ expect(subject.translate(stderr)).to eq(mapped_key)
41
+ end
42
+ end
43
+ end
44
+ 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: 2.0.0
4
+ version: 2.1.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: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -156,6 +156,7 @@ files:
156
156
  - examples/paymentfont.rb
157
157
  - lib/prawn/icon.rb
158
158
  - lib/prawn/icon/base.rb
159
+ - lib/prawn/icon/compatibility.rb
159
160
  - lib/prawn/icon/errors.rb
160
161
  - lib/prawn/icon/font_data.rb
161
162
  - lib/prawn/icon/interface.rb
@@ -167,6 +168,7 @@ files:
167
168
  - spec/support/parser_helper.rb
168
169
  - spec/support/pdf_helper.rb
169
170
  - spec/unit/base_spec.rb
171
+ - spec/unit/compatibility_spec.rb
170
172
  - spec/unit/errors/icon_key_empty_spec.rb
171
173
  - spec/unit/errors/icon_not_found_spec.rb
172
174
  - spec/unit/font_data_spec.rb