fa_rails 0.1.18 → 0.1.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 771f0170fa690c018158f89119397efc56702af5e02b94bb2627b0f6f2b4cab6
4
- data.tar.gz: 2b5bef6128cd65714edaea480c8024c3f871a3d4c240d79eb008411afbfc0f2c
3
+ metadata.gz: a0c5ec0ed2af445a927bc74382f2c7f3b058fa14e547972ec70ce36f24ab263b
4
+ data.tar.gz: b7361b459aaee1fcc70b068048bbbc37cb4f857b1f7ca682f8dc05b262213435
5
5
  SHA512:
6
- metadata.gz: 06bb529758d62780a54fcc01db8a94ae5bf71e12a4f5b936ff7a7c5198eb96d5ed0e31cc41f9690dba08a3010542ffbdeb7ac0661f2668b82404705b5eac8bbf
7
- data.tar.gz: 605a8dfe7d36472432e87f99f55faab94e8e6012af8f0e52e448230126ad4ea537fc13fd6494b020c1e9b71bc19ea5d9193ab22444fb454b7db49347338107f2
6
+ metadata.gz: 5885e9e3df860401c03b9869cd50170682092a1dcbd88d8a74d09015bc860f4f115b52d7489a6e5c699b6e48c027d4ea6be63cfbccc14aa8f14f5c2554b54353
7
+ data.tar.gz: 6cd3fdae68d50111ffa742f78048d3999db816b2fd1d70f04c06b971c64035cddf07168a11a794c1dfc27fca7f3aa8db3e00a0eb6da0e7b951beb8f603fa2272
@@ -8,6 +8,8 @@ notifications:
8
8
  email:
9
9
  on_success: change
10
10
  on_failure: always
11
+ before_install:
12
+ - gem install bundler -v '< 2'
11
13
  before_script:
12
14
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
15
  - chmod +x ./cc-test-reporter
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.18)
4
+ fa_rails (0.1.23)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,7 +9,7 @@ GEM
9
9
  diff-lcs (1.3)
10
10
  docile (1.3.1)
11
11
  json (2.1.0)
12
- rake (12.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
 
@@ -90,6 +102,7 @@ options #=> Hash
90
102
  size: Integer # Stepped scaling factor
91
103
 
92
104
  css: String # Arbitrary CSS classes, space-delimited
105
+ raw_css: Hash # Arbitrary raw CSS, as a hash of attributes and values
93
106
  fa: String # Arbitrary FA classes, space-delimited – each is automatically prefixed with `fa-`
94
107
  title: String #=> Tooltip text
95
108
  grow: Integer #=> Transform value – amount to grow by
@@ -114,6 +127,7 @@ options #=> Hash
114
127
  position: Symbol # Indicator of which corner to display on – one of [:tr, :tl, :br, :bl]
115
128
 
116
129
  css: String # Arbitrary CSS classes, space-delimited
130
+ raw_css: Hash # Arbitrary raw CSS, as a hash of attributes and values
117
131
  fa: String # Arbitrary FA classes, space-delimited – each is automatically prefixed with `fa-`
118
132
  title: String #=> Tooltip text
119
133
  grow: Integer #=> Transform value – amount to grow by
@@ -143,24 +157,39 @@ css #=> String – arbitrary CSS classes, space-delimited, applied to the layer
143
157
  ```ruby
144
158
  # Fixed-width lock icon
145
159
  FA::Icon.p('lock', fa: 'fw')
146
- #=> "<i class='fas fa-fw fa-lock fa-1x' data-fa-transform='' title=''></i>"
160
+ #=> "<i class='fas fa-fw fa-lock fa-1x' style='' data-fa-transform='' title=''></i>"
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
+
166
+ # Duotone fire-alt icon with specified opacities
167
+ FA::Icon.p('fire-alt', style: :duotone, raw_css: { '--fa-primary-opacity' => '0.6', '--fa-secondary-opacity' => '0.4' })
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>"
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>"
147
176
 
148
177
  # Counter span, with value 5
149
178
  FA::Span.p('counter', 5)
150
- #=> "<span class='fa-layers-counter ' data-fa-transform=''>5</span>"
179
+ #=> "<span class='fa-layers-counter ' style='' data-fa-transform=''>5</span>"
151
180
 
152
181
  # Gray envelope icon with red exclamation mark overlayed, with tooltip 'Invalid email address'
153
182
  FA::Layer.p([{ name: 'envelope', options: { css: :gray } }, { name: 'exclamation', options: { css: :red } }], title: 'Invalid email address')
154
183
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title='Invalid email address'>" \
155
- # "<i class='fas fa-stack-1x gray fa-envelope fa-1x' data-fa-transform='grow-0' title='Invalid email address'></i>" \
156
- # "<i class='fas fa-stack-1x red fa-exclamation fa-1x' data-fa-transform='grow-0' title='Invalid email address'></i>" \
184
+ # "<i class='fas fa-stack-1x gray fa-envelope fa-1x' style='' data-fa-transform='grow-0' title='Invalid email address'></i>" \
185
+ # "<i class='fas fa-stack-1x red fa-exclamation fa-1x' style='' data-fa-transform='grow-0' title='Invalid email address'></i>" \
157
186
  # "</span>"
158
187
 
159
188
  # Blue envelope with red counter on the top left corner, with value 7
160
189
  FA::Layer.p([{ name: 'envelope', options: { css: :blue } }, { name: 'counter', text: 7, options: { css: :red, position: :tl } }])
161
190
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
162
- # "<i class='fas fa-stack-1x blue fa-envelope fa-1x' data-fa-transform='grow-0' title=''></i>" \
163
- # "<span class='fa-stack-1x red fa-layers-counter fa-layers-top-left' data-fa-transform='grow-0'>7</span>" \
191
+ # "<i class='fas fa-stack-1x blue fa-envelope fa-1x' style='' data-fa-transform='grow-0' title=''></i>" \
192
+ # "<span class='fa-stack-1x red fa-layers-counter fa-layers-top-left' style='' data-fa-transform='grow-0'>7</span>" \
164
193
  # "</span>"
165
194
 
166
195
  # The same stack, but using the FA::Build DSL (with various syntaxes).
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fa_rails'
3
- s.version = '0.1.18'
4
- s.date = '2019-07-29'
3
+ s.version = '0.1.23'
4
+ s.date = '2020-06-18'
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'
@@ -3,14 +3,18 @@
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', duotone: 'd', brands: 'b'
8
+ }.freeze
9
+
6
10
  # Outputs the formatted string directly.
7
11
  def raw
8
12
  #
9
13
  end
10
14
 
11
15
  # Attempts to call `.html_safe` on the the output of `raw`, if available.
12
- def safe
13
- output = raw
16
+ def safe(html = nil)
17
+ output = html || raw
14
18
  output.respond_to?(:html_safe) ? output.html_safe : output
15
19
  end
16
20
 
@@ -43,7 +47,7 @@ module FA
43
47
  css = @classes.flatten.join(' ')
44
48
  transforms = @transforms.join(' ')
45
49
 
46
- "<i class='#{css}' data-fa-transform='#{transforms}' " \
50
+ "<i class='#{css}' style='#{@styles}' data-fa-transform='#{transforms}' " \
47
51
  "title='#{options[:title]}'></i>"
48
52
  end
49
53
 
@@ -59,11 +63,11 @@ module FA
59
63
  css = @classes.flatten.reject { |c| c.to_s.match?(/^fa.$/) }.join(' ')
60
64
  transforms = @transforms.join(' ')
61
65
 
62
- "<span class='#{css}' data-fa-transform='#{transforms}'>#{text}</span>"
66
+ "<span class='#{css}' style='#{@styles}' data-fa-transform='#{transforms}'>#{text}</span>"
63
67
  end
64
68
 
65
69
  def fa_options(options)
66
- default = { style: :solid, css: '', fa: '', size: 1 }
70
+ default = { style: :solid, css: '', raw_css: {}, fa: '', size: 1 }
67
71
 
68
72
  default.merge(options.to_h)
69
73
  end
@@ -93,6 +97,8 @@ module FA
93
97
 
94
98
  def parse_options(options)
95
99
  parse_classes(options)
100
+ options = merge_fa_styles(options)
101
+ parse_styles(options)
96
102
  parse_transforms(options)
97
103
  end
98
104
 
@@ -103,6 +109,21 @@ module FA
103
109
  @classes << options[:css].to_s.split(' ')
104
110
  end
105
111
 
112
+ def merge_fa_styles(options)
113
+ fa_styles = options.delete(:fa_styles)
114
+ return options unless fa_styles
115
+
116
+ fa_styles = fa_styles.each_with_object({}) do |(k, v), hash|
117
+ hash["--fa-#{k.to_s.tr('_', '-')}"] = v.to_s
118
+ end
119
+ options[:raw_css] = options[:raw_css].merge(fa_styles)
120
+ options
121
+ end
122
+
123
+ def parse_styles(options)
124
+ @styles = options[:raw_css].map { |k, v| "#{k}: #{v};" }.join(' ')
125
+ end
126
+
106
127
  def parse_transforms(options)
107
128
  @transforms = []
108
129
  %i[grow shrink rotate up down left right].each do |transform|
@@ -113,10 +134,10 @@ module FA
113
134
  end
114
135
 
115
136
  def parse_style(options)
116
- return if options[:css].to_s.match?(/fa[srlb]/)
117
- return 'fas' unless %i[solid regular light brands].include?(options[:style])
137
+ return if options[:css].to_s.match?(/fa[srldb]/)
138
+ return 'fas' unless STYLES.keys.include?(options[:style])
118
139
 
119
- 'fa' + { solid: 's', regular: 'r', light: 'l', brands: 'b' }[options[:style]]
140
+ 'fa' + STYLES[options[:style]]
120
141
  end
121
142
  end
122
143
  end
@@ -26,6 +26,11 @@ module FA
26
26
  "<script src=\"https://kit.fontawesome.com/#{@kit}.js\"></script>"
27
27
  end
28
28
 
29
+ def self.kit(kit_id)
30
+ k = new(kit: kit_id)
31
+ k.safe(k.kit)
32
+ end
33
+
29
34
  private
30
35
 
31
36
  def url
@@ -14,8 +14,8 @@ RSpec.describe FA do
14
14
  end
15
15
 
16
16
  it 'should generate the correct kit link tag' do
17
- tag = FA::Link.new(kit: 'abcdefg', pro: true)
18
- expect(tag.kit).to eql(
17
+ tag = FA::Link.kit('abcdefg')
18
+ expect(tag).to eql(
19
19
  "<script src=\"https://kit.fontawesome.com/abcdefg.js\"></script>"
20
20
  )
21
21
  end
@@ -28,20 +28,22 @@ 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
- "<i class='fas fa-help fa-1x' data-fa-transform='' title=''></i>"
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
- "<i class='fas fa-help fa-1x' data-fa-transform='' title=''></i>"
39
+ "<i class='fas fa-help fa-1x' style='' data-fa-transform='' title=''></i>"
38
40
  )
39
41
  end
40
42
 
41
43
  it 'should generate the correct icon from a configuration hash' do
42
44
  fa = { name: 'help', options: { style: :light, size: 2 } }
43
45
  expect(FA::Icon.p(fa)).to eql(
44
- "<i class='fal fa-help fa-2x' data-fa-transform='' title=''></i>"
46
+ "<i class='fal fa-help fa-2x' style='' data-fa-transform='' title=''></i>"
45
47
  )
46
48
  end
47
49
 
@@ -55,7 +57,20 @@ RSpec.describe FA do
55
57
 
56
58
  it 'should generate the correct brand icon' do
57
59
  expect(FA::Icon.p(:github, style: :brands)).to eql(
58
- "<i class='fab fa-github fa-1x' data-fa-transform='' title=''></i>"
60
+ "<i class='fab fa-github fa-1x' style='' data-fa-transform='' title=''></i>"
61
+ )
62
+ end
63
+
64
+ it 'should generate the correct icon with styles' do
65
+ expect(
66
+ FA::Icon.p(
67
+ 'fire-alt', style: :duotone, fa_styles: {
68
+ primary_opacity: '0.6', secondary_opacity: '0.4', primary_color: :green, secondary_color: '#DD2200'
69
+ }
70
+ )
71
+ ).to eql(
72
+ "<i class='fad fa-fire-alt fa-1x' style='--fa-primary-opacity: 0.6; --fa-secondary-opacity: 0.4; " \
73
+ "--fa-primary-color: green; --fa-secondary-color: #DD2200;' data-fa-transform='' title=''></i>"
59
74
  )
60
75
  end
61
76
  end
@@ -70,9 +85,9 @@ RSpec.describe FA do
70
85
 
71
86
  expect(FA::Layer.p(icons, grow: 2)).to eql(
72
87
  "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
73
- "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-2' title=''></i>" \
74
- "<i class='fas fa-stack-1x fa-circle fa-1x' data-fa-transform='grow-3' title=''></i>" \
75
- "<i class='far fa-stack-1x fa-exclamation fa-1x' data-fa-transform='grow-2' title=''></i>" \
88
+ "<i class='fas fa-stack-1x fa-square fa-1x' style='' data-fa-transform='grow-2' title=''></i>" \
89
+ "<i class='fas fa-stack-1x fa-circle fa-1x' style='' data-fa-transform='grow-3' title=''></i>" \
90
+ "<i class='far fa-stack-1x fa-exclamation fa-1x' style='' data-fa-transform='grow-2' title=''></i>" \
76
91
  '</span>'
77
92
  )
78
93
  end
@@ -85,8 +100,8 @@ RSpec.describe FA do
85
100
 
86
101
  expect(FA::Layer.p(icons)).to eql(
87
102
  "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
88
- "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-0' title=''></i>" \
89
- "<span class='fa-stack-1x fa-layers-counter fa-layers-top-left' data-fa-transform='grow-0'>17</span>" \
103
+ "<i class='fas fa-stack-1x fa-square fa-1x' style='' data-fa-transform='grow-0' title=''></i>" \
104
+ "<span class='fa-stack-1x fa-layers-counter fa-layers-top-left' style='' data-fa-transform='grow-0'>17</span>" \
90
105
  '</span>'
91
106
  )
92
107
  end
@@ -99,8 +114,8 @@ RSpec.describe FA do
99
114
 
100
115
  expect(FA::Layer.p(icons, title: 'right')).to eql(
101
116
  "<span class='icon fa-layers fa-stack fa-fw ' title='right'>" \
102
- "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-0' title='right'></i>" \
103
- "<i class='fas fa-stack-1x fa-exclamation fa-1x' data-fa-transform='grow-0' title='right'></i>" \
117
+ "<i class='fas fa-stack-1x fa-square fa-1x' style='' data-fa-transform='grow-0' title='right'></i>" \
118
+ "<i class='fas fa-stack-1x fa-exclamation fa-1x' style='' data-fa-transform='grow-0' title='right'></i>" \
104
119
  '</span>'
105
120
  )
106
121
  end
@@ -115,8 +130,8 @@ RSpec.describe FA do
115
130
 
116
131
  expect(layer).to eql(
117
132
  "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
118
- "<i class='fas fa-stack-1x fa-circle fa-1x' data-fa-transform='grow-0' title=''></i>" \
119
- "<span class='fa-stack-1x fa-layers-counter ' data-fa-transform='grow-0'>7</span>" \
133
+ "<i class='fas fa-stack-1x fa-circle fa-1x' style='' data-fa-transform='grow-0' title=''></i>" \
134
+ "<span class='fa-stack-1x fa-layers-counter ' style='' data-fa-transform='grow-0'>7</span>" \
120
135
  '</span>'
121
136
  )
122
137
  end
@@ -125,7 +140,7 @@ RSpec.describe FA do
125
140
  describe 'span' do
126
141
  it 'should generate the correct span from a string or symbol type' do
127
142
  expect(FA::Span.p(:text, 'Hello')).to eql(
128
- "<span class='fa-layers-text ' data-fa-transform=''>Hello</span>"
143
+ "<span class='fa-layers-text ' style='' data-fa-transform=''>Hello</span>"
129
144
  )
130
145
  end
131
146
 
@@ -133,7 +148,7 @@ RSpec.describe FA do
133
148
  span = { type: :text, text: 'World', options: { position: :bl } }
134
149
  expect(FA::Span.p(span)).to eql(
135
150
  "<span class='fa-layers-text fa-layers-bottom-left' " \
136
- "data-fa-transform=''>World</span>"
151
+ "style='' data-fa-transform=''>World</span>"
137
152
  )
138
153
  end
139
154
 
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.18
4
+ version: 0.1.23
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-07-29 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake