fa_rails 0.1.21 → 0.1.22

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: 626bd595bc9a79f241571cc01ea6c2b17f926f4a98b37678f2ab0f78046de28d
4
+ data.tar.gz: 9b2374e43b36b5f304496de28e2a876014875e5d1615e20a1d853fe8fe271e8b
5
5
  SHA512:
6
- metadata.gz: 7f5b7a3d34e521837f5576c4a4da657c6e7d91fb30a131a32427f1750ffd183ab0281c1f11209c370ad96a11810f1e3a0b5381a947b6a126288aaa17e0652127
7
- data.tar.gz: c6bfde33dce0ae1403553ca8ff1e36943e203ba6819010b9845b442e0ae46a242c16c63c424c121475af3fa6652f687dcec671150c4bff55613ac491cdeec7fc
6
+ metadata.gz: 9a20e551e982f87d8e3c81df3a4dbd5d15e3933ecebcef9b62978a0174879a389379189f93ed4a985672de8ebbab15fbb124f4c074a914dcb1da9ac1cab30d1f
7
+ data.tar.gz: 685fb1c6945497270fd48526f8d481bad0b48cf1f408164fabe2a3f23b51827448fb68be0dca9c496a440bbe6cdbe8b108f45f40b4f1fa08cc53b39d9b9a2e16
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.21)
4
+ fa_rails (0.1.22)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -151,6 +151,13 @@ FA::Icon.p('lock', fa: 'fw')
151
151
  FA::Icon.p('fire-alt', style: :duotone, raw_css: { '--fa-primary-opacity' => '0.6', '--fa-secondary-opacity' => '0.4' })
152
152
  #=> "<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
153
 
154
+ # You can also use this simplified configuration option for adding styles
155
+ # This is reforatted and merged into :raw_css
156
+ # Accepts either snake_case symbols or spear-case strings as keys, and strings or symbols as values
157
+ # This is the easiest way to add primary/secondary styles for duotone icons
158
+ FA::Icon.p('fire-alt', style: :duotone, fa_styles: { primary_opacity: '0.6', secondary_opacity: '0.4', primary_color: :green, secondary_color: '#DD2200' })
159
+ #=> "<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>"
160
+
154
161
  # Counter span, with value 5
155
162
  FA::Span.p('counter', 5)
156
163
  #=> "<span class='fa-layers-counter ' style='' data-fa-transform=''>5</span>"
data/fa_rails.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fa_rails'
3
- s.version = '0.1.21'
3
+ s.version = '0.1.22'
4
4
  s.date = '2019-08-09'
5
5
  s.summary = 'FontAwesome helper for Rails'
6
6
  s.description = 'A helper module for using FontAwesome icons in Rails.'
data/lib/fa/base.rb CHANGED
@@ -93,6 +93,7 @@ module FA
93
93
 
94
94
  def parse_options(options)
95
95
  parse_classes(options)
96
+ options = merge_fa_styles(options)
96
97
  parse_styles(options)
97
98
  parse_transforms(options)
98
99
  end
@@ -104,6 +105,17 @@ module FA
104
105
  @classes << options[:css].to_s.split(' ')
105
106
  end
106
107
 
108
+ def merge_fa_styles(options)
109
+ fa_styles = options.delete(:fa_styles)
110
+ return options unless fa_styles
111
+
112
+ fa_styles = fa_styles.each_with_object({}) do |(k, v), hash|
113
+ hash["--fa-#{k.to_s.tr('_', '-')}"] = v.to_s
114
+ end
115
+ options[:raw_css] = options[:raw_css].merge(fa_styles)
116
+ options
117
+ end
118
+
107
119
  def parse_styles(options)
108
120
  @styles = options[:raw_css].map { |k, v| "#{k}: #{v};" }.join(' ')
109
121
  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
  )
@@ -58,6 +60,19 @@ RSpec.describe FA do
58
60
  "<i class='fab fa-github fa-1x' style='' data-fa-transform='' title=''></i>"
59
61
  )
60
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>"
74
+ )
75
+ end
61
76
  end
62
77
 
63
78
  describe 'layer' do
metadata CHANGED
@@ -1,7 +1,7 @@
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.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander