font_awesome5_rails 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -10
- data/app/helpers/font_awesome5/rails/icon_helper.rb +19 -1
- data/lib/font_awesome5_rails/parsers/fa_icon_parser.rb +7 -0
- data/lib/font_awesome5_rails/parsers/parse_methods.rb +19 -0
- data/lib/font_awesome5_rails/version.rb +2 -2
- data/spec/font_awesome5_rails_spec.rb +26 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fce62a97997f16202fbb41c0be992ccd4ed2bb71c9dec2d99423dca6d88dd78f
|
4
|
+
data.tar.gz: aa16178143f28cee6a43f56d4b712a6eee0f5d330a3f76a647767cefedb9d436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb46f82c0262b631b3f22bafefae72bbf70ba8dd2805ca56783f2d3d50e25e1c2d905fe0b7dc131b6b4c15f3c58a2b12667eb0a03de56e7d83d829ac81562b8
|
7
|
+
data.tar.gz: 32a56d7102fc10eb9fa7c6353d8692ad6889c9f2ae668377d216cca3be69477385b58804b5c7ef8f662e3fafd349660b95bdc869db7fc7956f3c3d8668350ccd
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Font Awesome 5 Rails
|
2
|
-
[![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=1.
|
2
|
+
[![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=1.5.0&x2=0)](https://badge.fury.io/rb/font_awesome5_rails)
|
3
3
|
[![FA5 version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=gh&type=6&v=5.15.3&x2=0)](https://github.com/tomkra/font_awesome5_rails/blob/master/lib/font_awesome5_rails/version.rb)
|
4
4
|
[![Build Status](https://travis-ci.org/tomkra/font_awesome5_rails.svg?branch=master)](https://travis-ci.org/tomkra/font_awesome5_rails)
|
5
5
|
[![HitCount](http://hits.dwyl.io/tomkra/tomkra/font_awesome5_rails.svg)](http://hrits.dwyl.io/tomkra/tomkra/font_awesome5_rails)
|
@@ -23,6 +23,7 @@ Keep track of changes in [Changelog](https://github.com/tomkra/font_awesome5_rai
|
|
23
23
|
- **[Layered and Stacked icons](#layered-and-stacked-icons)** <br />
|
24
24
|
|
25
25
|
**[Use as images](#use-as-images)** <br />
|
26
|
+
**[Use inline SVGs](#use-inline-svgs)** <br />
|
26
27
|
**[FontAwesome 5 Pro icons](#fontawesome-5-pro-icons)** <br />
|
27
28
|
**[Release notes](#release-notes)** <br />
|
28
29
|
**[Buy me a coffee](#buy-me-a-coffee)** <br />
|
@@ -104,17 +105,18 @@ fa_icon(:camera_retro, text: 'Camera', right: true)
|
|
104
105
|
# => <i class="fas fa-camera-retro"></i>
|
105
106
|
```
|
106
107
|
|
107
|
-
### Solid, Regular, Light, Brand, Duotone icon types
|
108
|
+
### Solid, Regular, Light, Brand, Duotone, Uploaded icon types
|
108
109
|
In Font Awesome 5 there are several different types of icons. In font_awesome5_rails gem default icon type is ```solid```.
|
109
110
|
If you want to use different icon style you can do this through ```type``` attribute.
|
110
111
|
|
111
|
-
|
|
112
|
-
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
|Style | type: | type: |
|
113
|
+
|-------------|-------|---------|
|
114
|
+
|Solid | :fas |:solid |
|
115
|
+
|Regular | :far |:regular |
|
116
|
+
|Light | :fal |:light |
|
117
|
+
|Brand | :fab |:brand |
|
118
|
+
|Duotone | :fad |:duotone |
|
119
|
+
|Kit Uploaded | :fak |:uploaded|
|
118
120
|
|
119
121
|
|
120
122
|
```ruby
|
@@ -136,6 +138,12 @@ fa_icon('camera-retro', type: :duotone)
|
|
136
138
|
fa_icon('camera-retro', type: :fab)
|
137
139
|
# => <i class="fab fa-camera-retro"></i>
|
138
140
|
|
141
|
+
fa_icon('custom-uploaded', type: :fak)
|
142
|
+
# => <i class="fak fa-custom-uploaded"></i>
|
143
|
+
|
144
|
+
fa_icon('custom-uploaded', type: :uploaded)
|
145
|
+
# => <i class="fak fa-custom-uploaded"></i>
|
146
|
+
|
139
147
|
```
|
140
148
|
|
141
149
|
Each icon type has its own helper method so you don't need to provide the ```type``` attribute in every call.
|
@@ -255,6 +263,22 @@ More examples can be found in specs.
|
|
255
263
|
|
256
264
|
More animation and data attributes can be found on [FontAwesome documentation](https://fontawesome.com/how-to-use/svg-with-js).
|
257
265
|
|
266
|
+
|
267
|
+
## Use inline SVGs
|
268
|
+
You can also include icons as inline SVGs in your views directly, avoiding any JS entirely.
|
269
|
+
```ruby
|
270
|
+
fa_inline_icon('camera') # defaults to solid
|
271
|
+
fa_inline_icon('camera', style: :solid)
|
272
|
+
fa_inline_icon('camera', class: 'my-svg')
|
273
|
+
```
|
274
|
+
|
275
|
+
There are also helpers for the various styles available:
|
276
|
+
```ruby
|
277
|
+
fas_inline_icon('camera')
|
278
|
+
fab_inline_icon('facebook')
|
279
|
+
far_inline_icon('bell')
|
280
|
+
```
|
281
|
+
|
258
282
|
## FontAwesome 5 Pro icons
|
259
283
|
Due to licence policy this gem pack only free FA5 icons. However ```fa_icon``` helper support all types of icons. If you purchased FA5 Pro icons and want to use helpers provided by this gem it's possible.
|
260
284
|
1. Add this gem to your ```Gemfile``` without including anything to ```application.css``` and ```application.js```.
|
@@ -276,4 +300,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
276
300
|
### Buy me a coffee
|
277
301
|
If you liked this gem, you can
|
278
302
|
<a href="https://www.buymeacoffee.com/tomkra" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
|
279
|
-
.
|
303
|
+
.
|
@@ -5,6 +5,19 @@ require 'font_awesome5_rails/parsers/fa_stacked_icon_parser'
|
|
5
5
|
module FontAwesome5
|
6
6
|
module Rails
|
7
7
|
module IconHelper
|
8
|
+
ICON_TYPES = %w(fas far fal fab fad fak).freeze
|
9
|
+
|
10
|
+
def fa_inline_icon(icon, options = {})
|
11
|
+
file = FontAwesome5Rails::Parsers::FaIconParser.new(icon, options).file
|
12
|
+
return nil unless Pathname.new(file).exist?
|
13
|
+
|
14
|
+
doc = Nokogiri::XML(File.read(file))
|
15
|
+
svg = doc.root
|
16
|
+
svg[:fill] = 'currentColor'
|
17
|
+
classes = [options[:class], svg[:class]].flatten.compact.join ' '
|
18
|
+
svg[:class] = classes if classes
|
19
|
+
ActiveSupport::SafeBuffer.new(svg.to_s)
|
20
|
+
end
|
8
21
|
|
9
22
|
def fa5_icon(icon, options = {})
|
10
23
|
FontAwesome5Rails::Parsers::FaIconParser.new(icon, options).tag
|
@@ -34,12 +47,17 @@ module FontAwesome5
|
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
37
|
-
|
50
|
+
ICON_TYPES.each do |type|
|
38
51
|
define_method :"#{type}_icon" do |icon, options = {}|
|
39
52
|
options[:type] = type.to_sym unless options.key? :type
|
40
53
|
fa_icon(icon, options)
|
41
54
|
end
|
42
55
|
|
56
|
+
define_method :"#{type}_inline_icon" do |icon, options = {}|
|
57
|
+
options[:type] = type.to_sym unless options.key? :type
|
58
|
+
fa_inline_icon(icon, options)
|
59
|
+
end
|
60
|
+
|
43
61
|
define_method :"#{type}_stacked_icon" do |icon, options = {}|
|
44
62
|
options[:type] = type.to_sym unless options.key? :type
|
45
63
|
fa_stacked_icon(icon, options)
|
@@ -6,6 +6,8 @@ module FontAwesome5Rails
|
|
6
6
|
include ActionView::Helpers::TagHelper
|
7
7
|
include ParseMethods
|
8
8
|
|
9
|
+
GEM_PATH = Pathname.new('../../../../').expand_path(__FILE__)
|
10
|
+
|
9
11
|
attr_reader :icon, :options, :data, :style, :text, :title, :right, :attrs
|
10
12
|
|
11
13
|
def initialize(icon, options)
|
@@ -33,6 +35,11 @@ module FontAwesome5Rails
|
|
33
35
|
@right ? (text_content_tag + icon_content_tag) : (icon_content_tag + text_content_tag)
|
34
36
|
end
|
35
37
|
|
38
|
+
def file
|
39
|
+
file = GEM_PATH.join("app/assets/images/fa5/#{icon_type_path(@options[:type])}/#{@icon}.svg")
|
40
|
+
file.exist? ? file : nil
|
41
|
+
end
|
42
|
+
|
36
43
|
private
|
37
44
|
|
38
45
|
def parse_classes
|
@@ -13,11 +13,30 @@ module FontAwesome5Rails
|
|
13
13
|
'fab'
|
14
14
|
when :fad, :duotone
|
15
15
|
'fad'
|
16
|
+
when :fak, :uploaded
|
17
|
+
'fak'
|
16
18
|
else
|
17
19
|
'fas'
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
def icon_type_path(type)
|
24
|
+
return 'solid' if type.nil?
|
25
|
+
|
26
|
+
case type.to_sym
|
27
|
+
when :far, :regular
|
28
|
+
'regular'
|
29
|
+
when :fal, :light
|
30
|
+
'light'
|
31
|
+
when :fab, :brand
|
32
|
+
'brands'
|
33
|
+
when :fad, :duotone
|
34
|
+
'duotone'
|
35
|
+
else
|
36
|
+
'solid'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
21
40
|
def prepend_fa(string)
|
22
41
|
"fa-#{string}"
|
23
42
|
end
|
@@ -43,11 +43,13 @@ describe FontAwesome5Rails do
|
|
43
43
|
expect(send(subject, 'camera-retro', type: :fal)).to eq '<i class="fal fa-camera-retro"></i>'
|
44
44
|
expect(send(subject, 'camera-retro', type: :fab)).to eq '<i class="fab fa-camera-retro"></i>'
|
45
45
|
expect(send(subject, 'camera-retro', type: :fad)).to eq '<i class="fad fa-camera-retro"></i>'
|
46
|
+
expect(send(subject, 'camera-retro', type: :fak)).to eq '<i class="fak fa-camera-retro"></i>'
|
46
47
|
expect(send(subject, 'camera-retro', type: :solid)).to eq '<i class="fas fa-camera-retro"></i>'
|
47
48
|
expect(send(subject, 'camera-retro', type: :regular)).to eq '<i class="far fa-camera-retro"></i>'
|
48
49
|
expect(send(subject, 'camera-retro', type: :light)).to eq '<i class="fal fa-camera-retro"></i>'
|
49
50
|
expect(send(subject, 'camera-retro', type: :brand)).to eq '<i class="fab fa-camera-retro"></i>'
|
50
51
|
expect(send(subject, 'camera-retro', type: :duotone)).to eq '<i class="fad fa-camera-retro"></i>'
|
52
|
+
expect(send(subject, 'camera-retro', type: :uploaded)).to eq '<i class="fak fa-camera-retro"></i>'
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'should return correct class tags' do
|
@@ -196,6 +198,15 @@ describe FontAwesome5Rails do
|
|
196
198
|
end
|
197
199
|
end
|
198
200
|
|
201
|
+
describe 'fa_inline_icon tags' do
|
202
|
+
it 'should return correct tags' do
|
203
|
+
expect(send(:fa_inline_icon,
|
204
|
+
'square')).to match '<path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z"/>'
|
205
|
+
expect(send(:fa_inline_icon,
|
206
|
+
'square', type: :regular)).to match '<path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-6 400H54c-3.3 0-6-2.7-6-6V86c0-3.3 2.7-6 6-6h340c3.3 0 6 2.7 6 6v340c0 3.3-2.7 6-6 6z"/>'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
199
210
|
describe '[fas, far, fal, fab, fad, far_stacked_icon]_icon helper method' do
|
200
211
|
%w(fas far fal fab fad).each do |type|
|
201
212
|
it "#{type}_icon should be defined and use the right icon type" do
|
@@ -203,8 +214,21 @@ describe FontAwesome5Rails do
|
|
203
214
|
|
204
215
|
expect(self).to respond_to(method)
|
205
216
|
expect(send(method, 'camera-retro')).to eq "<i class=\"#{type} fa-camera-retro\"></i>"
|
206
|
-
expect(send(method, 'camera-retro', type: :fal)).to eq
|
207
|
-
expect(send(method, 'camera-retro', type: :brand,
|
217
|
+
expect(send(method, 'camera-retro', type: :fal)).to eq '<i class="fal fa-camera-retro"></i>'
|
218
|
+
expect(send(method, 'camera-retro', type: :brand,
|
219
|
+
class: 'test')).to eq '<i class="fab fa-camera-retro test"></i>'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe '[fas, far]_inline_icon helper method' do
|
225
|
+
%w[fas far].each do |type|
|
226
|
+
it "#{type}_inline_icon should be defined and use the right icon type" do
|
227
|
+
method = :"#{type}_inline_icon"
|
228
|
+
|
229
|
+
expect(self).to respond_to(method)
|
230
|
+
expect(send(method,
|
231
|
+
'square')).to match '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor" class="">'
|
208
232
|
end
|
209
233
|
end
|
210
234
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: font_awesome5_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomkra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.11.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: activesupport
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|