fa_rails 0.1.2 → 0.1.3
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 +4 -4
- data/.travis.yml +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +115 -5
- data/fa_rails.gemspec +1 -1
- data/lib/fa/base.rb +123 -0
- data/lib/fa/layer.rb +12 -7
- data/lib/fa.rb +4 -122
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f88269f81e443d27897b42865438b0f2b4dd70
|
4
|
+
data.tar.gz: 1eb05c958c102f6f6c2c8e00009b90f934d596d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ebb0c7826814759264e16f9752b7cc1bcff1b064a2ff4479efbd057e4dfb62504dc4fbf23244bb073170988fa77119811e4d59920b8136eb775153a1d7c723e
|
7
|
+
data.tar.gz: bf6727814a5611ac6bba85fed25fbf142a5ee22dbc8fabc7b39de40eafc5be2be12d3da32aa13b2dc3517ccd80ad08de8a3d2231a1c0449283610670738f638f
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.4.2
|
4
|
+
branches:
|
5
|
+
except:
|
6
|
+
- "/^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-.*)?/"
|
7
|
+
notifications:
|
8
|
+
email:
|
9
|
+
on_success: change
|
10
|
+
on_failure: always
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,9 +10,119 @@ You must still have your own FontAwesome Pro license, or install the
|
|
10
10
|
[Free](https://use.fontawesome.com/releases/v5.2.0/fontawesome-free-5.2.0-web.zip)
|
11
11
|
package.
|
12
12
|
|
13
|
-
Copy the
|
14
|
-
[web download
|
15
|
-
|
13
|
+
Copy the complete `js` and `css` directories from the
|
14
|
+
[web download](https://fontawesome.com/releases/5.2.0/web/download) into the
|
15
|
+
corresponding locations in your app, and ensure you correctly include all files.
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
Add the following to `config/application.rb`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'fa'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
The `FA` module contains three main subclasses: `Icon`, `Span`, and `Layer`.
|
26
|
+
Argument formatting is consistent throughout.
|
27
|
+
|
28
|
+
`Icon` and `Span` are the units of this module. Both can be used individually.
|
29
|
+
The first argument of each class's `new` method can be either a String/Symbol of
|
30
|
+
the name of the FontAwesome icon, or a Hash containing the complete
|
31
|
+
configuration for the object.
|
32
|
+
|
33
|
+
`Layer` is used to combine multiple units into a single end object. It takes
|
34
|
+
advantage of the Hash input style on `Icon` and `Span` to allow it to accept a
|
35
|
+
single configuration Hash for the entire stack.
|
36
|
+
|
37
|
+
All three classes respond to two output methods: `raw` and `safe`.
|
38
|
+
|
39
|
+
- `raw` outputs the formatted string directly
|
40
|
+
- `safe` attempts to call `.html_safe` on the formatted string, if available
|
41
|
+
|
42
|
+
### Icon
|
43
|
+
|
44
|
+
A single FontAwesome icon.
|
45
|
+
|
46
|
+
#### Icon Arguments
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
fa #=> String / Symbol – OR Hash
|
50
|
+
options #=> Hash
|
51
|
+
style: Symbol # One of [:solid, :regular, :light, :brands], default :solid
|
52
|
+
size: Integer # Stepped scaling factor
|
53
|
+
|
54
|
+
css: String # Arbitrary CSS classes, space-delimited
|
55
|
+
fa: String # Arbitrary FA classes, space-delimited – each is automatically prefixed with `fa-`
|
56
|
+
title: String #=> Tooltip text
|
57
|
+
grow: Integer #=> Transform value – amount to grow by
|
58
|
+
shrink: Integer #=> Transform value – amount to shrink by
|
59
|
+
rotate: Integer #=> Transform value – amount to rotate by
|
60
|
+
up: Integer #=> Translation value upward
|
61
|
+
down: Integer #=> Translation value downward
|
62
|
+
left: Integer #=> Translation value leftward
|
63
|
+
right: Integer #=> Translation value rightward
|
64
|
+
```
|
65
|
+
|
66
|
+
### Span
|
67
|
+
|
68
|
+
A single FontAwesome span – counters or text labels – to be used in a Layer.
|
69
|
+
|
70
|
+
#### Span Arguments
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
fa #=> String / Symbol – one of [:counter, :text] – OR Hash
|
74
|
+
text #=> String
|
75
|
+
options #=> Hash
|
76
|
+
position: Symbol # Indicator of which corner to display on – one of [:tr, :tl, :br, :bl]
|
77
|
+
|
78
|
+
css: String # Arbitrary CSS classes, space-delimited
|
79
|
+
fa: String # Arbitrary FA classes, space-delimited – each is automatically prefixed with `fa-`
|
80
|
+
title: String #=> Tooltip text
|
81
|
+
grow: Integer #=> Transform value – amount to grow by
|
82
|
+
shrink: Integer #=> Transform value – amount to shrink by
|
83
|
+
rotate: Integer #=> Transform value – amount to rotate by
|
84
|
+
up: Integer #=> Translation value upward
|
85
|
+
down: Integer #=> Translation value downward
|
86
|
+
left: Integer #=> Translation value leftward
|
87
|
+
right: Integer #=> Translation value rightward
|
88
|
+
```
|
89
|
+
|
90
|
+
### Layer
|
91
|
+
|
92
|
+
A stack of layered FontAwesome icons and spans.
|
93
|
+
|
94
|
+
#### Layer Arguments
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
icons #=> Hash of icon/span configurations
|
98
|
+
title #=> String for tooltip text
|
99
|
+
grow #=> Additional global scaling factor added to all objects in the stack
|
100
|
+
css # Arbitrary CSS classes, space-delimited, applied to the layer stack
|
101
|
+
```
|
102
|
+
|
103
|
+
### Examples
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# Fixed-width lock icon
|
107
|
+
FA::Icon.new('lock', fa: 'fw').safe
|
108
|
+
#=> "<i class='fas fa-fw fa-lock' data-fa-transform='' title=''></i>"
|
109
|
+
|
110
|
+
# Counter span, with value 5
|
111
|
+
FA::Span.new('counter', 5).safe
|
112
|
+
#=> "<span class='fa-layers-counter ' data-fa-transform=''>5</span>
|
113
|
+
|
114
|
+
# Gray envelope icon with red exclamation mark overlayed, with tooltip 'Invalid email address'
|
115
|
+
FA::Layer.new([{ name: 'envelope', options: { css: :gray } }, { name: 'exclamation', options: { css: :red } }], title: 'Invalid email address').safe
|
116
|
+
#=> "<span class='icon fa-layers fa-fw ' title='Invalid email address'>" \
|
117
|
+
# "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
|
118
|
+
# "<i class='fas red fa-exclamation' data-fa-transform='grow-0' title=''></i>" \
|
119
|
+
# "</span>"
|
120
|
+
|
121
|
+
# Blue envelope with red counter on the top left corner, with value 7
|
122
|
+
FA::Layer.new([{ name: 'envelope', options: { css: :blue } }, { name: 'counter', text: 7, options: { css: :red, position: :tl } }]).safe
|
123
|
+
#=> "<span class='icon fa-layers fa-fw ' title=''>" \
|
124
|
+
# "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
|
125
|
+
# "<span class='red fa-layers-counter ' data-fa-transform='grow-0'>7" \
|
126
|
+
# "</span>" \
|
127
|
+
# "</span>"
|
128
|
+
```
|
data/fa_rails.gemspec
CHANGED
data/lib/fa/base.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FA
|
4
|
+
# FontAwesome 5 (Pro) Helper core class
|
5
|
+
class Base
|
6
|
+
def raw
|
7
|
+
#
|
8
|
+
end
|
9
|
+
|
10
|
+
def safe
|
11
|
+
safe_output(raw)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def safe_output(output)
|
17
|
+
# html_safe: No user content
|
18
|
+
output.respond_to?(:html_safe) ? output.html_safe : output
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_all(icons)
|
22
|
+
icons.map do |icon|
|
23
|
+
name = icon[:name]
|
24
|
+
options = icon[:options] || {}
|
25
|
+
|
26
|
+
if %i[counter text].include?(name.to_sym)
|
27
|
+
parse_span(name, icon[:text], options)
|
28
|
+
else
|
29
|
+
parse_icon(name, options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_icon(name, options = {})
|
35
|
+
options = fa_options(options)
|
36
|
+
parse_options(options)
|
37
|
+
title = options[:title]
|
38
|
+
|
39
|
+
@classes << "fa-#{name}"
|
40
|
+
@classes << "fa-#{size_x(options[:size])}" if !!options[:size]
|
41
|
+
css = @classes.flatten.join(' ')
|
42
|
+
transforms = @transforms.join(' ')
|
43
|
+
|
44
|
+
"<i class='#{css}' data-fa-transform='#{transforms}' title='#{title}'></i>"
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_span(type, text, options = {})
|
48
|
+
options.delete(:style)
|
49
|
+
options = fa_options(options)
|
50
|
+
parse_options(options)
|
51
|
+
pos = options.delete(:position)
|
52
|
+
position = long_position(pos) if !!pos
|
53
|
+
|
54
|
+
@classes << "fa-layers-#{type}"
|
55
|
+
@classes << (!!position ? "fa-layers-#{position}" : '')
|
56
|
+
css = @classes.flatten.reject { |c| c.to_s.match?(/^fa.$/) }.join(' ')
|
57
|
+
transforms = @transforms.join(' ')
|
58
|
+
|
59
|
+
"<span class='#{css}' data-fa-transform='#{transforms}'>#{text}</span>"
|
60
|
+
end
|
61
|
+
|
62
|
+
def fa_options(options)
|
63
|
+
default = { style: :solid, css: '', fa: '' }
|
64
|
+
|
65
|
+
default.merge(options.to_h)
|
66
|
+
end
|
67
|
+
|
68
|
+
def combine_grows(i, grow)
|
69
|
+
if i.key?(:options) && i[:options].key?(:grow)
|
70
|
+
i[:options][:grow] + grow
|
71
|
+
else
|
72
|
+
grow
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def combine_options(i, combined_grow)
|
77
|
+
if i.key?(:options)
|
78
|
+
i[:options].merge(grow: combined_grow)
|
79
|
+
else
|
80
|
+
{ grow: combined_grow }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def size_x(size)
|
85
|
+
return '' unless !!size || size == 1
|
86
|
+
"#{size}x"
|
87
|
+
end
|
88
|
+
|
89
|
+
def long_position(position)
|
90
|
+
return 'top-right' if position == :tr
|
91
|
+
return 'top-left' if position == :tl
|
92
|
+
return 'bottom-right' if position == :br
|
93
|
+
return 'bottom-left' if position == :bl
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_options(options)
|
97
|
+
parse_classes(options)
|
98
|
+
parse_transforms(options)
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse_classes(options)
|
102
|
+
@classes = []
|
103
|
+
@classes << parse_style(options[:style])
|
104
|
+
@classes << options[:fa].to_s.split(' ').map { |c| "fa-#{c}" }
|
105
|
+
@classes << options[:css].to_s.split(' ')
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_transforms(options)
|
109
|
+
@transforms = []
|
110
|
+
%i[grow shrink rotate up down left right].each do |transform|
|
111
|
+
if !!options[transform]
|
112
|
+
@transforms << "#{transform}-#{options[transform]}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def parse_style(style)
|
118
|
+
return 'fas' unless %i[solid regular light brands].include?(style)
|
119
|
+
|
120
|
+
'fa' + { solid: 's', regular: 'r', light: 'l', brands: 'b' }[style]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/fa/layer.rb
CHANGED
@@ -8,16 +8,21 @@ module FA
|
|
8
8
|
#
|
9
9
|
# Note: scaling counters does not work well with :grow, so should use the
|
10
10
|
# older "fa-3x" syntax in :css instead.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@output = span_top + parse_all(icons).join + span_bottom
|
11
|
+
@icons = icons
|
12
|
+
@title = title
|
13
|
+
@grow = grow
|
14
|
+
@css = css
|
17
15
|
end
|
18
16
|
|
19
17
|
def raw
|
20
|
-
@
|
18
|
+
span_top = "<span class='icon fa-layers fa-fw #{@css}' title='#{@title}'>"
|
19
|
+
span_bottom = '</span>'
|
20
|
+
|
21
|
+
@icons.each do |i|
|
22
|
+
i[:options] = combine_options(i, combine_grows(i, @grow))
|
23
|
+
end
|
24
|
+
|
25
|
+
span_top + parse_all(@icons).join + span_bottom
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/fa.rb
CHANGED
@@ -2,126 +2,8 @@
|
|
2
2
|
|
3
3
|
# FontAwesome 5 (Pro) Helper
|
4
4
|
module FA
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def raw
|
11
|
-
#
|
12
|
-
end
|
13
|
-
|
14
|
-
def safe
|
15
|
-
safe_output(raw)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def safe_output(output)
|
21
|
-
# html_safe: No user content
|
22
|
-
output.respond_to?(:html_safe) ? output.html_safe : output
|
23
|
-
end
|
24
|
-
|
25
|
-
def parse_all(icons)
|
26
|
-
icons.map do |icon|
|
27
|
-
name = icon[:name]
|
28
|
-
options = icon[:options] || {}
|
29
|
-
|
30
|
-
if %i[counter text].include?(name)
|
31
|
-
parse_span(name, icon[:text], options)
|
32
|
-
else
|
33
|
-
parse_icon(name, options)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_icon(name, options = {})
|
39
|
-
options = fa_options(options)
|
40
|
-
parse_options(options)
|
41
|
-
title = options[:title]
|
42
|
-
|
43
|
-
@classes << "fa-#{name}"
|
44
|
-
@classes << "fa-#{size_x(options[:size])}" if !!options[:size]
|
45
|
-
css = @classes.flatten.join(' ')
|
46
|
-
transforms = @transforms.join(' ')
|
47
|
-
|
48
|
-
"<i class='#{css}' data-fa-transform='#{transforms}' title='#{title}'></i>"
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_span(type, text, options = {})
|
52
|
-
options.delete(:style)
|
53
|
-
options = fa_options(options)
|
54
|
-
parse_options(options)
|
55
|
-
pos = options.delete(:position)
|
56
|
-
position = long_position(pos) if !!pos
|
57
|
-
|
58
|
-
@classes << "fa-layers-#{type}"
|
59
|
-
@classes << (!!position ? "fa-layers-#{position}" : '')
|
60
|
-
css = @classes.flatten.reject { |c| c.to_s.match?(/^fa.$/) }.join(' ')
|
61
|
-
transforms = @transforms.join(' ')
|
62
|
-
|
63
|
-
"<span class='#{css}' data-fa-transform='#{transforms}'>#{text}</span>"
|
64
|
-
end
|
65
|
-
|
66
|
-
def fa_options(options)
|
67
|
-
default = { style: :solid, css: '', fa: '' }
|
68
|
-
|
69
|
-
default.merge(options.to_h)
|
70
|
-
end
|
71
|
-
|
72
|
-
def combine_grows(i, grow)
|
73
|
-
if i.key?(:options) && i[:options].key?(:grow)
|
74
|
-
i[:options][:grow] + grow
|
75
|
-
else
|
76
|
-
grow
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def combine_options(i, combined_grow)
|
81
|
-
if i.key?(:options)
|
82
|
-
i[:options].merge(grow: combined_grow)
|
83
|
-
else
|
84
|
-
{ grow: combined_grow }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def size_x(size)
|
89
|
-
return '' unless !!size || size == 1
|
90
|
-
"#{size}x"
|
91
|
-
end
|
92
|
-
|
93
|
-
def long_position(position)
|
94
|
-
return 'top-right' if position == :tr
|
95
|
-
return 'top-left' if position == :tl
|
96
|
-
return 'bottom-right' if position == :br
|
97
|
-
return 'bottom-left' if position == :bl
|
98
|
-
end
|
99
|
-
|
100
|
-
def parse_options(options)
|
101
|
-
parse_classes(options)
|
102
|
-
parse_transforms(options)
|
103
|
-
end
|
104
|
-
|
105
|
-
def parse_classes(options)
|
106
|
-
@classes = []
|
107
|
-
@classes << parse_style(options[:style])
|
108
|
-
@classes << options[:fa].to_s.split(' ').map { |c| "fa-#{c}" }
|
109
|
-
@classes << options[:css].to_s.split(' ')
|
110
|
-
end
|
111
|
-
|
112
|
-
def parse_transforms(options)
|
113
|
-
@transforms = []
|
114
|
-
%i[grow shrink rotate up down left right].each do |transform|
|
115
|
-
if !!options[transform]
|
116
|
-
@transforms << "#{transform}-#{options[transform]}"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def parse_style(style)
|
122
|
-
return 'fas' unless %i[solid regular light brands].include?(style)
|
123
|
-
|
124
|
-
'fa' + { solid: 's', regular: 'r', light: 'l', brands: 'b' }[style]
|
125
|
-
end
|
126
|
-
end
|
5
|
+
require 'fa/base'
|
6
|
+
require 'fa/icon'
|
7
|
+
require 'fa/span'
|
8
|
+
require 'fa/layer'
|
127
9
|
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.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
@@ -97,12 +97,14 @@ extensions: []
|
|
97
97
|
extra_rdoc_files: []
|
98
98
|
files:
|
99
99
|
- ".gitignore"
|
100
|
+
- ".travis.yml"
|
100
101
|
- Gemfile
|
101
102
|
- Gemfile.lock
|
102
103
|
- README.md
|
103
104
|
- Rakefile
|
104
105
|
- fa_rails.gemspec
|
105
106
|
- lib/fa.rb
|
107
|
+
- lib/fa/base.rb
|
106
108
|
- lib/fa/icon.rb
|
107
109
|
- lib/fa/layer.rb
|
108
110
|
- lib/fa/span.rb
|