prawn-icon 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a8ac902ada7341c7635d8513cb1cbb766194d7d
4
- data.tar.gz: 8bf0c5b69bdedc4a80c37f5fe7ad7eb9c115e0dc
3
+ metadata.gz: f598dd2d932646dceab0f8a70f8dd763b5786e9d
4
+ data.tar.gz: 5f424295e1d8defd4414da7e439fd3cc8da7d570
5
5
  SHA512:
6
- metadata.gz: 9437bae0f1990156ab41f016b169055162869923c0b6a3a2cca5baac61b8d5b64da32a8d860b0d5629ce93cb164e6690ec4f8f4b62bfb7cdd1fab1568c20c1ad
7
- data.tar.gz: dc9433a07cd4c864d78cccfe3be8461a20629286e18b5d812242291e85bd85951b796d0d81d06471bf5da820515dd8f9bbe073e746c14c95deccf0202fa59516
6
+ metadata.gz: 2943e05b79c2ca885e5a43dc3a65d8f3762502129025f536f25acad77570da60f8307c4bbfef2031df1c146b16600264b04e026516b65ca27e877c0d01313b2b
7
+ data.tar.gz: 957abf7f70693da0ffc0578ab5b2d42dd19dad1c7deee28e7d3139c7d55d4474f75ba28571c02fd93a0cb8eff29daa1b7e13f8a5dc10b3b6de0e6b85a8483704
@@ -1,3 +1,9 @@
1
+ # 1.3.0 - Oct 15, 2016
2
+
3
+ - Update rubocop developement dependency (to `0.44.1`).
4
+ - Add `simplecov` as a development dependency and require 100% coverage.
5
+ - Break out `Prawn::Icon::Interface` into its own file. This resolves issue [#27](https://github.com/jessedoyle/prawn-icon/issues/27).
6
+
1
7
  # 1.2.0 - Sept 12, 2016
2
8
 
3
9
  - Update FontAwesome from v4.5.0 to v4.6.3. See [changelog](http://fontawesome.io/icons#new).
@@ -9,207 +9,6 @@
9
9
  require_relative 'icon/base'
10
10
  require_relative 'icon/font_data'
11
11
  require_relative 'icon/parser'
12
-
13
- module Prawn
14
- # Easy icon font usage within Prawn. Currently
15
- # supported icon fonts include: FontAwesome,
16
- # Zurb Foundicons, GitHub Octicons, as well as
17
- # PaymentFont.
18
- #
19
- # = Icon Keys
20
- #
21
- # Icon keys must be supplied to most +Prawn::Icon+
22
- # methods. Keys map directly to a unicode character
23
- # within the font that produces a given icon. As a
24
- # rule, included icon keys should match the keys from
25
- # the font provider. The icon key mapping is specified
26
- # in the font's +legend_file+, which is a +YAML+ file
27
- # located in Prawn::Icon::Base::FONTDIR/font/font.yml.
28
- #
29
- # Prawn::Icon::
30
- # Houses the methods and interfaces necessary for
31
- # rendering icons to the Prawn::Document.
32
- #
33
- # Prawn::Icon::FontData::
34
- # Used to store various information about an icon font,
35
- # including the key-to-unicode mapping information.
36
- # Also houses methods to cache and lazily load the
37
- # requested font data on a document basis.
38
- #
39
- # Prawn::Icon::Parser::
40
- # Used to initially parse icons that are used with the
41
- # inline_format: true option. The input string is parsed
42
- # once for <icon></icon> tags, then the output is provided
43
- # to Prawn's internal formatted text parser.
44
- #
45
- class Icon
46
- FONTDIR = Icon::Base::FONTDIR
47
-
48
- module Interface
49
- # Set up and draw an icon on this document. This
50
- # method operates much like +Prawn::Text::Box+.
51
- #
52
- # == Parameters:
53
- # key::
54
- # Contains the key to a particular icon within
55
- # a font family. If :inline_format is true,
56
- # then key may contain formatted text marked
57
- # with <icon></icon> tags and any tag supported
58
- # by Prawn's parser.
59
- #
60
- # opts::
61
- # A hash of options that may be supplied to
62
- # the underlying +text+ method call.
63
- #
64
- # == Examples:
65
- # pdf.icon 'fa-beer'
66
- # pdf.icon '<icon color="0099FF">fa-arrows</icon>',
67
- # inline_format: true
68
- #
69
- def icon(key, opts = {})
70
- make_icon(key, opts).tap(&:render)
71
- end
72
-
73
- # Initialize a new icon object, but do
74
- # not render it to the document.
75
- #
76
- # == Parameters:
77
- # key::
78
- # Contains the key to a particular icon within
79
- # a font family. If :inline_format is true,
80
- # then key may contain formatted text marked
81
- # with <icon></icon> tags and any tag supported
82
- # by Prawn's parser.
83
- #
84
- # opts::
85
- # A hash of options that may be supplied to
86
- # the underlying text method call.
87
- #
88
- def make_icon(key, opts = {})
89
- if opts[:inline_format]
90
- inline_icon(key, opts)
91
- else
92
- Icon.new(key, self, opts)
93
- end
94
- end
95
-
96
- # Initialize a new formatted text box containing
97
- # icon information, but don't render it to the
98
- # document.
99
- #
100
- # == Parameters:
101
- # text::
102
- # Input text to be parsed initially for <icon>
103
- # tags, then passed to Prawn's formatted text
104
- # parser.
105
- #
106
- # opts::
107
- # A hash of options that may be supplied to the
108
- # underlying text call.
109
- #
110
- def inline_icon(text, opts = {})
111
- parsed = Icon::Parser.format(self, text)
112
- content = Text::Formatted::Parser.format(parsed)
113
- box_options = opts.merge(
114
- inline_format: true,
115
- document: self,
116
- at: [bounds.left, cursor]
117
- )
118
- icon_box(content, box_options)
119
- end
120
-
121
- # Initialize a new Prawn::Icon, but don't render
122
- # the icon to a document. Intended to be used as
123
- # an entry of a data array when combined with
124
- # Prawn::Table.
125
- #
126
- # == Parameters:
127
- # key::
128
- # Contains the key to a particular icon within
129
- # a font family. The key may contain a string
130
- # with format tags if +inline_format: true+ in
131
- # the +opts+ hash.
132
- #
133
- # opts::
134
- # A hash of options that may be supplied to the
135
- # underlying text call.
136
- #
137
- # == Returns:
138
- # A Hash containing +font+ and +content+ keys
139
- # that match the data necessary for the
140
- # specified icon.
141
- #
142
- # eg. { font: 'fa', content: '\uf047' }
143
- #
144
- # Note that the +font+ key will not be set
145
- # if +inline_format: true+.
146
- #
147
- # == Examples:
148
- # require 'prawn/table'
149
- #
150
- # data = [
151
- # # Explicit brackets must be used here
152
- # [pdf.table_icon('fa-arrows'), 'Cell 1'],
153
- # ['Cell 2', 'Cell 3']
154
- # ]
155
- #
156
- # pdf.table(data) => (2 x 2 table)
157
- #
158
- def table_icon(key, opts = {})
159
- if opts[:inline_format]
160
- content = Icon::Parser.format(self, key)
161
- opts.merge(content: content)
162
- else
163
- make_icon(key, opts).format_hash
164
- end
165
- end
166
-
167
- private
168
-
169
- def icon_box(content, opts = {}) # :nodoc:
170
- Text::Formatted::Box.new(content, opts).tap do |box|
171
- box.render(dry_run: true)
172
- self.y -= box.height
173
- unless opts.fetch(:final_gap, true)
174
- self.y -= box.line_gap + box.leading
175
- end
176
- end
177
- end
178
- end
179
-
180
- attr_reader :set, :unicode
181
-
182
- def initialize(key, document, opts = {})
183
- @pdf = document
184
- @set = opts[:set] ||
185
- FontData.specifier_from_key(key)
186
- @data = FontData.load(document, @set)
187
- @key = strip_specifier_from_key(key)
188
- @unicode = @data.unicode(@key)
189
- @options = opts
190
- end
191
-
192
- def format_hash
193
- base = { font: @set.to_s, content: @unicode }
194
- opts = @options.dup
195
- # Prawn::Table renames :color to :text_color
196
- opts[:text_color] = opts.delete(:color)
197
- base.merge(opts)
198
- end
199
-
200
- def render
201
- @pdf.font(@data.path) do
202
- @pdf.text @unicode, @options
203
- end
204
- end
205
-
206
- private
207
-
208
- def strip_specifier_from_key(key) # :nodoc:
209
- reg = Regexp.new "#{@data.specifier}-"
210
- key.sub(reg, '') # Only one specifier
211
- end
212
- end
213
- end
12
+ require_relative 'icon/interface'
214
13
 
215
14
  Prawn::Document.extensions << Prawn::Icon::Interface
@@ -0,0 +1,209 @@
1
+ # encoding: utf-8
2
+ #
3
+ # interface.rb: Prawn extension module and logic.
4
+ #
5
+ # Copyright October 2016, 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
+ # Easy icon font usage within Prawn. Currently
11
+ # supported icon fonts include: FontAwesome,
12
+ # Zurb Foundicons, GitHub Octicons, as well as
13
+ # PaymentFont.
14
+ #
15
+ # = Icon Keys
16
+ #
17
+ # Icon keys must be supplied to most +Prawn::Icon+
18
+ # methods. Keys map directly to a unicode character
19
+ # within the font that produces a given icon. As a
20
+ # rule, included icon keys should match the keys from
21
+ # the font provider. The icon key mapping is specified
22
+ # in the font's +legend_file+, which is a +YAML+ file
23
+ # located in Prawn::Icon::Base::FONTDIR/font/font.yml.
24
+ #
25
+ # Prawn::Icon::
26
+ # Houses the methods and interfaces necessary for
27
+ # rendering icons to the Prawn::Document.
28
+ #
29
+ # Prawn::Icon::FontData::
30
+ # Used to store various information about an icon font,
31
+ # including the key-to-unicode mapping information.
32
+ # Also houses methods to cache and lazily load the
33
+ # requested font data on a document basis.
34
+ #
35
+ # Prawn::Icon::Parser::
36
+ # Used to initially parse icons that are used with the
37
+ # inline_format: true option. The input string is parsed
38
+ # once for <icon></icon> tags, then the output is provided
39
+ # to Prawn's internal formatted text parser.
40
+ #
41
+ class Icon
42
+ FONTDIR = Icon::Base::FONTDIR
43
+
44
+ module Interface
45
+ # Set up and draw an icon on this document. This
46
+ # method operates much like +Prawn::Text::Box+.
47
+ #
48
+ # == Parameters:
49
+ # key::
50
+ # Contains the key to a particular icon within
51
+ # a font family. If :inline_format is true,
52
+ # then key may contain formatted text marked
53
+ # with <icon></icon> tags and any tag supported
54
+ # by Prawn's parser.
55
+ #
56
+ # opts::
57
+ # A hash of options that may be supplied to
58
+ # the underlying +text+ method call.
59
+ #
60
+ # == Examples:
61
+ # pdf.icon 'fa-beer'
62
+ # pdf.icon '<icon color="0099FF">fa-arrows</icon>',
63
+ # inline_format: true
64
+ #
65
+ def icon(key, opts = {})
66
+ make_icon(key, opts).tap(&:render)
67
+ end
68
+
69
+ # Initialize a new icon object, but do
70
+ # not render it to the document.
71
+ #
72
+ # == Parameters:
73
+ # key::
74
+ # Contains the key to a particular icon within
75
+ # a font family. If :inline_format is true,
76
+ # then key may contain formatted text marked
77
+ # with <icon></icon> tags and any tag supported
78
+ # by Prawn's parser.
79
+ #
80
+ # opts::
81
+ # A hash of options that may be supplied to
82
+ # the underlying text method call.
83
+ #
84
+ def make_icon(key, opts = {})
85
+ if opts[:inline_format]
86
+ inline_icon(key, opts)
87
+ else
88
+ Icon.new(key, self, opts)
89
+ end
90
+ end
91
+
92
+ # Initialize a new formatted text box containing
93
+ # icon information, but don't render it to the
94
+ # document.
95
+ #
96
+ # == Parameters:
97
+ # text::
98
+ # Input text to be parsed initially for <icon>
99
+ # tags, then passed to Prawn's formatted text
100
+ # parser.
101
+ #
102
+ # opts::
103
+ # A hash of options that may be supplied to the
104
+ # underlying text call.
105
+ #
106
+ def inline_icon(text, opts = {})
107
+ parsed = Icon::Parser.format(self, text)
108
+ content = Text::Formatted::Parser.format(parsed)
109
+ box_options = opts.merge(
110
+ inline_format: true,
111
+ document: self,
112
+ at: [bounds.left, cursor]
113
+ )
114
+ icon_box(content, box_options)
115
+ end
116
+
117
+ # Initialize a new Prawn::Icon, but don't render
118
+ # the icon to a document. Intended to be used as
119
+ # an entry of a data array when combined with
120
+ # Prawn::Table.
121
+ #
122
+ # == Parameters:
123
+ # key::
124
+ # Contains the key to a particular icon within
125
+ # a font family. The key may contain a string
126
+ # with format tags if +inline_format: true+ in
127
+ # the +opts+ hash.
128
+ #
129
+ # opts::
130
+ # A hash of options that may be supplied to the
131
+ # underlying text call.
132
+ #
133
+ # == Returns:
134
+ # A Hash containing +font+ and +content+ keys
135
+ # that match the data necessary for the
136
+ # specified icon.
137
+ #
138
+ # eg. { font: 'fa', content: '\uf047' }
139
+ #
140
+ # Note that the +font+ key will not be set
141
+ # if +inline_format: true+.
142
+ #
143
+ # == Examples:
144
+ # require 'prawn/table'
145
+ #
146
+ # data = [
147
+ # # Explicit brackets must be used here
148
+ # [pdf.table_icon('fa-arrows'), 'Cell 1'],
149
+ # ['Cell 2', 'Cell 3']
150
+ # ]
151
+ #
152
+ # pdf.table(data) => (2 x 2 table)
153
+ #
154
+ def table_icon(key, opts = {})
155
+ if opts[:inline_format]
156
+ content = Icon::Parser.format(self, key)
157
+ opts.merge(content: content)
158
+ else
159
+ make_icon(key, opts).format_hash
160
+ end
161
+ end
162
+
163
+ private
164
+
165
+ def icon_box(content, opts = {}) # :nodoc:
166
+ Text::Formatted::Box.new(content, opts).tap do |box|
167
+ box.render(dry_run: true)
168
+ self.y -= box.height
169
+ unless opts.fetch(:final_gap, true)
170
+ self.y -= box.line_gap + box.leading
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ attr_reader :set, :unicode
177
+
178
+ def initialize(key, document, opts = {})
179
+ @pdf = document
180
+ @set = opts[:set] ||
181
+ FontData.specifier_from_key(key)
182
+ @data = FontData.load(document, @set)
183
+ @key = strip_specifier_from_key(key)
184
+ @unicode = @data.unicode(@key)
185
+ @options = opts
186
+ end
187
+
188
+ def format_hash
189
+ base = { font: @set.to_s, content: @unicode }
190
+ opts = @options.dup
191
+ # Prawn::Table renames :color to :text_color
192
+ opts[:text_color] = opts.delete(:color)
193
+ base.merge(opts)
194
+ end
195
+
196
+ def render
197
+ @pdf.font(@data.path) do
198
+ @pdf.text @unicode, @options
199
+ end
200
+ end
201
+
202
+ private
203
+
204
+ def strip_specifier_from_key(key) # :nodoc:
205
+ reg = Regexp.new "#{@data.specifier}-"
206
+ key.sub(reg, '') # Only one specifier
207
+ end
208
+ end
209
+ end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '1.2.0'.freeze
11
+ VERSION = '1.3.0'.freeze
12
12
  end
13
13
  end
@@ -1,6 +1,7 @@
1
1
  basedir = File.expand_path(File.dirname(__FILE__))
2
2
  require "#{basedir}/lib/prawn/icon/version"
3
3
 
4
+ # rubocop:disable Metrics/BlockLength
4
5
  Gem::Specification.new do |spec|
5
6
  spec.name = 'prawn-icon'
6
7
  spec.version = Prawn::Icon::VERSION
@@ -26,9 +27,10 @@ Gem::Specification.new do |spec|
26
27
 
27
28
  spec.add_development_dependency('pdf-inspector', '~> 1.2.1')
28
29
  spec.add_development_dependency('rspec', '~> 3.5.0')
29
- spec.add_development_dependency('rubocop', '~> 0.38.0')
30
+ spec.add_development_dependency('rubocop', '~> 0.44.1')
30
31
  spec.add_development_dependency('rake')
31
32
  spec.add_development_dependency('pdf-reader', '~> 1.4')
33
+ spec.add_development_dependency('simplecov', '~> 0.12')
32
34
 
33
35
  spec.description = <<-END_DESC
34
36
  Prawn::Icon provides various icon fonts including
@@ -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
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.2.0
4
+ version: 1.3.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-09-16 00:00:00.000000000 Z
11
+ date: 2016-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.38.0
67
+ version: 0.44.1
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.38.0
74
+ version: 0.44.1
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
102
  version: '1.4'
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.12'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.12'
103
117
  description: |2
104
118
  Prawn::Icon provides various icon fonts including
105
119
  FontAwesome, Foundation Icons and GitHub Octicons
@@ -142,6 +156,7 @@ files:
142
156
  - lib/prawn/icon/base.rb
143
157
  - lib/prawn/icon/errors.rb
144
158
  - lib/prawn/icon/font_data.rb
159
+ - lib/prawn/icon/interface.rb
145
160
  - lib/prawn/icon/parser.rb
146
161
  - lib/prawn/icon/version.rb
147
162
  - prawn-icon.gemspec