fa_rails 0.1.4 → 0.1.5

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
  SHA1:
3
- metadata.gz: a72e373530cd8a3caedad00de37025fb2187e006
4
- data.tar.gz: cd91f707b79ab534a6e33c2eb93a136ce545882d
3
+ metadata.gz: 9fbd3a8577ad17608b6c22a6f859bd6c5310d754
4
+ data.tar.gz: 2ad7baf895420340358d2a3b996d737094eeb017
5
5
  SHA512:
6
- metadata.gz: 27ba03ee38ef0b3989b296d7871e29b3bc5fb02abe76cfcd1378303bbad953cafd663bce525f05a1dc54486b732a3ed1343f334e13bc12e6a4bbed7e4dc5a88b
7
- data.tar.gz: 03d4a55e8a63b0bb1586f18ae4608b5e62d853f39adb5b81a0b92184b2b6679e6f0d507baf7d061ad45dcedb26e5cf44703c033502fa4e1a5fb84f9e3d5b49e8
6
+ metadata.gz: 422152f48a9815e5423118f43f1e8d5851d1926dda4500ba8584525a0a96e0af3bae1dd1273fd5cad7feb93a062ccaae2bda4b71c6d765ee1816626b8583e90d
7
+ data.tar.gz: 3fa5f813afa216497416d20cd180e03a943b32b4d7f9ac3c2e7720109b3b8baf6e51e4c8e6b7f81f17543bf472239fc9ee35344ef52f1d1bef0f8201b700c197
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fa_rails (0.1.3)
4
+ fa_rails (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -10,6 +10,8 @@ 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
+ ### Local Files
14
+
13
15
  Copy the complete `js` and `css` directories from the
14
16
  [web download](https://fontawesome.com/releases/5.2.0/web/download) into the
15
17
  corresponding locations in your app, and ensure you correctly include all files.
@@ -20,6 +22,26 @@ Add the following to `config/application.rb`:
20
22
  require 'fa'
21
23
  ```
22
24
 
25
+ ### FontAwesome CDN
26
+
27
+ Go to the FontAwesome
28
+ [How to Use](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=web-fonts-with-css)
29
+ page and copy the appropriate CDN link tag:
30
+
31
+ #### Free
32
+
33
+ ```html
34
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-some-key-here" crossorigin="anonymous">
35
+ ```
36
+
37
+ #### Pro
38
+
39
+ ```html
40
+ <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-some-key-here" crossorigin="anonymous">
41
+ ```
42
+
43
+ **Be sure to also need to register each domain that will use this CDN link.**
44
+
23
45
  ## Usage
24
46
 
25
47
  The `FA` module contains three main subclasses: `Icon`, `Span`, and `Layer`.
data/fa_rails.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fa_rails'
3
- s.version = '0.1.4'
4
- s.date = '2018-07-28'
3
+ s.version = '0.1.5'
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.'
7
7
  s.homepage = 'http://rubygems.org/gems/fa_rails'
data/lib/fa/base.rb CHANGED
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FA
4
- # FontAwesome 5 (Pro) Helper core class
4
+ # FontAwesome 5 (Pro) Helper core class for inheritance
5
5
  class Base
6
+ # Outputs the formatted string directly.
6
7
  def raw
7
8
  #
8
9
  end
9
10
 
11
+ # Attempts to call `.html_safe` on the the output of `raw`, if available.
10
12
  def safe
11
- safe_output(raw)
13
+ output = raw
14
+ output.respond_to?(:html_safe) ? output.html_safe : output
12
15
  end
13
16
 
14
17
  private
15
18
 
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
19
  def parse_all(icons)
22
20
  icons.map do |icon|
23
21
  name = icon[:name]
data/lib/fa/icon.rb CHANGED
@@ -3,6 +3,11 @@
3
3
  module FA
4
4
  # FontAwesome 5 (Pro) Helper for generating icons
5
5
  class Icon < FA::Base
6
+ # Creates a new Icon instance
7
+ #
8
+ # @param [Hash] fa The complete icon configuration
9
+ # @param [String] fa The icon name to generate
10
+ # @param [Hash] options Additional configuration options
6
11
  def initialize(fa, options = {})
7
12
  @options = options
8
13
  if fa.is_a?(Hash)
@@ -15,6 +20,7 @@ module FA
15
20
  end
16
21
  end
17
22
 
23
+ # Outputs the formatted icon directly.
18
24
  def raw
19
25
  parse_icon(@name, @options)
20
26
  end
data/lib/fa/layer.rb CHANGED
@@ -3,17 +3,25 @@
3
3
  module FA
4
4
  # FontAwesome 5 (Pro) Helper for generating layered icons and spans
5
5
  class Layer < FA::Base
6
+ # Creates a new Layer instance
7
+ #
8
+ # Add icons or spans to the stack from bottom to top
9
+ #
10
+ # Note: scaling counters does not work well with :grow, so should use the
11
+ # older "fa-3x" syntax in :css instead.
12
+ #
13
+ # @param [Array] icons The complete hash configurations for each icon/span
14
+ # @param [String] title The tooltip text
15
+ # @param [Integer] grow An additional global scaling factor added in
16
+ # @param [String] css Additional arbitrary CSS classes, space-delimited
6
17
  def initialize(icons = {}, title: nil, grow: 0, css: '')
7
- # Add icons to the stack bottom to top
8
- #
9
- # Note: scaling counters does not work well with :grow, so should use the
10
- # older "fa-3x" syntax in :css instead.
11
18
  @icons = icons
12
19
  @title = title
13
20
  @grow = grow
14
21
  @css = css
15
22
  end
16
23
 
24
+ # Outputs the formatted stack of icons and spans directly.
17
25
  def raw
18
26
  span_top = "<span class='icon fa-layers fa-fw #{@css}' title='#{@title}'>"
19
27
  span_bottom = '</span>'
data/lib/fa/span.rb CHANGED
@@ -3,6 +3,12 @@
3
3
  module FA
4
4
  # FontAwesome 5 (Pro) Helper for generating spans (counters and text)
5
5
  class Span < FA::Base
6
+ # Creates a new Span instance
7
+ #
8
+ # @param [Hash] fa The complete span configuration
9
+ # @param [String] fa The span type to generate
10
+ # @param [String] test The contents of the span
11
+ # @param [Hash] options Additional configuration options
6
12
  def initialize(fa, text = '', options = {})
7
13
  if fa.is_a?(Hash)
8
14
  set_options(fa[:type].to_sym, fa[:text], fa[:options])
@@ -13,6 +19,7 @@ module FA
13
19
  end
14
20
  end
15
21
 
22
+ # Outputs the formatted span directly.
16
23
  def raw
17
24
  parse_span(@type, @text, @options)
18
25
  end
data/lib/fa.rb CHANGED
@@ -1,9 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # FontAwesome 5 (Pro) Helper
4
+ #
5
+ # @author Julian Fiander
6
+ # @since 0.1.0
4
7
  module FA
5
8
  require 'fa/base'
6
9
  require 'fa/icon'
7
10
  require 'fa/span'
8
11
  require 'fa/layer'
12
+
13
+ def fa_cdn_link(version:, integrity:, pro: true)
14
+ subdomain = pro ? 'pro' : 'use'
15
+ url = "https://#{subdomain}.fontawesome.com/releases/#{version}/css/all.css"
16
+
17
+ "<link rel=\"stylesheet\" href=\"#{url}\" " \
18
+ "integrity=\"#{integrity}\" crossorigin=\"anonymous\">"
19
+ end
9
20
  end
data/spec/lib/fa_spec.rb CHANGED
@@ -3,6 +3,17 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe FA do
6
+ include FA
7
+
8
+ it 'should generate the correct link tag' do
9
+ tag = fa_cdn_link(version: 'v0.1.2', integrity: 'sha384-abc', pro: true)
10
+ expect(tag).to eql(
11
+ '<link rel="stylesheet" ' \
12
+ 'href="https://pro.fontawesome.com/releases/v0.1.2/css/all.css" ' \
13
+ 'integrity="sha384-abc" crossorigin="anonymous">'
14
+ )
15
+ end
16
+
6
17
  describe 'icon' do
7
18
  it 'should generate the correct icon from a string or symbol name' do
8
19
  expect(FA::Icon.new('help').safe).to eql(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fa_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-28 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake