prawn-icon 2.4.0 → 3.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.
@@ -11,8 +11,9 @@ STYLES = {
11
11
 
12
12
  STYLES.each do |specifier, type|
13
13
  Prawn::Document.generate("fontawesome_#{type.downcase}.pdf") do
14
- deja_path = File.join \
15
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
14
+ deja_path = Prawn::Icon.configuration.font_directory
15
+ .join('DejaVuSans.ttf')
16
+ .to_s
16
17
 
17
18
  font_families.update(
18
19
  'deja' => { normal: deja_path }
@@ -4,8 +4,9 @@ require_relative '../lib/prawn/icon'
4
4
  require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('foundation_icons.pdf') do
7
- deja_path = File.join \
8
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
9
10
 
10
11
  font_families.update({
11
12
  'deja' => { normal: deja_path }
data/examples/mdi.rb ADDED
@@ -0,0 +1,36 @@
1
+ # All example code may be executed by calling `rake legend`
2
+
3
+ require_relative '../lib/prawn/icon'
4
+ require_relative 'example_helper'
5
+
6
+ Prawn::Document.generate('mdi_icons.pdf') do
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
10
+
11
+ font_families.update({
12
+ 'deja' => { normal: deja_path }
13
+ })
14
+
15
+ font('deja')
16
+
17
+ icons = icon_keys(self, 'mdi')
18
+ required_pages = number_of_pages(self, 'mdi')
19
+
20
+ define_grid(columns: 6, rows: 12, gutter: 16)
21
+
22
+ sub_header = 'Material Design Icons'
23
+ link = 'https://materialdesignicons.com/'
24
+ page_header sub_header, link
25
+
26
+ first_page_icons icons do |icon_key|
27
+ # Just call the +icon+ method and pass in an icon key
28
+ icon icon_key, size: 20, align: :center
29
+ end
30
+
31
+ start_new_page
32
+
33
+ page_icons icons, required_pages do |icon_key|
34
+ icon icon_key, size: 20, align: :center
35
+ end
36
+ end
@@ -4,8 +4,9 @@ require_relative '../lib/prawn/icon'
4
4
  require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('paymentfont.pdf') do
7
- deja_path = File.join \
8
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
9
10
 
10
11
  font_families.update({
11
12
  'deja' => { normal: deja_path }
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # base.rb - Base configuration for Prawn::Icon.
4
4
  #
5
5
  # Copyright September 2016, Jesse Doyle. All rights reserved.
@@ -11,9 +11,21 @@ require_relative 'errors'
11
11
 
12
12
  module Prawn
13
13
  class Icon
14
+ class << self
15
+ attr_writer :configuration
16
+
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def configure
22
+ yield(configuration)
23
+ end
24
+ end
25
+
14
26
  module Base
15
- FONTDIR = File.join \
16
- File.expand_path('../../../..', __FILE__), 'data/fonts'
27
+ # @deprecated Use {Prawn::Icon.configuration.font_directory} instead
28
+ FONTDIR = Prawn::Icon.configuration.font_directory.to_s
17
29
  end
18
30
  end
19
31
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # compatibility.rb - Prawn::Icon FontAwesome 4/5 compatibility shim.
4
4
  #
5
5
  # Copyright March 2018, Jesse Doyle. All rights reserved.
@@ -9,34 +9,40 @@
9
9
  module Prawn
10
10
  class Icon
11
11
  class Compatibility
12
+ # @deprecated Use {Prawn::Icon::Compatibility.shims} instead
12
13
  SHIMS = YAML.load_file(
13
- File.join(
14
- Base::FONTDIR,
14
+ Prawn::Icon.configuration.font_directory.join(
15
15
  'fa4',
16
16
  'shims.yml'
17
17
  )
18
18
  ).freeze
19
19
 
20
+ class << self
21
+ def shims
22
+ @shims ||= YAML.load_file(
23
+ Icon.configuration.font_directory.join('fa4', 'shims.yml').to_s
24
+ )
25
+ end
26
+ end
27
+
20
28
  attr_accessor :key
21
29
 
22
30
  def initialize(opts = {})
23
31
  self.key = opts.fetch(:key)
24
32
  end
25
33
 
26
- def translate(io = STDERR)
27
- @translate ||= begin
28
- if key.start_with?('fa-')
29
- map.tap { |replaced| warning(replaced, key, io) }
30
- else
31
- key
32
- end
33
- end
34
+ def translate(io = $stderr)
35
+ @translate ||= if key.start_with?('fa-')
36
+ map.tap { |replaced| warning(replaced, key, io) }
37
+ else
38
+ key
39
+ end
34
40
  end
35
41
 
36
42
  private
37
43
 
38
44
  def map
39
- SHIMS.fetch(key) do
45
+ self.class.shims.fetch(key) do
40
46
  # FontAwesome shim metadata assumes "fas" as the default
41
47
  # font family if not explicity referenced.
42
48
  "fas-#{key.sub(/fa-/, '')}"
@@ -44,14 +50,13 @@ module Prawn
44
50
  end
45
51
 
46
52
  def warning(new_key, old_key, io)
47
- io.puts <<-DEPRECATION
48
- [Prawn::Icon - DEPRECATION WARNING]
49
- FontAwesome 4 icon was referenced as '#{old_key}'.
50
- Use the FontAwesome 5 icon '#{new_key}' instead.
51
- This compatibility layer will be removed in Prawn::Icon 3.0.0.
52
- DEPRECATION
53
+ io.puts <<~DEPRECATION
54
+ [Prawn::Icon - DEPRECATION WARNING]
55
+ FontAwesome 4 icon was referenced as '#{old_key}'.
56
+ Use the FontAwesome 5 icon '#{new_key}' instead.
57
+ This compatibility layer will be removed in Prawn::Icon 4.0.0.
58
+ DEPRECATION
53
59
  end
54
60
  end
55
61
  end
56
62
  end
57
- # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # configuration.rb: Prawn icon configuration.
4
+ #
5
+ # Copyright October 2020, Jesse Doyle. All rights reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+
9
+ module Prawn
10
+ class Icon
11
+ class Configuration
12
+ def font_directory=(path)
13
+ @font_directory = Pathname.new(path)
14
+ end
15
+
16
+ def font_directory
17
+ @font_directory ||= default_font_directory
18
+ end
19
+
20
+ private
21
+
22
+ def default_font_directory
23
+ Pathname.new(gem_path).join('data', 'fonts')
24
+ end
25
+
26
+ # :nocov:
27
+ def gem_path
28
+ spec = Gem.loaded_specs.fetch('prawn-icon') do
29
+ Struct.new(:full_gem_path).new(failsafe_gem_path)
30
+ end
31
+ spec.full_gem_path
32
+ end
33
+
34
+ def failsafe_gem_path
35
+ File.expand_path('../../..', __dir__)
36
+ end
37
+ # :nocov:
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # errors.rb - Prawn::Icon standard errors.
4
4
  #
5
5
  # Copyright September 2016, Jesse Doyle. All rights reserved.
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # font_data.rb: Icon font metadata container/cache.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -63,15 +63,19 @@ module Prawn
63
63
  end
64
64
 
65
65
  def path
66
- ttf = File.join(Icon::Base::FONTDIR, @set.to_s, '*.ttf')
67
- font = Dir[ttf].first
66
+ @path = begin
67
+ font = Icon.configuration.font_directory
68
+ .join(@set.to_s)
69
+ .glob('*.ttf')
70
+ .first
71
+
72
+ if font.nil?
73
+ raise Prawn::Errors::UnknownFont,
74
+ "Icon font not found for set: #{@set}"
75
+ end
68
76
 
69
- if font.nil?
70
- raise Prawn::Errors::UnknownFont,
71
- "Icon font not found for set: #{@set}"
77
+ font.to_s
72
78
  end
73
-
74
- @path ||= font
75
79
  end
76
80
 
77
81
  def specifier
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # interface.rb: Prawn extension module and logic.
4
4
  #
5
5
  # Copyright October 2016, Jesse Doyle. All rights reserved.
@@ -19,7 +19,7 @@ module Prawn
19
19
  # rule, included icon keys should match the keys from
20
20
  # the font provider. The icon key mapping is specified
21
21
  # in the font's +legend_file+, which is a +YAML+ file
22
- # located in Prawn::Icon::Base::FONTDIR/font/font.yml.
22
+ # located in {Prawn::Icon.configuration.font_directory}/font/font.yml.
23
23
  #
24
24
  # Prawn::Icon::
25
25
  # Houses the methods and interfaces necessary for
@@ -38,6 +38,7 @@ module Prawn
38
38
  # to Prawn's internal formatted text parser.
39
39
  #
40
40
  class Icon
41
+ # @deprecated Use {Prawn::Icon.configuration.font_directory} instead
41
42
  FONTDIR = Icon::Base::FONTDIR
42
43
 
43
44
  module Interface
@@ -63,11 +64,10 @@ module Prawn
63
64
  #
64
65
  def icon(key, opts = {})
65
66
  key = translate_key(key)
66
- make_icon(key, opts).tap(&:render)
67
+ make_icon(key, opts).tap { |i| i && i.render }
67
68
  end
68
69
 
69
- # Initialize a new icon object, but do
70
- # not render it to the document.
70
+ # Initialize a new icon object.
71
71
  #
72
72
  # == Parameters:
73
73
  # key::
@@ -90,9 +90,9 @@ module Prawn
90
90
  end
91
91
  end
92
92
 
93
- # Initialize a new formatted text box containing
94
- # icon information, but don't render it to the
95
- # document.
93
+ # Render formatted icon content to the document from
94
+ # a string containing icons. Content will correctly
95
+ # transition to a new page when necessary.
96
96
  #
97
97
  # == Parameters:
98
98
  # text::
@@ -107,10 +107,37 @@ module Prawn
107
107
  def inline_icon(text, opts = {})
108
108
  parsed = Icon::Parser.format(self, text)
109
109
  content = Text::Formatted::Parser.format(parsed)
110
+ formatted_text(content, opts)
111
+ end
112
+
113
+ # Initialize a formatted icon box from an icon-conatining
114
+ # string. Content is not directly rendered to the document,
115
+ # instead a +Prawn::Text::Formatted::Box+ instance is returned
116
+ # that responds to the +render+ method.
117
+ #
118
+ # == Parameters:
119
+ # text::
120
+ # Input text to be parsed initially for <icon>
121
+ # tags, then passed to Prawn's formatted text
122
+ # parser.
123
+ #
124
+ # opts::
125
+ # A hash of options that may be supplied to the
126
+ # underlying text call.
127
+ #
128
+ def formatted_icon_box(text, opts = {})
129
+ parsed = Icon::Parser.format(self, text)
130
+ content = Text::Formatted::Parser.format(parsed)
131
+ position = opts.fetch(:at) do
132
+ [
133
+ opts.fetch(:x) { bounds.left },
134
+ opts.fetch(:y) { cursor }
135
+ ]
136
+ end
110
137
  box_options = opts.merge(
111
138
  inline_format: true,
112
139
  document: self,
113
- at: [bounds.left, cursor]
140
+ at: position
114
141
  )
115
142
  icon_box(content, box_options)
116
143
  end
@@ -172,9 +199,7 @@ module Prawn
172
199
  Text::Formatted::Box.new(content, opts).tap do |box|
173
200
  box.render(dry_run: true)
174
201
  self.y -= box.height
175
- unless opts.fetch(:final_gap, true)
176
- self.y -= box.line_gap + box.leading
177
- end
202
+ self.y -= box.line_gap + box.leading unless opts.fetch(:final_gap, true)
178
203
  end
179
204
  end
180
205
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # parser.rb: Prawn icon tag text parser (pseudo-HTML).
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -31,15 +31,17 @@ module Prawn
31
31
  #
32
32
  class Parser
33
33
  PARSER_REGEX = Regexp.new \
34
- '<icon[^>]*>|</icon>',
35
- Regexp::IGNORECASE |
36
- Regexp::MULTILINE
34
+ '<icon[^>]*>|</icon>',
35
+ Regexp::IGNORECASE |
36
+ Regexp::MULTILINE
37
37
 
38
- CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi
38
+ CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi.freeze
39
39
 
40
- TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi
40
+ TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi.freeze
41
41
 
42
- ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi
42
+ # rubocop:disable Lint/MixedRegexpCaptureTypes
43
+ ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi.freeze
44
+ # rubocop:enable Lint/MixedRegexpCaptureTypes
43
45
 
44
46
  class << self
45
47
  def format(document, string)
@@ -103,9 +105,9 @@ module Prawn
103
105
  options ||= {}
104
106
  options = config[index] if config.any?
105
107
  info = {
106
- set: FontData.specifier_from_key(key),
107
- size: options[:size],
108
- color: options[:color],
108
+ set: FontData.specifier_from_key(key),
109
+ size: options[:size],
110
+ color: options[:color],
109
111
  content: FontData.unicode_from_key(document, key)
110
112
  }
111
113
  icons << info
@@ -115,7 +117,7 @@ module Prawn
115
117
 
116
118
  private
117
119
 
118
- def attr_hash(value) #:nodoc:
120
+ def attr_hash(value) # :nodoc:
119
121
  # If attr == size, we must cast value to float,
120
122
  # else symbolize the key and map it to value
121
123
  if value[0] =~ /size/i
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # version.rb: Prawn icon versioning.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '2.4.0'.freeze
11
+ VERSION = '3.1.0'
12
12
  end
13
13
  end
data/lib/prawn/icon.rb CHANGED
@@ -1,12 +1,14 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # icon.rb: Prawn icon functionality.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
+ require 'pathname'
9
10
  require_relative 'icon/version'
11
+ require_relative 'icon/configuration'
10
12
  require_relative 'icon/base'
11
13
  require_relative 'icon/font_data'
12
14
  require_relative 'icon/parser'
data/prawn-icon.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- basedir = File.expand_path(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ basedir = __dir__
2
4
  require "#{basedir}/lib/prawn/icon/version"
3
5
 
4
6
  Gem::Specification.new do |spec|
@@ -17,23 +19,23 @@ Gem::Specification.new do |spec|
17
19
 
18
20
  spec.homepage = 'https://github.com/jessedoyle/prawn-icon/'
19
21
 
20
- spec.test_files = Dir['spec/*_spec.rb']
21
22
  spec.authors = ['Jesse Doyle']
22
23
  spec.email = ['jdoyle@ualberta.ca']
23
- spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
24
+ spec.licenses = %w[RUBY GPL-2 GPL-3]
24
25
 
25
26
  spec.add_dependency('prawn', '>= 1.1.0', '< 3.0.0')
26
27
 
27
28
  spec.add_development_dependency('pdf-inspector', '>= 1.2.1')
28
- spec.add_development_dependency('rspec', '>= 3.5.0')
29
- spec.add_development_dependency('rubocop', '~> 0.49.1')
30
- spec.add_development_dependency('rake')
31
29
  spec.add_development_dependency('pdf-reader', '>= 1.4')
30
+ spec.add_development_dependency('rake')
31
+ spec.add_development_dependency('rspec', '>= 3.5.0')
32
+ spec.add_development_dependency('rubocop', '~> 1.35.1')
32
33
  spec.add_development_dependency('simplecov')
33
34
 
34
- spec.description = <<-END_DESC
35
- Prawn::Icon provides various icon fonts including
36
- FontAwesome, PaymentFont and Foundation Icons
37
- for use with the Prawn PDF toolkit.
35
+ spec.description = <<~END_DESC
36
+ Prawn::Icon provides various icon fonts including
37
+ FontAwesome, PaymentFont and Foundation Icons
38
+ for use with the Prawn PDF toolkit.
38
39
  END_DESC
40
+ spec.metadata['rubygems_mfa_required'] = 'true'
39
41
  end
@@ -47,20 +47,28 @@ describe Prawn::Icon::Interface do
47
47
  pdf.move_down 10
48
48
  pdf.text 'More'
49
49
  pdf.move_down 20
50
- icon = pdf.icon icon_text, inline_format: true
50
+ pdf.icon icon_text, inline_format: true
51
51
  pdf.move_down 30
52
52
  pdf.text 'End'
53
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
54
+ x, y = inspector.positions[2]
53
55
 
54
- expect(icon.at.first).to eq(0)
55
- expect(icon.at.last.round).to eq(734)
56
+ expect(x).to eq(0)
57
+ expect(y.round).to eq(724)
56
58
  end
57
59
 
58
60
  context 'with final_gap: false' do
59
61
  it 'renders the icon without a final gap' do
60
- icon = pdf.icon '<icon size="60">far-address-book</icon>',
62
+ pdf.icon(
63
+ '<icon size="60">far-address-book</icon>',
61
64
  inline_format: true,
62
65
  final_gap: false
63
- expect(icon.at.last.round).to eq(792)
66
+ )
67
+ pdf.text('Hello')
68
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
69
+ y = inspector.positions[1].last.round
70
+
71
+ expect(y).to eq(723)
64
72
  end
65
73
  end
66
74
  end
@@ -77,17 +85,17 @@ describe Prawn::Icon::Interface do
77
85
 
78
86
  context 'invalid icon key' do
79
87
  it 'should raise IconNotFound' do
80
- proc = Proc.new { pdf.icon 'far-__INVALID' }
81
-
82
- expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
88
+ expect { pdf.icon('far-__INVALID') }.to raise_error(
89
+ Prawn::Icon::Errors::IconNotFound
90
+ )
83
91
  end
84
92
  end
85
93
 
86
94
  context 'invalid specifier' do
87
95
  it 'should raise UnknownFont' do
88
- proc = Proc.new { pdf.icon '__INVALID__' }
89
-
90
- expect(proc).to raise_error(Prawn::Errors::UnknownFont)
96
+ expect { pdf.icon('__INVALID__') }.to raise_error(
97
+ Prawn::Errors::UnknownFont
98
+ )
91
99
  end
92
100
  end
93
101
  end
@@ -102,19 +110,63 @@ describe Prawn::Icon::Interface do
102
110
  end
103
111
 
104
112
  context ':inline_format => true' do
105
- it 'should return a Prawn::::Text::Formatted::Box instance' do
113
+ it 'returns nil' do
106
114
  icon = pdf.make_icon '<icon>far-address-book</icon>', inline_format: true
107
115
 
108
- expect(icon).to be_a(Prawn::Text::Formatted::Box)
116
+ expect(icon).to be_nil
109
117
  end
110
118
  end
111
119
  end
112
120
 
113
121
  describe '::inline_icon' do
114
- it 'should return a Prawn::Text::Formatted::Box instance' do
122
+ it 'returns nil' do
115
123
  icon = pdf.inline_icon '<icon>far-address-book</icon>'
116
124
 
117
- expect(icon).to be_a(Prawn::Text::Formatted::Box)
125
+ expect(icon).to be_nil
126
+ end
127
+
128
+ it 'starts a new page if necessary', github_issue: '49' do
129
+ text = 209.times.map { 'Hello, World!' }.join(' ')
130
+ pdf.text(text, size: 18)
131
+ pdf.icon('Hello, <icon>fas-globe</icon>', inline_format: true, size: 18)
132
+ inspector = PDF::Inspector::Page.analyze(pdf.render)
133
+
134
+ expect(inspector.pages.size).to eq(2)
135
+ end
136
+ end
137
+
138
+ describe '::formatted_icon_box' do
139
+ it 'returns a Prawn::Text::Formatted::Box instance' do
140
+ icon_text = <<~CONTENT
141
+ <icon size="20">fas-broom</icon>
142
+ <strikethrough>cancel that</strikethrough>
143
+ <icon>fas-check</icon>
144
+ CONTENT
145
+ box = pdf.formatted_icon_box(icon_text, inline_format: true)
146
+
147
+ expect(box).to be_a(Prawn::Text::Formatted::Box)
148
+ end
149
+
150
+ it 'accepts an absolute position parameter' do
151
+ icon_text = 'Hello, <icon>fas-globe</icon>!'
152
+ pdf.formatted_icon_box(icon_text, inline_format: true, x: 200, y: 100).render
153
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
154
+ x, y = inspector.positions[0]
155
+
156
+ expect(x).to eq(200)
157
+ expect(y.round).to eq(90)
158
+ end
159
+
160
+ it 'handles final_gap: false correctly' do
161
+ icon_text = <<~CONTENT
162
+ Hello, <icon size="60">fas-globe</icon>
163
+ Next line.
164
+ CONTENT
165
+ pdf.formatted_icon_box(icon_text, inline_format: true, final_gap: false).render
166
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
167
+ x = inspector.positions[1].first
168
+
169
+ expect(x.round).to eq(34)
118
170
  end
119
171
  end
120
172
 
@@ -209,4 +261,13 @@ describe Prawn::Icon do
209
261
  expect(text.strings.first).to eq('')
210
262
  end
211
263
  end
264
+
265
+ context 'Material Design Icons' do
266
+ it 'renders Material Design Icon glyphs' do
267
+ pdf.icon 'mdi-beer'
268
+ text = PDF::Inspector::Text.analyze(pdf.render)
269
+
270
+ expect(text.strings.first).to eq('')
271
+ end
272
+ end
212
273
  end
@@ -4,12 +4,31 @@
4
4
  #
5
5
  # This is free software. Please see the LICENSE and COPYING files for details.
6
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)
7
+ describe Prawn::Icon do
8
+ describe '#configuration' do
9
+ it 'returns an instance of Prawn::Icon::Configuration' do
10
+ expect(described_class.configuration).to be_a(Prawn::Icon::Configuration)
11
+ end
12
+ end
13
+
14
+ describe '#configure' do
15
+ around(:each) do |example|
16
+ old = described_class.configuration.dup
17
+ described_class.configure do |config|
18
+ config.font_directory = '/tmp/fonts'
19
+ end
20
+ example.run
21
+ described_class.configuration = old
22
+ end
23
+
24
+ it 'yields control' do
25
+ expect { |b| described_class.configure(&b) }.to yield_control
26
+ end
27
+
28
+ it 'configures properties' do
29
+ expect(described_class.configuration.font_directory).to eq(
30
+ Pathname.new('/tmp/fonts')
31
+ )
13
32
  end
14
33
  end
15
34
  end