fa_rails 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 0dbacdc4e0a4e68f79cfc68e8bb41711e43300e3
4
- data.tar.gz: fec55616a7eaaa224bab094b25268b47d6b025be
3
+ metadata.gz: 426ebafa62f8215649caebd5b5a032a8e6811edb
4
+ data.tar.gz: 78512e22aa49f1869bae9b3772b1b27680c4663d
5
5
  SHA512:
6
- metadata.gz: dd4692e88c2772c21655bd288302fa24f7e0dc89ed2e8ec25b0ba1c69085569ef657f563f498ad8ce18065f404b9a577047fd2c4f2603f724d2dbb9d4443d400
7
- data.tar.gz: 25a690db403ab8e3006eca15d0bbc585a92b092a70db0293dc2ee43e6a03debdc8b980661ad8858598cbdac9fe78ffda9802f554b440d50cc1749a48e33354d0
6
+ metadata.gz: c51c668fbe28857e2e6f4fd4c9b1bbffa3844b0072109f66d71dfbcf6edbc1e433c84fe40cacff2c5e2f4cd4919c2771f33de261051daa58758dc43b5355be67
7
+ data.tar.gz: 51980ca1a7a4be0e919c1d38eae5989bc33c0a2b394cc8b6fef765ac1d7f23a11019a3678a159744ce1c6508d294b652691bd6789a94afbd2969b006b42336c5
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.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2018-07-27'
5
5
  s.summary = 'FontAwesome helper for Rails'
6
6
  s.description = 'A helper module for using FontAwesome icons in Rails.'
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
- module FontAwesomeHelper
5
- # html_safe: No user content
6
- def fa_layer(icons = {}, title: nil, grow: 0, css: '')
7
- # Add icons to the stack bottom to top
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
- output = span_top + parse_all(icons).join + span_bottom
17
- safe_output(output)
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 fa_span(fa, text = '', options = {})
33
- if fa.is_a?(Hash)
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
- require 'font_awesome_helper'
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(fa_icon('help')).to eql(
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(fa_icon(:help)).to eql(
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(fa_icon(fa)).to eql(
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 { fa_icon(fa) }.to raise_error(
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(fa_icon(:github, style: :brands)).to eql(
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(fa_layer(icons, grow: 2)).to eql(
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(fa_layer(icons)).to eql(
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(fa_span(:text, 'Hello')).to eql(
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(fa_span(span)).to eql(
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 { fa_span(fa) }.to raise_error(
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
@@ -3,6 +3,8 @@ Bundler.setup
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
+ require 'fa'
7
+
6
8
  RSpec.configure do |config|
7
9
  #
8
10
  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.0
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/font_awesome_helper.rb
106
- - spec/helpers/font_awesome_helper_spec.rb
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/font_awesome_helper_spec.rb
138
+ - spec/helpers/fa_spec.rb
136
139
  - spec/spec_helper.rb