fa_rails 0.1.21 → 0.1.26

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
  SHA256:
3
- metadata.gz: f664c27729b24055feaa406ad8847a1cd8e2c6bf176d513dff946c0cacfd088b
4
- data.tar.gz: c2b3557385fe58d2c0cc87cc5f88b64b4a420cbf4ab521062e794253e2fc2672
3
+ metadata.gz: 9b54f242a9e548eec5062f96702e9932068fe7c7c51859b5447da6365f2ffe98
4
+ data.tar.gz: 37fa7e6971c0db4f1bf67ff689e0ce30e52b5f1c7df9ff73af208b96c8589998
5
5
  SHA512:
6
- metadata.gz: 7f5b7a3d34e521837f5576c4a4da657c6e7d91fb30a131a32427f1750ffd183ab0281c1f11209c370ad96a11810f1e3a0b5381a947b6a126288aaa17e0652127
7
- data.tar.gz: c6bfde33dce0ae1403553ca8ff1e36943e203ba6819010b9845b442e0ae46a242c16c63c424c121475af3fa6652f687dcec671150c4bff55613ac491cdeec7fc
6
+ metadata.gz: 574d7b97c657e3030300737364079cfb095fc7fbdde7c018f2efda666c2b460eb5788639ef44786bbb3eb4b046ca906d937b573c0eb0ccdfcf561c80f2685ab6
7
+ data.tar.gz: 7cef6d1273dbf03b156505e48e3f91685f1fefc3f8c79a852bdf5abf1fc3a2366b881b34b84a3bb0b20020d784a1dc1618fcdd651e424091850d2eba8f25844a
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.21)
4
+ fa_rails (0.1.26)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.3)
10
10
  docile (1.3.1)
11
- json (2.1.0)
12
- rake (12.3.1)
11
+ json (2.3.1)
12
+ rake (12.3.3)
13
13
  rspec (3.7.0)
14
14
  rspec-core (~> 3.7.0)
15
15
  rspec-expectations (~> 3.7.0)
data/README.md CHANGED
@@ -29,29 +29,41 @@ corresponding locations in your app, and ensure you correctly include all files.
29
29
 
30
30
  ### FontAwesome CDN
31
31
 
32
- Go to the FontAwesome
33
- [How to Use](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=web-fonts-with-css)
34
- page and copy the appropriate CDN link tag.
32
+ You can also link into the FontAwesome CDN, in either of two ways:
35
33
 
36
- You can also `include FA`, then use the built-in helper method in your layout:
34
+ #### Version-Specific Link
35
+
36
+ You can use this helper method in your layout:
37
37
 
38
38
  ```ruby
39
39
  FA::Link.new(version: 'v5.3.1', integrity: 'sha384-some-key-here').safe
40
40
  ```
41
41
 
42
- #### Free
42
+ Or, go to the FontAwesome
43
+ [How to Use](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=web-fonts-with-css)
44
+ page and copy the appropriate CDN link tag.
45
+
46
+ **Be sure to also register each domain that will use this CDN link.**
47
+
48
+ ##### Free
43
49
 
44
50
  ```html
45
51
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-some-key-here" crossorigin="anonymous">
46
52
  ```
47
53
 
48
- #### Pro
54
+ ##### Pro
49
55
 
50
56
  ```html
51
57
  <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-some-key-here" crossorigin="anonymous">
52
58
  ```
53
59
 
54
- **Be sure to also register each domain that will use this CDN link.**
60
+ #### Kit Link
61
+
62
+ Use this helper method in your layout:
63
+
64
+ ```ruby
65
+ FA::Link.kit('kit-id')
66
+ ```
55
67
 
56
68
  ## Usage
57
69
 
@@ -147,10 +159,21 @@ css #=> String – arbitrary CSS classes, space-delimited, applied to the layer
147
159
  FA::Icon.p('lock', fa: 'fw')
148
160
  #=> "<i class='fas fa-fw fa-lock fa-1x' style='' data-fa-transform='' title=''></i>"
149
161
 
162
+ # Duotone fire-alt icon with swapped opacity
163
+ FA::Icon.p('fire-alt', fa: 'swap-opacity')
164
+ #=> "<i class='fas fa-swap-opacity fa-fire-alt fa-1x' style='' data-fa-transform='' title=''></i>"
165
+
150
166
  # Duotone fire-alt icon with specified opacities
151
167
  FA::Icon.p('fire-alt', style: :duotone, raw_css: { '--fa-primary-opacity' => '0.6', '--fa-secondary-opacity' => '0.4' })
152
168
  #=> "<i class='fad fa-fire-alt fa-1x' style='--fa-primary-opacity: 0.4; --fa-secondary-opacity: 0.6;' data-fa-transform='' title=''></i>"
153
169
 
170
+ # You can also use this simplified configuration option for adding styles
171
+ # This is reforatted and merged into :raw_css
172
+ # Accepts either snake_case symbols or spear-case strings as keys, and strings or symbols as values
173
+ # This is the easiest way to add primary/secondary styles for duotone icons
174
+ FA::Icon.p('fire-alt', style: :duotone, fa_styles: { primary_opacity: '0.6', secondary_opacity: '0.4', primary_color: :green, secondary_color: '#DD2200' })
175
+ #=> "<i class='fad fa-fire-alt fa-1x' style='--fa-primary-opacity: 0.6; --fa-secondary-opacity: 0.4; --fa-primary-color: green; --fa-secondary-color: #DD2200;' data-fa-transform='' title=''></i>"
176
+
154
177
  # Counter span, with value 5
155
178
  FA::Span.p('counter', 5)
156
179
  #=> "<span class='fa-layers-counter ' style='' data-fa-transform=''>5</span>"
data/fa_rails.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fa_rails'
3
- s.version = '0.1.21'
4
- s.date = '2019-08-09'
3
+ s.version = '0.1.26'
4
+ s.date = '2021-04-03'
5
5
  s.summary = 'FontAwesome helper for Rails'
6
6
  s.description = 'A helper module for using FontAwesome icons in Rails.'
7
7
  s.homepage = 'http://rubygems.org/gems/fa_rails'
data/lib/fa/base.rb CHANGED
@@ -3,6 +3,11 @@
3
3
  module FA
4
4
  # FontAwesome 5 (Pro) Helper core class for inheritance
5
5
  class Base
6
+ STYLES = {
7
+ solid: 's', regular: 'r', light: 'l', thin: 't',
8
+ duotone: 'd', brands: 'b', kit_upload: 'k'
9
+ }.freeze
10
+
6
11
  # Outputs the formatted string directly.
7
12
  def raw
8
13
  #
@@ -93,6 +98,7 @@ module FA
93
98
 
94
99
  def parse_options(options)
95
100
  parse_classes(options)
101
+ options = merge_fa_styles(options)
96
102
  parse_styles(options)
97
103
  parse_transforms(options)
98
104
  end
@@ -100,8 +106,24 @@ module FA
100
106
  def parse_classes(options)
101
107
  @classes = []
102
108
  @classes << parse_style(options)
103
- @classes << options[:fa].to_s.split(' ').map { |c| "fa-#{c}" }
104
- @classes << options[:css].to_s.split(' ')
109
+ @classes << format_classes(options[:fa], prefix: 'fa-')
110
+ @classes << format_classes(options[:css])
111
+ end
112
+
113
+ def format_classes(classes, prefix: nil)
114
+ classes = classes.to_s.split(' ') unless classes.is_a?(Array)
115
+ classes.map { |c| "#{prefix}#{c}" }
116
+ end
117
+
118
+ def merge_fa_styles(options)
119
+ fa_styles = options.delete(:fa_styles)
120
+ return options unless fa_styles
121
+
122
+ fa_styles = fa_styles.each_with_object({}) do |(k, v), hash|
123
+ hash["--fa-#{k.to_s.tr('_', '-')}"] = v.to_s
124
+ end
125
+ options[:raw_css] = options[:raw_css].merge(fa_styles)
126
+ options
105
127
  end
106
128
 
107
129
  def parse_styles(options)
@@ -118,10 +140,10 @@ module FA
118
140
  end
119
141
 
120
142
  def parse_style(options)
121
- return if options[:css].to_s.match?(/fa[srldb]/)
122
- return 'fas' unless %i[solid regular light duotone brands].include?(options[:style])
143
+ return if options[:css].to_s.match?(/fa[srldbk]/)
144
+ return 'fas' unless STYLES.keys.include?(options[:style])
123
145
 
124
- 'fa' + { solid: 's', regular: 'r', light: 'l', duotone: 'd', brands: 'b' }[options[:style]]
146
+ 'fa' + STYLES[options[:style]]
125
147
  end
126
148
  end
127
149
  end
data/spec/lib/fa_spec.rb CHANGED
@@ -28,11 +28,13 @@ RSpec.describe FA do
28
28
  end
29
29
 
30
30
  describe 'icon' do
31
- it 'should generate the correct icon from a string or symbol name' do
31
+ it 'should generate the correct icon from a string name' do
32
32
  expect(FA::Icon.p('help')).to eql(
33
33
  "<i class='fas fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
34
34
  )
35
+ end
35
36
 
37
+ it 'should generate the correct icon from a symbol name' do
36
38
  expect(FA::Icon.p(:help)).to eql(
37
39
  "<i class='fas fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
38
40
  )
@@ -45,6 +47,36 @@ RSpec.describe FA do
45
47
  )
46
48
  end
47
49
 
50
+ it 'should correctly handle a string fa option' do
51
+ expect(FA::Icon.p(:help, fa: 'fw 2x')).to eql(
52
+ "<i class='fas fa-fw fa-2x fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
53
+ )
54
+ end
55
+
56
+ it 'should correctly handle an array fa option' do
57
+ expect(FA::Icon.p(:help, fa: %i[fw 2x])).to eql(
58
+ "<i class='fas fa-fw fa-2x fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
59
+ )
60
+ end
61
+
62
+ it 'should correctly handle a string css option' do
63
+ expect(FA::Icon.p(:help, css: 'green big')).to eql(
64
+ "<i class='fas green big fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
65
+ )
66
+ end
67
+
68
+ it 'should correctly handle an array css option' do
69
+ expect(FA::Icon.p(:help, css: %i[green big])).to eql(
70
+ "<i class='fas green big fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
71
+ )
72
+ end
73
+
74
+ it 'should correctly handle a nil css option' do
75
+ expect(FA::Icon.p(:help, css: nil)).to eql(
76
+ "<i class='fas fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
77
+ )
78
+ end
79
+
48
80
  it 'should raise ArgumentError for other input types' do
49
81
  [nil, [], 0].each do |fa|
50
82
  expect { FA::Icon.p(fa) }.to raise_error(
@@ -58,6 +90,19 @@ RSpec.describe FA do
58
90
  "<i class='fab fa-github fa-1x' style='' data-fa-transform='' title=''></i>"
59
91
  )
60
92
  end
93
+
94
+ it 'should generate the correct icon with styles' do
95
+ expect(
96
+ FA::Icon.p(
97
+ 'fire-alt', style: :duotone, fa_styles: {
98
+ primary_opacity: '0.6', secondary_opacity: '0.4', primary_color: :green, secondary_color: '#DD2200'
99
+ }
100
+ )
101
+ ).to eql(
102
+ "<i class='fad fa-fire-alt fa-1x' style='--fa-primary-opacity: 0.6; --fa-secondary-opacity: 0.4; " \
103
+ "--fa-primary-color: green; --fa-secondary-color: #DD2200;' data-fa-transform='' title=''></i>"
104
+ )
105
+ end
61
106
  end
62
107
 
63
108
  describe 'layer' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fa_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2021-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -77,6 +77,7 @@ extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - ".gitignore"
80
+ - ".ruby-version"
80
81
  - ".travis.yml"
81
82
  - Gemfile
82
83
  - Gemfile.lock
@@ -113,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  - !ruby/object:Gem::Version
114
115
  version: '0'
115
116
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.6
117
+ rubygems_version: 3.2.15
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: FontAwesome helper for Rails