font_awesome5_rails 0.2.0 → 0.2.1

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: cc58a58950f15df45b6f0fe9f3f12b12b353af6bc4fe88e35a54a79f5f5c50cc
4
- data.tar.gz: e9982fa1a84e1eebff97deeb5baa15e3eb24de6c1795d57998667bc24c46ed16
3
+ metadata.gz: 99d08e6a633a47779690afed02b22d8865588e75a5cbbb50e797d75fcdd3f0d0
4
+ data.tar.gz: 05bade9ea906385cb1d7ffc05376203f1be69c5a854eedb0aee361bbf90e8ba4
5
5
  SHA512:
6
- metadata.gz: 7b9dfec777ff6afc943e7bc31f68fb38d4c9da6ab7228d205ea0afc0dee358c4757a9f40438dbbba85a9c146aad643bc29ccb79d5b07549300c6bb0f876ec886
7
- data.tar.gz: d23e231f852dc7db99551cb3e34136e409b6054056791748f456ea868b94ae71485e1255414b2b0660127125cf941fc10a09241c50f14f65a242c3ae8efb1637
6
+ metadata.gz: 197ca98e6d4e80b59b6f0228da1f2d03fb019bdef74280c269b9da9e9384b160f8dd6c4b121fabb0fa184507dc921c2e351219278768a34e9af4777a3aa6e142
7
+ data.tar.gz: 4fa1373007e09fad93942bc7fd7a48d488ece24bba69ee5df4cd7e7d3305f5ef624d2d21bad3fdc54d16e505f6d79271d165fa9226421f0feddfdc5864d2b164
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # FontAwesome5Rails
2
+ [![Build Status](https://travis-ci.org/tomkra/font_awesome5_rails.svg?branch=master)](https://travis-ci.org/tomkra/font_awesome5_rails)
3
+ [![HitCount](http://hits.dwyl.io/tomkra/tomkra/font_awesome5_rails.svg)](http://hits.dwyl.io/tomkra/tomkra/font_awesome5_rails)
4
+
2
5
  font_awesome5_rails provides the [Font-Awesome5](https://fontawesome.com/) web fonts, stylesheets and javascripts as a Rails engine for use with the asset pipeline and with backwards compatibility with [font-awesome-rails](https://github.com/bokmann/font-awesome-rails) gem.
3
6
 
4
7
  This gem provides only Free icons from Font-Awesome.
@@ -44,24 +47,27 @@ fa_icon('camera-retro', class: 'my-class', text: 'Camera', size: '3x')
44
47
  In Font Awesome 5 there are several different types of icons. In font_awesome5_rails gem default icon type is ```solid```.
45
48
  If you want to use different icon style you can do this through ```type``` attribute.
46
49
 
47
- | Style | type: |
48
- | ------------- |-------|
49
- | Solid | :fas |
50
- | Regular | :far |
51
- | Light | :fal |
52
- | Brand | :fab |
50
+ | Style | type: | type: |
51
+ | ------------- |-------|--------|
52
+ | Solid | :fas |:solid |
53
+ | Regular | :far |:regular|
54
+ | Light | :fal |:light |
55
+ | Brand | :fab |:brand |
53
56
 
54
57
 
55
58
  ```ruby
56
- fa_icon('camera-retro', type: :fas)
59
+ fa_icon('camera-retro', type: :solid) #Default
57
60
  # => <i class="fas fa-camera-retro"></i>
58
61
 
59
- fa_icon('camera-retro', type: :far)
62
+ fa_icon('camera-retro', type: :regular)
60
63
  # => <i class="far fa-camera-retro"></i>
61
64
 
62
- fa_icon('camera-retro', type: :fal)
65
+ fa_icon('camera-retro', type: :light)
63
66
  # => <i class="fal fa-camera-retro"></i>
64
67
 
68
+ fa_icon('camera-retro', type: :brand)
69
+ # => <i class="fab fa-camera-retro"></i>
70
+
65
71
  fa_icon('camera-retro', type: :fab)
66
72
  # => <i class="fab fa-camera-retro"></i>
67
73
 
@@ -1,21 +1,18 @@
1
+ require 'font_awesome5_rails/fa_icon_parser'
2
+
1
3
  module FontAwesome
2
4
  module Rails
3
5
  module IconHelper
4
6
 
5
7
  def fa_icon(icon, options = {})
6
- classes = [options[:type].nil? ? "fas" : options[:type].to_s]
7
- classes << "fa-#{icon}"
8
- classes += options[:class].split(" ") unless options[:class].nil?
9
- classes += options[:size].split(" ").map{|s| "fa-#{s}"} unless options[:size].nil?
10
- classes += options[:animation].split(" ").map{|s| "fa-#{s}"} unless options[:animation].nil?
11
- classes = classes.uniq.join(" ")
8
+ parser = FaIconParser.new(icon, options)
12
9
  tags = []
13
- if options[:text].nil?
14
- tags << content_tag(:i, nil, class: classes, style: options[:style], data: options[:data])
10
+ if parser.text.nil?
11
+ tags << content_tag(:i, nil, class: parser.classes, style: parser.style, data: parser.data)
15
12
  else
16
13
  content_tag :span do
17
- tags << content_tag(:i, nil, class: classes, style: options[:style], data: options[:data])
18
- tags << content_tag(:span, options[:text], style: "padding-left: 5px;#{options[:style]}")
14
+ tags << content_tag(:i, nil, class: parser.classes, style: parser.style, data: parser.data)
15
+ tags << content_tag(:span, parser.text, style: "padding-left: 5px;#{parser.style}")
19
16
  end
20
17
  end
21
18
  tags.join.html_safe
@@ -0,0 +1,49 @@
1
+ class FaIconParser
2
+ attr_reader :icon, :options, :data, :style, :text
3
+
4
+ def initialize(icon, options)
5
+ @icon = icon
6
+ @options = options
7
+ @data = options[:data]
8
+ @style = options[:style]
9
+ @text = options[:text]
10
+ end
11
+
12
+ def classes
13
+ @classes ||= get_all_classes
14
+ end
15
+
16
+ def icon_type(type)
17
+ return "fas" if type.nil?
18
+ case type.to_s
19
+ when "far", "regular"
20
+ "far"
21
+ when "fal", "light"
22
+ "fal"
23
+ when "fab", "brand"
24
+ "fab"
25
+ else
26
+ "fas"
27
+ end
28
+ end
29
+
30
+ def prepend_fa(string)
31
+ "fa-#{string}"
32
+ end
33
+
34
+ def arr_with_fa(array)
35
+ array.split(" ").map{ |s| prepend_fa(s) }
36
+ end
37
+
38
+ private
39
+
40
+ def get_all_classes
41
+ tmp = []
42
+ tmp << icon_type(@options[:type])
43
+ tmp << prepend_fa(@icon)
44
+ tmp += @options[:class].split(" ") unless @options[:class].nil?
45
+ tmp += arr_with_fa(@options[:size]) unless @options[:size].nil?
46
+ tmp += arr_with_fa(@options[:animation]) unless @options[:animation].nil?
47
+ tmp.uniq.join(" ")
48
+ end
49
+ end
@@ -1,4 +1,4 @@
1
1
  module FontAwesome5Rails
2
2
  FA_VERSION = '5.0.7'
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
@@ -4,6 +4,29 @@ describe FontAwesome5Rails do
4
4
  include RSpecHtmlMatchers
5
5
  include ActionView::Context
6
6
 
7
+ describe 'files' do
8
+ it 'should have correct dirs' do
9
+ expect(Dir.exists?('./app/assets/images')).to be_truthy
10
+ expect(Dir.exists?('./app/assets/javascripts')).to be_truthy
11
+ expect(Dir.exists?('./app/assets/stylesheets')).to be_truthy
12
+ expect(Dir.exists?('./app/helpers/font_awesome/rails')).to be_truthy
13
+ end
14
+
15
+ it 'should have correct files' do
16
+ expect(File.exists?('./app/helpers/font_awesome/rails/icon_helper.rb')).to be_truthy
17
+ expect(File.exists?('./app/assets/images/fa-brands.svg')).to be_truthy
18
+ expect(File.exists?('./app/assets/images/fa-regular.svg')).to be_truthy
19
+ expect(File.exists?('./app/assets/images/fa-solid.svg')).to be_truthy
20
+ expect(File.exists?('./app/assets/javascripts/font_awesome5.js')).to be_truthy
21
+ expect(File.exists?('./app/assets/javascripts/fontawesome-all.min.js')).to be_truthy
22
+ expect(File.exists?('./app/assets/stylesheets/fa-svg-with-js.css')).to be_truthy
23
+ expect(File.exists?('./app/assets/stylesheets/font_awesome5.css')).to be_truthy
24
+ expect(File.exists?('./lib/font_awesome5_rails/engine.rb')).to be_truthy
25
+ expect(File.exists?('./lib/font_awesome5_rails/version.rb')).to be_truthy
26
+ expect(File.exists?('./lib/font_awesome5_rails/fa_icon_parser.rb')).to be_truthy
27
+ end
28
+ end
29
+
7
30
  describe 'tags' do
8
31
  it 'should return correct type tags' do
9
32
  expect(fa_icon 'camera-retro').to eq '<i class="fas fa-camera-retro"></i>'
@@ -11,6 +34,10 @@ describe FontAwesome5Rails do
11
34
  expect(fa_icon 'camera-retro', type: :far).to eq '<i class="far fa-camera-retro"></i>'
12
35
  expect(fa_icon 'camera-retro', type: :fal).to eq '<i class="fal fa-camera-retro"></i>'
13
36
  expect(fa_icon 'camera-retro', type: :fab).to eq '<i class="fab fa-camera-retro"></i>'
37
+ expect(fa_icon 'camera-retro', type: :solid).to eq '<i class="fas fa-camera-retro"></i>'
38
+ expect(fa_icon 'camera-retro', type: :regular).to eq '<i class="far fa-camera-retro"></i>'
39
+ expect(fa_icon 'camera-retro', type: :light).to eq '<i class="fal fa-camera-retro"></i>'
40
+ expect(fa_icon 'camera-retro', type: :brand).to eq '<i class="fab fa-camera-retro"></i>'
14
41
  end
15
42
 
16
43
  it 'should return correct class tags' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: font_awesome5_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomkra
@@ -79,6 +79,7 @@ files:
79
79
  - bin/test
80
80
  - lib/font_awesome5_rails.rb
81
81
  - lib/font_awesome5_rails/engine.rb
82
+ - lib/font_awesome5_rails/fa_icon_parser.rb
82
83
  - lib/font_awesome5_rails/version.rb
83
84
  - lib/tasks/font_awesome5_rails_tasks.rake
84
85
  - spec/dummy/Rakefile
@@ -132,7 +133,6 @@ files:
132
133
  - spec/dummy/public/apple-touch-icon-precomposed.png
133
134
  - spec/dummy/public/apple-touch-icon.png
134
135
  - spec/dummy/public/favicon.ico
135
- - spec/examples.txt
136
136
  - spec/font_awesome5_rails_spec.rb
137
137
  - spec/spec_helper.rb
138
138
  homepage: https://github.com/tomkra/font_awesome5_rails
data/spec/examples.txt DELETED
@@ -1,3 +0,0 @@
1
- example_id | status | run_time |
2
- ------------------------------- | ------ | --------------- |
3
- ./spec/icon_helper_spec.rb[1:1] | failed | 0.00014 seconds |