fa_rails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fa_rails.gemspec +1 -1
- data/lib/fa/icon.rb +19 -0
- data/lib/fa/layer.rb +20 -0
- data/lib/fa/span.rb +20 -0
- data/lib/{font_awesome_helper.rb → fa.rb} +9 -36
- data/spec/helpers/{font_awesome_helper_spec.rb → fa_spec.rb} +11 -15
- data/spec/spec_helper.rb +2 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 426ebafa62f8215649caebd5b5a032a8e6811edb
|
4
|
+
data.tar.gz: 78512e22aa49f1869bae9b3772b1b27680c4663d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51c668fbe28857e2e6f4fd4c9b1bbffa3844b0072109f66d71dfbcf6edbc1e433c84fe40cacff2c5e2f4cd4919c2771f33de261051daa58758dc43b5355be67
|
7
|
+
data.tar.gz: 51980ca1a7a4be0e919c1d38eae5989bc33c0a2b394cc8b6fef765ac1d7f23a11019a3678a159744ce1c6508d294b652691bd6789a94afbd2969b006b42336c5
|
data/fa_rails.gemspec
CHANGED
data/lib/fa/icon.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FA::Icon < FA
|
4
|
+
def initialize(fa, options = {})
|
5
|
+
@options = options
|
6
|
+
if fa.is_a?(Hash)
|
7
|
+
@name = fa[:name]
|
8
|
+
@options = fa[:options]
|
9
|
+
elsif fa.is_a?(String) || fa.is_a?(Symbol)
|
10
|
+
@name = fa.to_s
|
11
|
+
else
|
12
|
+
raise ArgumentError, 'Unexpected argument type.'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def raw
|
17
|
+
parse_icon(@name, @options)
|
18
|
+
end
|
19
|
+
end
|
data/lib/fa/layer.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FA::Layer < FA
|
4
|
+
def initialize(icons = {}, title: nil, grow: 0, css: '')
|
5
|
+
# Add icons to the stack bottom to top
|
6
|
+
#
|
7
|
+
# Note: scaling ounters does not work well with :grow, so should use the
|
8
|
+
# older "fa-3x" syntax in :css instead.
|
9
|
+
span_top = "<span class='icon fa-layers fa-fw #{css}' title='#{title}'>"
|
10
|
+
span_bottom = '</span>'
|
11
|
+
|
12
|
+
icons.each { |i| i[:options] = combine_options(i, combine_grows(i, grow)) }
|
13
|
+
|
14
|
+
@output = span_top + parse_all(icons).join + span_bottom
|
15
|
+
end
|
16
|
+
|
17
|
+
def raw
|
18
|
+
@output
|
19
|
+
end
|
20
|
+
end
|
data/lib/fa/span.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FA::Span < FA
|
4
|
+
def initialize(fa, text = '', options = {})
|
5
|
+
@options = options
|
6
|
+
if fa.is_a?(Hash)
|
7
|
+
@type = fa[:type].to_sym
|
8
|
+
@text = fa[:text]
|
9
|
+
@options = fa[:options]
|
10
|
+
elsif fa.is_a?(String) || fa.is_a?(Symbol)
|
11
|
+
@type = fa.to_s
|
12
|
+
else
|
13
|
+
raise ArgumentError, 'Unexpected argument type.'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def raw
|
18
|
+
parse_span(@type, @text, @options)
|
19
|
+
end
|
20
|
+
end
|
@@ -1,50 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# FontAwesome 5 (Pro) Helper
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
# Note: scaling ounters does not work well with :grow, so should use the
|
10
|
-
# older "fa-3x" syntax in :css instead.
|
11
|
-
span_top = "<span class='icon fa-layers fa-fw #{css}' title='#{title}'>"
|
12
|
-
span_bottom = '</span>'
|
13
|
-
|
14
|
-
icons.each { |i| i[:options] = combine_options(i, combine_grows(i, grow)) }
|
4
|
+
class FA
|
5
|
+
require 'fa/icon'
|
6
|
+
require 'fa/span'
|
7
|
+
require 'fa/layer'
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def fa_icon(fa, options = {})
|
21
|
-
if fa.is_a?(Hash)
|
22
|
-
name = fa[:name]
|
23
|
-
options = fa[:options]
|
24
|
-
elsif fa.is_a?(String) || fa.is_a?(Symbol)
|
25
|
-
name = fa.to_s
|
26
|
-
else
|
27
|
-
raise ArgumentError, 'Unexpected argument type.'
|
28
|
-
end
|
29
|
-
safe_output(parse_icon(name, options))
|
9
|
+
def raw
|
10
|
+
#
|
30
11
|
end
|
31
12
|
|
32
|
-
def
|
33
|
-
|
34
|
-
type = fa[:type].to_sym
|
35
|
-
text = fa[:text]
|
36
|
-
options = fa[:options]
|
37
|
-
elsif fa.is_a?(String) || fa.is_a?(Symbol)
|
38
|
-
type = fa.to_s
|
39
|
-
else
|
40
|
-
raise ArgumentError, 'Unexpected argument type.'
|
41
|
-
end
|
42
|
-
safe_output(parse_span(type, text, options))
|
13
|
+
def safe
|
14
|
+
safe_output(raw)
|
43
15
|
end
|
44
16
|
|
45
17
|
private
|
46
18
|
|
47
19
|
def safe_output(output)
|
20
|
+
# html_safe: No user content
|
48
21
|
output.respond_to?(:html_safe) ? output.html_safe : output
|
49
22
|
end
|
50
23
|
|
@@ -1,38 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe do
|
6
|
-
include FontAwesomeHelper
|
7
|
-
|
3
|
+
RSpec.describe FA do
|
8
4
|
describe 'icon' do
|
9
5
|
it 'should generate the correct icon from a string or symbol name' do
|
10
|
-
expect(
|
6
|
+
expect(FA::Icon.new('help')).to eql(
|
11
7
|
"<i class='fas fa-help' data-fa-transform='' title=''></i>"
|
12
8
|
)
|
13
9
|
|
14
|
-
expect(
|
10
|
+
expect(FA::Icon.new(:help)).to eql(
|
15
11
|
"<i class='fas fa-help' data-fa-transform='' title=''></i>"
|
16
12
|
)
|
17
13
|
end
|
18
14
|
|
19
15
|
it 'should generate the correct icon from a configuration hash' do
|
20
16
|
fa = { name: 'help', options: { style: :light, size: 2 } }
|
21
|
-
expect(
|
17
|
+
expect(FA::Icon.new(fa)).to eql(
|
22
18
|
"<i class='fal fa-help fa-2x' data-fa-transform='' title=''></i>"
|
23
19
|
)
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'should raise ArgumentError for other input types' do
|
27
23
|
[nil, [], 0].each do |fa|
|
28
|
-
expect {
|
24
|
+
expect { FA::Icon.new(fa) }.to raise_error(
|
29
25
|
ArgumentError, 'Unexpected argument type.'
|
30
26
|
)
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
34
30
|
it 'should generate the correct brand icon' do
|
35
|
-
expect(
|
31
|
+
expect(FA::Icon.new(:github, style: :brands)).to eql(
|
36
32
|
"<i class='fab fa-github' data-fa-transform='' title=''></i>"
|
37
33
|
)
|
38
34
|
end
|
@@ -46,7 +42,7 @@ RSpec.describe do
|
|
46
42
|
{ name: 'exclamation', options: { style: :regular } }
|
47
43
|
]
|
48
44
|
|
49
|
-
expect(
|
45
|
+
expect(FA::Layer.new(icons, grow: 2)).to eql(
|
50
46
|
"<span class='icon fa-layers fa-fw ' title=''>" \
|
51
47
|
"<i class='fas fa-square' data-fa-transform='grow-2' title=''></i>" \
|
52
48
|
"<i class='fas fa-circle' data-fa-transform='grow-3' title=''></i>" \
|
@@ -61,7 +57,7 @@ RSpec.describe do
|
|
61
57
|
{ name: :counter, text: 17, options: { position: :tl } }
|
62
58
|
]
|
63
59
|
|
64
|
-
expect(
|
60
|
+
expect(FA::Layer.new(icons)).to eql(
|
65
61
|
"<span class='icon fa-layers fa-fw ' title=''>" \
|
66
62
|
"<i class='fas fa-square' data-fa-transform='grow-0' title=''></i>" \
|
67
63
|
"<span class='fa-layers-counter fa-layers-top-left' " \
|
@@ -72,14 +68,14 @@ RSpec.describe do
|
|
72
68
|
|
73
69
|
describe 'span' do
|
74
70
|
it 'should generate the correct span from a string or symbol type' do
|
75
|
-
expect(
|
71
|
+
expect(FA::Span.new(:text, 'Hello')).to eql(
|
76
72
|
"<span class='fa-layers-text ' data-fa-transform=''>Hello</span>"
|
77
73
|
)
|
78
74
|
end
|
79
75
|
|
80
76
|
it 'should generate the correct span from a configuration hash' do
|
81
77
|
span = { type: :text, text: 'World', options: { position: :bl } }
|
82
|
-
expect(
|
78
|
+
expect(FA::Span.new(span)).to eql(
|
83
79
|
"<span class='fa-layers-text fa-layers-bottom-left' " \
|
84
80
|
"data-fa-transform=''>World</span>"
|
85
81
|
)
|
@@ -87,7 +83,7 @@ RSpec.describe do
|
|
87
83
|
|
88
84
|
it 'should raise ArgumentError for other input types' do
|
89
85
|
[nil, [], 0].each do |fa|
|
90
|
-
expect {
|
86
|
+
expect { FA::Span.new(fa) }.to raise_error(
|
91
87
|
ArgumentError, 'Unexpected argument type.'
|
92
88
|
)
|
93
89
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
@@ -102,8 +102,11 @@ files:
|
|
102
102
|
- README.md
|
103
103
|
- Rakefile
|
104
104
|
- fa_rails.gemspec
|
105
|
-
- lib/
|
106
|
-
-
|
105
|
+
- lib/fa.rb
|
106
|
+
- lib/fa/icon.rb
|
107
|
+
- lib/fa/layer.rb
|
108
|
+
- lib/fa/span.rb
|
109
|
+
- spec/helpers/fa_spec.rb
|
107
110
|
- spec/spec_helper.rb
|
108
111
|
homepage: http://rubygems.org/gems/fa_rails
|
109
112
|
licenses:
|
@@ -132,5 +135,5 @@ signing_key:
|
|
132
135
|
specification_version: 4
|
133
136
|
summary: FontAwesome helper for Rails
|
134
137
|
test_files:
|
135
|
-
- spec/helpers/
|
138
|
+
- spec/helpers/fa_spec.rb
|
136
139
|
- spec/spec_helper.rb
|