fa_rails 0.1.13 → 0.1.14

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
  SHA1:
3
- metadata.gz: c3968254b8c159868cfb8ea652f34eff2326c36f
4
- data.tar.gz: 11acb7f382f5aad18ad03b34bb927fc3eaeb1cfa
3
+ metadata.gz: bedbb3b52f82b24d5ef7d78088141fcf16710258
4
+ data.tar.gz: aad0ad0db36223df9317c8fe54d0a61a879a5ba1
5
5
  SHA512:
6
- metadata.gz: 122bb5a2e2f171f2208a04015defbce07e7865aef2a4c286c0a79e6ed1b4a163097289bb75b3bda665110ef8f40fea0e7ef96d06650e5643eed6c497fd03fc9f
7
- data.tar.gz: f83c382aaff389202657466094af61f4e479539797a47e96dcc9e29b9dfb4dc66a4667989d0b6e0c0468b5618c086a37585e39c6c1204b8cfc88338f3874b752
6
+ metadata.gz: 2ac8ff919be13408c0c1093bfc260eb6eb86b532b90236c5e7cf4234eb1b35ab1764a903641f256ac0dbe2d228918d2bf155eb5c22d6e02f9d197342bb09e777
7
+ data.tar.gz: dff2c8aa2b9ea64e4924d241ff4fd0922bf52747fd63a37b223765b97e0917d3c14b9891a3590c3977a5537c6d11285f238ed202c2efa3af8a086b641b32e0a8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.13)
4
+ fa_rails (0.1.14)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -67,6 +67,9 @@ All three classes respond to two output methods: `raw` and `safe`.
67
67
  - `raw` outputs the formatted string directly
68
68
  - `safe` attempts to call `.html_safe` on the formatted string, if available
69
69
 
70
+ For convenience, each class also has a `p` method, which will create a new
71
+ instance, and return its `safe` output.
72
+
70
73
  ### Icon
71
74
 
72
75
  A single FontAwesome icon.
@@ -132,22 +135,22 @@ css # String – arbitrary CSS classes, space-delimited, applied to the layer st
132
135
 
133
136
  ```ruby
134
137
  # Fixed-width lock icon
135
- FA::Icon.new('lock', fa: 'fw').safe
138
+ FA::Icon.p('lock', fa: 'fw')
136
139
  #=> "<i class='fas fa-fw fa-lock' data-fa-transform='' title=''></i>"
137
140
 
138
141
  # Counter span, with value 5
139
- FA::Span.new('counter', 5).safe
142
+ FA::Span.p('counter', 5)
140
143
  #=> "<span class='fa-layers-counter ' data-fa-transform=''>5</span>
141
144
 
142
145
  # Gray envelope icon with red exclamation mark overlayed, with tooltip 'Invalid email address'
143
- FA::Layer.new([{ name: 'envelope', options: { css: :gray } }, { name: 'exclamation', options: { css: :red } }], title: 'Invalid email address').safe
146
+ FA::Layer.p([{ name: 'envelope', options: { css: :gray } }, { name: 'exclamation', options: { css: :red } }], title: 'Invalid email address')
144
147
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title='Invalid email address'>" \
145
148
  # "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
146
149
  # "<i class='fas red fa-exclamation' data-fa-transform='grow-0' title=''></i>" \
147
150
  # "</span>"
148
151
 
149
152
  # Blue envelope with red counter on the top left corner, with value 7
150
- FA::Layer.new([{ name: 'envelope', options: { css: :blue } }, { name: 'counter', text: 7, options: { css: :red, position: :tl } }]).safe
153
+ FA::Layer.p([{ name: 'envelope', options: { css: :blue } }, { name: 'counter', text: 7, options: { css: :red, position: :tl } }])
151
154
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
152
155
  # "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
153
156
  # "<span class='red fa-layers-counter ' data-fa-transform='grow-0'>7" \
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.13'
3
+ s.version = '0.1.14'
4
4
  s.date = '2018-07-30'
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
@@ -14,6 +14,11 @@ module FA
14
14
  output.respond_to?(:html_safe) ? output.html_safe : output
15
15
  end
16
16
 
17
+ # Shortcut for create and output safe
18
+ def self.p(*args)
19
+ new(*args).safe
20
+ end
21
+
17
22
  private
18
23
 
19
24
  def parse_all(icons)
data/spec/lib/fa_spec.rb CHANGED
@@ -14,32 +14,32 @@ RSpec.describe FA do
14
14
 
15
15
  describe 'icon' do
16
16
  it 'should generate the correct icon from a string or symbol name' do
17
- expect(FA::Icon.new('help').safe).to eql(
17
+ expect(FA::Icon.p('help')).to eql(
18
18
  "<i class='fas fa-help fa-1x' data-fa-transform='' title=''></i>"
19
19
  )
20
20
 
21
- expect(FA::Icon.new(:help).safe).to eql(
21
+ expect(FA::Icon.p(:help)).to eql(
22
22
  "<i class='fas fa-help fa-1x' data-fa-transform='' title=''></i>"
23
23
  )
24
24
  end
25
25
 
26
26
  it 'should generate the correct icon from a configuration hash' do
27
27
  fa = { name: 'help', options: { style: :light, size: 2 } }
28
- expect(FA::Icon.new(fa).safe).to eql(
28
+ expect(FA::Icon.p(fa)).to eql(
29
29
  "<i class='fal fa-help fa-2x' data-fa-transform='' title=''></i>"
30
30
  )
31
31
  end
32
32
 
33
33
  it 'should raise ArgumentError for other input types' do
34
34
  [nil, [], 0].each do |fa|
35
- expect { FA::Icon.new(fa).safe }.to raise_error(
35
+ expect { FA::Icon.p(fa) }.to raise_error(
36
36
  ArgumentError, 'Unexpected argument type.'
37
37
  )
38
38
  end
39
39
  end
40
40
 
41
41
  it 'should generate the correct brand icon' do
42
- expect(FA::Icon.new(:github, style: :brands).safe).to eql(
42
+ expect(FA::Icon.p(:github, style: :brands)).to eql(
43
43
  "<i class='fab fa-github fa-1x' data-fa-transform='' title=''></i>"
44
44
  )
45
45
  end
@@ -53,7 +53,7 @@ RSpec.describe FA do
53
53
  { name: 'exclamation', options: { style: :regular } }
54
54
  ]
55
55
 
56
- expect(FA::Layer.new(icons, grow: 2).safe).to eql(
56
+ expect(FA::Layer.p(icons, grow: 2)).to eql(
57
57
  "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
58
58
  "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-2' title=''></i>" \
59
59
  "<i class='fas fa-stack-1x fa-circle fa-1x' data-fa-transform='grow-3' title=''></i>" \
@@ -68,7 +68,7 @@ RSpec.describe FA do
68
68
  { name: :counter, text: 17, options: { position: :tl } }
69
69
  ]
70
70
 
71
- expect(FA::Layer.new(icons).safe).to eql(
71
+ expect(FA::Layer.p(icons)).to eql(
72
72
  "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
73
73
  "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-0' title=''></i>" \
74
74
  "<span class='fa-stack-1x fa-layers-counter fa-layers-top-left' data-fa-transform='grow-0'>17</span>" \
@@ -82,7 +82,7 @@ RSpec.describe FA do
82
82
  { name: :exclamation, title: 'wrong 2' }
83
83
  ]
84
84
 
85
- expect(FA::Layer.new(icons, title: 'right').safe).to eql(
85
+ expect(FA::Layer.p(icons, title: 'right')).to eql(
86
86
  "<span class='icon fa-layers fa-stack fa-fw ' title='right'>" \
87
87
  "<i class='fas fa-stack-1x fa-square fa-1x' data-fa-transform='grow-0' title='right'></i>" \
88
88
  "<i class='fas fa-stack-1x fa-exclamation fa-1x' data-fa-transform='grow-0' title='right'></i>" \
@@ -93,14 +93,14 @@ RSpec.describe FA do
93
93
 
94
94
  describe 'span' do
95
95
  it 'should generate the correct span from a string or symbol type' do
96
- expect(FA::Span.new(:text, 'Hello').safe).to eql(
96
+ expect(FA::Span.p(:text, 'Hello')).to eql(
97
97
  "<span class='fa-layers-text ' data-fa-transform=''>Hello</span>"
98
98
  )
99
99
  end
100
100
 
101
101
  it 'should generate the correct span from a configuration hash' do
102
102
  span = { type: :text, text: 'World', options: { position: :bl } }
103
- expect(FA::Span.new(span).safe).to eql(
103
+ expect(FA::Span.p(span)).to eql(
104
104
  "<span class='fa-layers-text fa-layers-bottom-left' " \
105
105
  "data-fa-transform=''>World</span>"
106
106
  )
@@ -108,7 +108,7 @@ RSpec.describe FA do
108
108
 
109
109
  it 'should raise ArgumentError for other input types' do
110
110
  [nil, [], 0].each do |fa|
111
- expect { FA::Span.new(fa).safe }.to raise_error(
111
+ expect { FA::Span.p(fa) }.to raise_error(
112
112
  ArgumentError, 'Unexpected argument type.'
113
113
  )
114
114
  end
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.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander