fa_rails 0.1.14 → 0.1.15

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: bedbb3b52f82b24d5ef7d78088141fcf16710258
4
- data.tar.gz: aad0ad0db36223df9317c8fe54d0a61a879a5ba1
3
+ metadata.gz: 1ac5856744bf6210fbf8d25ad918d04b1400e4b6
4
+ data.tar.gz: 434637241dbce4c9b753f0190b9ac5bc98093f1a
5
5
  SHA512:
6
- metadata.gz: 2ac8ff919be13408c0c1093bfc260eb6eb86b532b90236c5e7cf4234eb1b35ab1764a903641f256ac0dbe2d228918d2bf155eb5c22d6e02f9d197342bb09e777
7
- data.tar.gz: dff2c8aa2b9ea64e4924d241ff4fd0922bf52747fd63a37b223765b97e0917d3c14b9891a3590c3977a5537c6d11285f238ed202c2efa3af8a086b641b32e0a8
6
+ metadata.gz: e4597b5992842776f509f9c43509df54e89d6a13658c9018b94e25fc168c41121ce6217b5682870066901183718ecb987a712570c21029a6d57617cac7171fed
7
+ data.tar.gz: 0613746247f5dc8a6d86e76a7ee4548c7441e3f62b65301bcfdcd857e3a2f6d85739b9d7ef829373e0612131c288cda0365c3fafb20ef55714cdc52a97e34a35
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.14)
4
+ fa_rails (0.1.15)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -136,24 +136,29 @@ css # String – arbitrary CSS classes, space-delimited, applied to the layer st
136
136
  ```ruby
137
137
  # Fixed-width lock icon
138
138
  FA::Icon.p('lock', fa: 'fw')
139
- #=> "<i class='fas fa-fw fa-lock' data-fa-transform='' title=''></i>"
139
+ #=> "<i class='fas fa-fw fa-lock fa-1x' data-fa-transform='' title=''></i>"
140
140
 
141
141
  # Counter span, with value 5
142
142
  FA::Span.p('counter', 5)
143
- #=> "<span class='fa-layers-counter ' data-fa-transform=''>5</span>
143
+ #=> "<span class='fa-layers-counter ' data-fa-transform=''>5</span>"
144
144
 
145
145
  # Gray envelope icon with red exclamation mark overlayed, with tooltip 'Invalid email address'
146
146
  FA::Layer.p([{ name: 'envelope', options: { css: :gray } }, { name: 'exclamation', options: { css: :red } }], title: 'Invalid email address')
147
147
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title='Invalid email address'>" \
148
- # "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
149
- # "<i class='fas red fa-exclamation' data-fa-transform='grow-0' title=''></i>" \
148
+ # "<i class='fas fa-stack-1x gray fa-envelope fa-1x' data-fa-transform='grow-0' title='Invalid email address'></i>" \
149
+ # "<i class='fas fa-stack-1x red fa-exclamation fa-1x' data-fa-transform='grow-0' title='Invalid email address'></i>" \
150
150
  # "</span>"
151
151
 
152
152
  # Blue envelope with red counter on the top left corner, with value 7
153
153
  FA::Layer.p([{ name: 'envelope', options: { css: :blue } }, { name: 'counter', text: 7, options: { css: :red, position: :tl } }])
154
154
  #=> "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
155
- # "<i class='fas gray fa-envelope' data-fa-transform='grow-0' title=''></i>" \
156
- # "<span class='red fa-layers-counter ' data-fa-transform='grow-0'>7" \
157
- # "</span>" \
155
+ # "<i class='fas fa-stack-1x blue fa-envelope fa-1x' data-fa-transform='grow-0' title=''></i>" \
156
+ # "<span class='fa-stack-1x red fa-layers-counter fa-layers-top-left' data-fa-transform='grow-0'>7</span>" \
158
157
  # "</span>"
158
+
159
+ # The same stack, but using FA::Build
160
+ FA::Build.p do |b|
161
+ b.icon('circle')
162
+ b.span('counter', 7)
163
+ end
159
164
  ```
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.14'
3
+ s.version = '0.1.15'
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/build.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FA
4
+ # FontAwesome 5 (Pro) Helper for piecewise building layered icons and spans
5
+ class Build < FA::Layer
6
+ # Creates a new Layer instance
7
+ #
8
+ # Add icons or spans to the stack from bottom to top
9
+ #
10
+ # This is a variand of FA::Layer, to allow for DSL building stacks
11
+ #
12
+ # Note: scaling counters does not work well with :grow, so should use the
13
+ # older "fa-3x" syntax in :css instead.
14
+ #
15
+ # @param [Array] icons The complete hash configurations for each icon/span
16
+ # @param [String] title The tooltip text
17
+ # @param [Integer] grow An additional global scaling factor added in
18
+ # @param [String] css Additional arbitrary CSS classes, space-delimited
19
+ def initialize(icons = {}, title: nil, grow: 0, css: '')
20
+ super
21
+ @contents = ''
22
+ yield(self) if block_given?
23
+ end
24
+
25
+ # Outputs the formatted stack of icons and spans directly.
26
+ def raw
27
+ build { @contents }
28
+ end
29
+
30
+ # Adds an icon to the stack using the same argument format.
31
+ def icon(icon, **options)
32
+ @contents += FA::Icon.p(icon, full_options(options))
33
+ self
34
+ end
35
+
36
+ # Adds a span to the stack using the same argument format.
37
+ def span(type, text, **options)
38
+ @contents += FA::Span.p(type, text, full_options(options))
39
+ self
40
+ end
41
+
42
+ # Shortcut for create and output safe
43
+ def self.p(*args, &block)
44
+ new(*args, &block).safe
45
+ end
46
+
47
+ private
48
+
49
+ def default_options
50
+ { title: @title, grow: @grow, css: @css, size: 1, fa: '' }
51
+ end
52
+
53
+ def full_options(options)
54
+ options = default_options.merge(options)
55
+ options[:fa] += " stack-#{options[:size]}x"
56
+ options
57
+ end
58
+ end
59
+ end
data/lib/fa/layer.rb CHANGED
@@ -23,16 +23,19 @@ module FA
23
23
 
24
24
  # Outputs the formatted stack of icons and spans directly.
25
25
  def raw
26
- span_top = "<span class='icon fa-layers fa-stack fa-fw #{@css}' " \
27
- "title='#{@title}'>"
28
- span_bottom = '</span>'
29
-
30
26
  @icons.each do |i|
31
27
  i[:options] = combine_options(i, combine_grows(i, @grow))
32
28
  i[:options][:title] = @title
33
29
  end
34
30
 
35
- span_top + parse_all(@icons).join + span_bottom
31
+ build { parse_all(@icons).join }
32
+ end
33
+
34
+ private
35
+
36
+ def build
37
+ "<span class='icon fa-layers fa-stack fa-fw #{@css}' " \
38
+ "title='#{@title}'>#{yield}</span>"
36
39
  end
37
40
  end
38
41
  end
data/lib/fa.rb CHANGED
@@ -9,5 +9,6 @@ module FA
9
9
  require 'fa/icon'
10
10
  require 'fa/span'
11
11
  require 'fa/layer'
12
+ require 'fa/build'
12
13
  require 'fa/link'
13
14
  end
data/spec/lib/fa_spec.rb CHANGED
@@ -91,6 +91,22 @@ RSpec.describe FA do
91
91
  end
92
92
  end
93
93
 
94
+ describe 'build' do
95
+ it 'should generate the correct layer' do
96
+ layer = FA::Build.p do |b|
97
+ b.icon('circle')
98
+ b.span('counter', 7)
99
+ end
100
+
101
+ expect(layer).to eql(
102
+ "<span class='icon fa-layers fa-stack fa-fw ' title=''>" \
103
+ "<i class='fas fa-stack-1x fa-circle fa-1x' data-fa-transform='grow-0' title=''></i>" \
104
+ "<span class='fa-stack-1x fa-layers-counter ' data-fa-transform='grow-0'>7</span>" \
105
+ '</span>'
106
+ )
107
+ end
108
+ end
109
+
94
110
  describe 'span' do
95
111
  it 'should generate the correct span from a string or symbol type' do
96
112
  expect(FA::Span.p(:text, 'Hello')).to eql(
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.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -85,6 +85,7 @@ files:
85
85
  - fa_rails.gemspec
86
86
  - lib/fa.rb
87
87
  - lib/fa/base.rb
88
+ - lib/fa/build.rb
88
89
  - lib/fa/icon.rb
89
90
  - lib/fa/layer.rb
90
91
  - lib/fa/link.rb