prawn-icon 0.6.1 → 0.6.2
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 +24 -0
- data/README.md +120 -0
- data/fonts/fa/fa.yml +1 -1
- data/lib/prawn/icon.rb +52 -0
- data/lib/prawn/icon/font_data.rb +1 -1
- data/lib/prawn/icon/version.rb +1 -1
- data/prawn-icon.gemspec +13 -11
- data/spec/integration/icon_spec.rb +18 -0
- data/spec/unit/icon_spec.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71b726e45b44b50467f1410b717c9aca2901d25
|
4
|
+
data.tar.gz: c0bd60125ff1e91e4d0e1789f3f01ab2f1342058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9154c806a2213b4d772c20ab888fdc86b283d931918a2fe63d8e7896461757a6e05ad0aad88d4a8b75396ae4f4ec6c2f7f7ed3263b0980546db24a6263e2a859
|
7
|
+
data.tar.gz: 8c4b4a26ed6119e7fba8431a9d62ca2b2976c1ae935a86fc9ea6f2ac371201666e88adf9fad6803b840ab9aeed3e158b01ba735306fdce2f16b01ca7343056cc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# 0.6.2 - February 10, 2015
|
2
|
+
|
3
|
+
- Added this CHANGELOG.
|
4
|
+
- Added the `table_icon` method to simplify icon use in conjuction with `Prawn::Table`.
|
5
|
+
- Added a `.yardopts` file for better documentation.
|
6
|
+
- Clean `.gemspec` to increase readability.
|
7
|
+
|
8
|
+
# 0.6.1 - January 27, 2015
|
9
|
+
|
10
|
+
- Upgraded FontAwesome to `v4.3.0`.
|
11
|
+
|
12
|
+
# 0.6.0 - January 20, 2015
|
13
|
+
|
14
|
+
- Single-quoted attributes are now supported when using `inline_format: true`.
|
15
|
+
- Prawn is now specified as a runtime dependency of `prawn/icon`.
|
16
|
+
|
17
|
+
# 0.5.1 - November 2, 2014
|
18
|
+
|
19
|
+
- Bugfix for improperly cached font data.
|
20
|
+
- Added Codeclimate and Travis CI.
|
21
|
+
|
22
|
+
# 0.5.0 - October 29, 2014
|
23
|
+
|
24
|
+
- Initial public release.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# Prawn::Icon
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/prawn-icon)
|
4
|
+
[](http://travis-ci.org/jessedoyle/prawn-icon)
|
5
|
+
[](https://codeclimate.com/github/jessedoyle/prawn-icon)
|
6
|
+
|
7
|
+
Prawn::Icon provides a simple mechanism for rendering icons and icon fonts from within [Prawn](https://github.com/prawnpdf/prawn).
|
8
|
+
|
9
|
+
The following icon fonts ship with Prawn::Icon:
|
10
|
+
|
11
|
+
* FontAwesome (http://fontawesome.io/icons/)
|
12
|
+
* Foundation Icons (http://zurb.com/playground/foundation-icon-fonts-3)
|
13
|
+
* GitHub Octicons (https://octicons.github.com)
|
14
|
+
|
15
|
+
Prawn::Icon was originally written by Jesse Doyle.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Prawn::Icon is distributed via RubyGems. You can install it with the following command:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
gem install prawn-icon
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Prawn::Icon was designed to have an API familiar to Prawn. A single icon may be rendered as such:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'prawn/icon'
|
31
|
+
|
32
|
+
Prawn::Document.generate('icons.pdf') do |pdf|
|
33
|
+
pdf.icon 'fa-beer', size: 60
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
produces:
|
38
|
+
|
39
|
+

|
40
|
+
|
41
|
+
## Inline Icons
|
42
|
+
|
43
|
+
You can also provide the `inline_format: true` option to Prawn::Icon:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'prawn/icon'
|
47
|
+
|
48
|
+
Prawn::Document.generate('inline_icons.pdf') do |pdf|
|
49
|
+
pdf.icon 'Enjoy: <icon size="20" color="AAAAAA">fa-beer</icon>', inline_format: true
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
produces:
|
54
|
+
|
55
|
+

|
56
|
+
|
57
|
+
When using `inline_format: true`, you may supply `<icon>` tags with `color` and `size` attributes.
|
58
|
+
|
59
|
+
## Use with [Prawn::Table](https://github.com/prawnpdf/prawn-table)
|
60
|
+
|
61
|
+
A `table_icon` method may be called when creating a table's data array to render icons within a table cell:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'prawn/icon'
|
65
|
+
require 'prawn/table'
|
66
|
+
|
67
|
+
Prawn::Document.generate('table_icons.pdf') do |pdf|
|
68
|
+
|
69
|
+
data = [
|
70
|
+
# Explicit brackets must be used here
|
71
|
+
[pdf.table_icon('fa-birthday-cake'), 'Cake'],
|
72
|
+
['is', 'Great!']
|
73
|
+
]
|
74
|
+
|
75
|
+
pdf.table(data) # => (2 x 2 table)
|
76
|
+
```
|
77
|
+
|
78
|
+
Note that the `table_icon` method does not support the `inline_format: true` option.
|
79
|
+
|
80
|
+
## Specifying Icon Families
|
81
|
+
|
82
|
+
Prawn::Icon uses the prefix of an icon key to determine which font family is used to render a particular icon.
|
83
|
+
|
84
|
+
Currently supported prefixes include:
|
85
|
+
|
86
|
+
* `fa` - Fontawesome (eg. `fa-arrows`)
|
87
|
+
* `fi` - Foundation Icons (eg. `fi-compass`)
|
88
|
+
* `octicon` - Github Octicons (eg. `octicon-calendar`)
|
89
|
+
|
90
|
+
## How It Works
|
91
|
+
|
92
|
+
Prawn::Icon uses a "legend" to map icon keys to unicode characters that respresent a particular icon within the font file.
|
93
|
+
|
94
|
+
This legend is a standard `.yml` file located within the font's directory.
|
95
|
+
|
96
|
+
If you wish to fork this repository and add a new font, you'll likely need to supply a corresponding legend file. Please see the current legend files within the `fonts` directory for examples.
|
97
|
+
|
98
|
+
## Examples
|
99
|
+
|
100
|
+
A Rake task is included to generate documents that display each icon and it's corresponding icon key.
|
101
|
+
|
102
|
+
The command:
|
103
|
+
|
104
|
+
```bash
|
105
|
+
rake legend
|
106
|
+
```
|
107
|
+
|
108
|
+
should generate these files when run from Prawn::Icon's gem directory.
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
I'll gladly accept pull requests that are well tested for any bug found in Prawn::Icon.
|
113
|
+
|
114
|
+
If there is enough demand for including a particular icon font, I will also accept a pull request to include it in Prawn::Icon.
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
Prawn::Icon is licensed under the same terms that are used by Prawn.
|
119
|
+
|
120
|
+
You may choose between Matz's terms, the GPLv2, or GPLv3. For details, please see the LICENSE, GPLv2, and GPLv3 files.
|
data/fonts/fa/fa.yml
CHANGED
data/lib/prawn/icon.rb
CHANGED
@@ -125,6 +125,50 @@ module Prawn
|
|
125
125
|
opts.merge!(inline_format: true, document: self)
|
126
126
|
Text::Formatted::Box.new(content, opts)
|
127
127
|
end
|
128
|
+
|
129
|
+
# Initialize a new Prawn::Icon, but don't render
|
130
|
+
# the icon to a document. Intended to be used as
|
131
|
+
# an entry of a data array when combined with
|
132
|
+
# Prawn::Table.
|
133
|
+
#
|
134
|
+
# == Parameters:
|
135
|
+
# key::
|
136
|
+
# Contains the key to a particular icon within
|
137
|
+
# a font family. Note that :inline_format is not
|
138
|
+
# supported as a valid option.
|
139
|
+
#
|
140
|
+
# opts::
|
141
|
+
# A hash of options that may be supplied to the
|
142
|
+
# underlying text call. Note that :inline_format
|
143
|
+
# is not supported as a valid option.
|
144
|
+
#
|
145
|
+
# == Returns:
|
146
|
+
# A Hash containing +font+ and +content+ keys
|
147
|
+
# that match the data necessary for the
|
148
|
+
# specified icon.
|
149
|
+
#
|
150
|
+
# eg. { font: 'fa', content: '/uf047' }
|
151
|
+
#
|
152
|
+
# == Examples:
|
153
|
+
# require 'prawn/table'
|
154
|
+
#
|
155
|
+
# data = [
|
156
|
+
# # Explicit brackets must be used here
|
157
|
+
# [pdf.table_icon('fa-arrows'), 'Cell 1'],
|
158
|
+
# ['Cell 2', 'Cell 3']
|
159
|
+
# ]
|
160
|
+
#
|
161
|
+
# pdf.table(data) => (2 x 2 table)
|
162
|
+
#
|
163
|
+
def table_icon(key, opts = {})
|
164
|
+
if opts.delete(:inline_format)
|
165
|
+
raise Prawn::Errors::UnknownOption,
|
166
|
+
'Inline formatting is not supported.'
|
167
|
+
end
|
168
|
+
|
169
|
+
icon = make_icon(key, opts)
|
170
|
+
icon.format_hash
|
171
|
+
end
|
128
172
|
end
|
129
173
|
|
130
174
|
attr_reader :set, :unicode
|
@@ -139,6 +183,14 @@ module Prawn
|
|
139
183
|
@options = opts
|
140
184
|
end
|
141
185
|
|
186
|
+
def format_hash
|
187
|
+
base = { font: @set.to_s, content: @unicode }
|
188
|
+
opts = @options.dup
|
189
|
+
# Prawn::Table renames :color to :text_color
|
190
|
+
opts[:text_color] = opts.delete(:color)
|
191
|
+
base.merge(opts)
|
192
|
+
end
|
193
|
+
|
142
194
|
def render
|
143
195
|
@pdf.font(@data.path) do
|
144
196
|
@pdf.text @unicode, @options
|
data/lib/prawn/icon/font_data.rb
CHANGED
data/lib/prawn/icon/version.rb
CHANGED
data/prawn-icon.gemspec
CHANGED
@@ -2,23 +2,25 @@ basedir = File.expand_path(File.dirname(__FILE__))
|
|
2
2
|
require "#{basedir}/lib/prawn/icon/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name
|
6
|
-
spec.version
|
5
|
+
spec.name = 'prawn-icon'
|
6
|
+
spec.version = Prawn::Icon::VERSION
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
|
-
spec.summary
|
9
|
-
spec.files
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
spec.summary = 'Provides icon fonts for PrawnPDF'
|
9
|
+
spec.files = Dir.glob('{lib,spec,fonts,examples}/**/**/*') +
|
10
|
+
%w(prawn-icon.gemspec Gemfile Rakefile) +
|
11
|
+
%w(README.md CHANGELOG.md) +
|
12
|
+
%w(COPYING LICENSE GPLv2 GPLv3)
|
13
|
+
|
14
|
+
spec.require_path = 'lib'
|
15
|
+
spec.required_ruby_version = '>= 1.9.3'
|
14
16
|
spec.required_rubygems_version = '>= 1.3.6'
|
15
17
|
|
16
18
|
spec.homepage = 'https://github.com/jessedoyle/prawn-icon/'
|
17
19
|
|
18
20
|
spec.test_files = Dir['spec/*_spec.rb']
|
19
|
-
spec.authors
|
20
|
-
spec.email
|
21
|
-
spec.licenses
|
21
|
+
spec.authors = ['Jesse Doyle']
|
22
|
+
spec.email = ['jdoyle@ualberta.ca']
|
23
|
+
spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
|
22
24
|
|
23
25
|
spec.add_dependency('prawn', '>= 1.3.0', '< 3.0.0')
|
24
26
|
|
@@ -100,4 +100,22 @@ describe Prawn::Icon::Interface do
|
|
100
100
|
expect(icon.class).to eq(Prawn::Text::Formatted::Box)
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
104
|
+
describe '::table_icon' do
|
105
|
+
it 'should return a hash with font and content keys' do
|
106
|
+
pdf = create_pdf
|
107
|
+
icon = pdf.table_icon 'fa-arrows'
|
108
|
+
|
109
|
+
expect(icon.class).to eq(Hash)
|
110
|
+
expect(icon[:font]).to eq('fa')
|
111
|
+
expect(icon[:content]).to eq("\uf047")
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should raise an error if inline_format: true' do
|
115
|
+
pdf = create_pdf
|
116
|
+
proc = Proc.new { pdf.table_icon 'fa-arrows', inline_format: true }
|
117
|
+
|
118
|
+
expect(proc).to raise_error(Prawn::Errors::UnknownOption)
|
119
|
+
end
|
120
|
+
end
|
103
121
|
end
|
data/spec/unit/icon_spec.rb
CHANGED
@@ -42,6 +42,26 @@ describe Prawn::Icon do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe '#format_hash' do
|
46
|
+
it 'should add :font and :content keys' do
|
47
|
+
pdf = create_pdf
|
48
|
+
icon = Prawn::Icon.new 'fa-arrows', pdf
|
49
|
+
hash = icon.format_hash
|
50
|
+
|
51
|
+
expect(hash[:font]).to eq('fa')
|
52
|
+
expect(hash[:content]).to eq("\uf047")
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should rename key :color to :text_color' do
|
56
|
+
pdf = create_pdf
|
57
|
+
icon = Prawn::Icon.new 'fa-arrows', pdf, color: '0099ff'
|
58
|
+
hash = icon.format_hash
|
59
|
+
|
60
|
+
expect(hash[:color]).to be_nil
|
61
|
+
expect(hash[:text_color]).to eq('0099ff')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
45
65
|
describe '#render' do
|
46
66
|
it 'should render an icon to the page' do
|
47
67
|
pdf = create_pdf
|
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: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -168,6 +168,8 @@ files:
|
|
168
168
|
- prawn-icon.gemspec
|
169
169
|
- Gemfile
|
170
170
|
- Rakefile
|
171
|
+
- README.md
|
172
|
+
- CHANGELOG.md
|
171
173
|
- COPYING
|
172
174
|
- LICENSE
|
173
175
|
- GPLv2
|