fontawesome_cdn 0.3.0 → 1.1.0
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/CHANGELOG.md +43 -0
- data/README.md +44 -28
- data/lib/fontawesome_cdn/configuration.rb +28 -0
- data/lib/fontawesome_cdn/helpers/icon.rb +63 -40
- data/lib/fontawesome_cdn/version.rb +1 -1
- data/lib/fontawesome_cdn.rb +12 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a3570d57a5ff55f3e8d76855da20a3d4743aa6d28f074f8195e08f030e16373
|
|
4
|
+
data.tar.gz: d1672f687e2a00fb5dbbff244e7b62e71975e8b8b3f90619a01bad9764154a63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2aeeda5c1970e61f55e7dcd77170117b7eb16cbaab06de19df4518ee5fa93143b1e56df0c0a6203fae0880cba2966bf3c434319316ba50a9f48f5d8410815d59
|
|
7
|
+
data.tar.gz: d6d70f2d163927def278fdb3e86714105f0786409e29d81b4884a5feca1eb71b17b9311596c1466f8665f056e5c811b2973dff7c9db5ceb15fd0a915eb7d2a32
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,49 @@ This project follows [Semantic Versioning](https://semver.org).
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Allow passing arbitrary HTML attributes (e.g. style, data, title) to the `icon` helper
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 1.0.0
|
|
17
|
+
|
|
18
|
+
This release marks the **first stable version** of FontawesomeCdn.
|
|
19
|
+
The public API is now considered stable and will follow Semantic Versioning.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Stabilized the `icon` helper API with a fully class-based approach.
|
|
23
|
+
- Removed legacy `style:` and `pack:` options in favor of direct Font Awesome classes.
|
|
24
|
+
- Default family and style are now applied automatically via configuration.
|
|
25
|
+
- The `classic` family is implicit and no longer rendered as `fa-classic`.
|
|
26
|
+
- When using the `brands` family, no style class is automatically injected.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- Added `fa:` option as a convenience shortcut to pass space-separated Font Awesome tokens
|
|
30
|
+
(automatically prefixed with `fa-`).
|
|
31
|
+
- Added global configuration options:
|
|
32
|
+
- `default_family`
|
|
33
|
+
- `default_style`
|
|
34
|
+
- `default_aria_hidden`
|
|
35
|
+
|
|
36
|
+
### Examples
|
|
37
|
+
```erb
|
|
38
|
+
<%= icon "user" %>
|
|
39
|
+
<%= icon "gear", "Settings" %>
|
|
40
|
+
<%= icon "bell", class: "fa-regular fa-2x fa-shake" %>
|
|
41
|
+
<%= icon "bell", fa: "regular 2x shake" %>
|
|
42
|
+
<%= icon "github", "Source code", fa: "brands", class: "link" %>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Notes
|
|
46
|
+
- No validation or conflict resolution is applied when multiple styles or families are provided.
|
|
47
|
+
- Users are free to combine classes as needed for experimentation or advanced use cases.
|
|
48
|
+
- Versions prior to `1.0.0` should be considered experimental.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
9
52
|
## 0.3.0
|
|
10
53
|
|
|
11
54
|
### Changed
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Simple Rails helpers to load **Font Awesome via CDN or Kit**, and render icons i
|
|
|
8
8
|
✅ Supports **Font Awesome Free (CDN)**
|
|
9
9
|
✅ Supports **Font Awesome Pro (Kit)**
|
|
10
10
|
✅ Compatible with **Font Awesome 7**
|
|
11
|
-
✅ Compatible with **Rails
|
|
11
|
+
✅ Compatible with **Rails 8**
|
|
12
12
|
✅ No asset pipeline required
|
|
13
13
|
|
|
14
14
|
---
|
|
@@ -27,25 +27,23 @@ bundle install
|
|
|
27
27
|
|
|
28
28
|
## 🚀 Usage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
### 1️⃣ Load Font Awesome
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Place inside your `<head>`:
|
|
32
|
+
**Simply add the helper inside the `<head>` of your layout**:
|
|
35
33
|
|
|
36
34
|
```erb
|
|
37
|
-
|
|
35
|
+
<!-- app/views/layouts/application.html.erb -->
|
|
36
|
+
<head>
|
|
37
|
+
<%= include_font_awesome "7.0.1" %>
|
|
38
|
+
</head>
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```html
|
|
43
|
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" ...>
|
|
44
|
-
```
|
|
41
|
+
👉 Loads Font Awesome from cdnjs
|
|
42
|
+
👉 Recommended for Font Awesome Free
|
|
45
43
|
|
|
46
44
|
---
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
#### Alternative — Load a Font Awesome Kit
|
|
49
47
|
|
|
50
48
|
If you have a Font Awesome Pro subscription, you can load your Kit:
|
|
51
49
|
|
|
@@ -53,34 +51,52 @@ If you have a Font Awesome Pro subscription, you can load your Kit:
|
|
|
53
51
|
<%= include_font_awesome kit: "YOUR-KIT-ID" %>
|
|
54
52
|
```
|
|
55
53
|
|
|
56
|
-
This generates:
|
|
57
|
-
|
|
58
|
-
```html
|
|
59
|
-
<script src="https://kit.fontawesome.com/YOUR-KIT-ID.js" crossorigin="anonymous"></script>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
54
|
👉 Use this method for **Font Awesome Pro**
|
|
63
55
|
👉 The kit automatically loads your own selection (Pro icons, subsets, etc.)
|
|
64
56
|
|
|
65
57
|
---
|
|
66
58
|
|
|
67
|
-
|
|
59
|
+
### 2️⃣ Render icons (in views)
|
|
60
|
+
|
|
61
|
+
Basic usage:
|
|
68
62
|
|
|
69
63
|
```erb
|
|
70
64
|
<%= icon "user" %>
|
|
71
65
|
<%= icon "gear", "Settings" %>
|
|
72
|
-
<%= icon "
|
|
73
|
-
|
|
66
|
+
<%= icon "bell", class: "fa-regular fa-2x fa-shake" %>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Using the `fa:` shortcut
|
|
70
|
+
|
|
71
|
+
For convenience, you can use the `fa:` option to pass **space-separated Font Awesome tokens**, automatically prefixed with `fa-`.
|
|
72
|
+
|
|
73
|
+
```erb
|
|
74
|
+
<%= icon "bell", fa: "regular 2x shake" %>
|
|
75
|
+
<%= icon "github", "Source code", fa: "brands", class: "link" %>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## ⚙️ Configuration
|
|
81
|
+
|
|
82
|
+
FontawesomeCdn allows you to define default icon behavior that will be **automatically applied to all icons**, unless explicitly overridden at render time.
|
|
83
|
+
|
|
84
|
+
```rb
|
|
85
|
+
# config/initializers/fontawesome_cdn.rb
|
|
86
|
+
FontawesomeCdn.configure do |config|
|
|
87
|
+
config.default_family = "classic"
|
|
88
|
+
config.default_style = "solid"
|
|
89
|
+
config.default_aria_hidden = true
|
|
90
|
+
end
|
|
74
91
|
```
|
|
75
92
|
|
|
76
|
-
|
|
93
|
+
By default, these settings are used to determine which Font Awesome family and style are added to each icon.
|
|
94
|
+
If a family or style is explicitly provided via `class:` or `fa:`, it will be used instead of the defaults.
|
|
77
95
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
| `class:` | Additional CSS classes |
|
|
83
|
-
| `aria-hidden:` | Passed as-is |
|
|
96
|
+
Defaults:
|
|
97
|
+
- `classic` is implicit (no `fa-classic`)
|
|
98
|
+
- default style is injected automatically
|
|
99
|
+
- `brands` does not inject a style
|
|
84
100
|
|
|
85
101
|
---
|
|
86
102
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FontawesomeCdn
|
|
4
|
+
# Configuration object for FontawesomeCdn.
|
|
5
|
+
#
|
|
6
|
+
# Allows customizing default icon behavior such as:
|
|
7
|
+
# - icon family (classic, brands, duotone, …)
|
|
8
|
+
# - icon style (solid, regular, light, thin)
|
|
9
|
+
# - default aria-hidden attribute
|
|
10
|
+
#
|
|
11
|
+
# This configuration can be set in a Rails initializer:
|
|
12
|
+
#
|
|
13
|
+
# FontawesomeCdn.configure do |config|
|
|
14
|
+
# config.default_family = "classic"
|
|
15
|
+
# config.default_style = "solid"
|
|
16
|
+
# config.default_aria_hidden = true
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
class Configuration
|
|
20
|
+
attr_accessor :default_family, :default_style, :default_aria_hidden
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
@default_family = :classic
|
|
24
|
+
@default_style = :solid
|
|
25
|
+
@default_aria_hidden = true
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -3,15 +3,35 @@
|
|
|
3
3
|
module FontawesomeCdn
|
|
4
4
|
# View helpers for rendering Font Awesome icons
|
|
5
5
|
module Helpers
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
FAMILIES = %w[
|
|
7
|
+
classic duotone sharp sharp-duotone brands chisel etch jelly notdog slab
|
|
8
|
+
thumbprint utility whiteboard
|
|
9
|
+
].freeze
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
STYLES = %w[solid regular light thin].freeze
|
|
12
|
+
|
|
13
|
+
# Renders a Font Awesome icon
|
|
14
|
+
#
|
|
15
|
+
# Basic usage (default family and style are applied automatically):
|
|
10
16
|
#
|
|
11
17
|
# <%= icon "user" %>
|
|
12
18
|
# <%= icon "gear", "Settings" %>
|
|
13
|
-
# <%= icon "
|
|
14
|
-
#
|
|
19
|
+
# <%= icon "bell", class: "fa-regular fa-2x fa-shake" %>
|
|
20
|
+
#
|
|
21
|
+
# Using the `fa:` shortcut (tokens are automatically prefixed with `fa-`):
|
|
22
|
+
#
|
|
23
|
+
# <%= icon "bell", fa: "regular 2x shake" %>
|
|
24
|
+
# <%= icon "github", "Source code", fa: "brands", class: "link" %>
|
|
25
|
+
# <%= icon "alien", fa: "duotone light" %>
|
|
26
|
+
#
|
|
27
|
+
# Accessibility:
|
|
28
|
+
#
|
|
29
|
+
# <%= icon "user", aria-hidden: false %>
|
|
30
|
+
#
|
|
31
|
+
# Notes:
|
|
32
|
+
# - Default family and style are applied unless explicitly overridden.
|
|
33
|
+
# - No validation or conflict resolution is performed on classes.
|
|
34
|
+
# - Users are free to combine multiple styles or families if needed.
|
|
15
35
|
#
|
|
16
36
|
def icon(name, text = nil, **options)
|
|
17
37
|
# Allow the 2nd argument to be either text or the options hash
|
|
@@ -20,52 +40,55 @@ module FontawesomeCdn
|
|
|
20
40
|
text = nil
|
|
21
41
|
end
|
|
22
42
|
|
|
23
|
-
|
|
43
|
+
aria_hidden =
|
|
44
|
+
if options.key?(:"aria-hidden")
|
|
45
|
+
options.delete(:"aria-hidden")
|
|
46
|
+
else
|
|
47
|
+
FontawesomeCdn.configuration.default_aria_hidden
|
|
48
|
+
end
|
|
24
49
|
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
# "special" options we consume
|
|
51
|
+
class_tokens = options.delete(:class).to_s.split
|
|
52
|
+
fa_tokens = options.delete(:fa).to_s.split.map { |t| "fa-#{t}" }
|
|
27
53
|
|
|
28
|
-
|
|
54
|
+
tokens = (class_tokens + fa_tokens).uniq
|
|
29
55
|
|
|
30
|
-
|
|
31
|
-
|
|
56
|
+
family = tokens
|
|
57
|
+
.map { |t| t.delete_prefix("fa-") }
|
|
58
|
+
.find { |t| FAMILIES.include?(t) } || FontawesomeCdn.configuration.default_family.to_s
|
|
32
59
|
|
|
33
|
-
|
|
60
|
+
style = tokens
|
|
61
|
+
.map { |t| t.delete_prefix("fa-") }
|
|
62
|
+
.find { |t| STYLES.include?(t) } || FontawesomeCdn.configuration.default_style.to_s
|
|
34
63
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# Special case: brands icons don't use a style like "solid"
|
|
39
|
-
def build_pack_and_style_classes(options)
|
|
40
|
-
pack = options.delete(:pack)&.to_s
|
|
41
|
-
style = options.delete(:style)&.to_s
|
|
42
|
-
style ||= DEFAULT_ICON_STYLE unless pack == "brands"
|
|
64
|
+
# remove family + style from tokens so they can't reappear later
|
|
65
|
+
tokens.delete("fa-#{family}")
|
|
66
|
+
tokens.delete("fa-#{style}")
|
|
43
67
|
|
|
44
|
-
|
|
68
|
+
classes = []
|
|
69
|
+
classes << "fa-#{family}" unless family == "classic"
|
|
70
|
+
classes << "fa-#{style}" unless family == "brands"
|
|
71
|
+
classes << "fa-#{name}"
|
|
72
|
+
classes.concat(tokens)
|
|
45
73
|
|
|
46
|
-
|
|
47
|
-
|
|
74
|
+
# keep remaining options as HTML attributes (style, data, id, title, ...)
|
|
75
|
+
html_options = options.merge(
|
|
76
|
+
class: classes.uniq.join(" "),
|
|
77
|
+
"aria-hidden": aria_hidden
|
|
78
|
+
)
|
|
48
79
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
#
|
|
52
|
-
def validate_icon_style_and_pack!(style, pack)
|
|
53
|
-
raise_style_used_as_pack_error(pack) if pack && ICON_STYLES.include?(pack)
|
|
54
|
-
raise_unsupported_icon_style_error(style) if style && !ICON_STYLES.include?(style)
|
|
55
|
-
end
|
|
80
|
+
icon_tag = content_tag(:i, nil, **html_options)
|
|
81
|
+
return icon_tag if text.nil? || text.to_s.empty?
|
|
56
82
|
|
|
57
|
-
|
|
58
|
-
raise ArgumentError, <<~MSG
|
|
59
|
-
fontawesome_cdn: #{pack.inspect} is a style, not a pack.
|
|
60
|
-
Use style: #{pack.inspect} instead.
|
|
61
|
-
MSG
|
|
83
|
+
safe_join([icon_tag, ERB::Util.html_escape(text.to_s)], " ")
|
|
62
84
|
end
|
|
63
85
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def extract_family_and_style(tokens)
|
|
89
|
+
family = tokens.find { |t| FAMILIES.include?(t) }
|
|
90
|
+
style = tokens.find { |t| STYLES.include?(t) }
|
|
91
|
+
[family, style]
|
|
69
92
|
end
|
|
70
93
|
end
|
|
71
94
|
end
|
data/lib/fontawesome_cdn.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "fontawesome_cdn/version"
|
|
4
|
+
require_relative "fontawesome_cdn/configuration"
|
|
5
|
+
|
|
4
6
|
require "fontawesome_cdn/helpers/include_font_awesome"
|
|
5
7
|
require "fontawesome_cdn/helpers/icon"
|
|
6
8
|
require "fontawesome_cdn/railtie" if defined?(Rails)
|
|
@@ -20,6 +22,16 @@ module FontawesomeCdn
|
|
|
20
22
|
|
|
21
23
|
SUPPORTED_VERSIONS = CDN_INTEGRITY_MAP.keys.freeze
|
|
22
24
|
|
|
25
|
+
class << self
|
|
26
|
+
def configuration
|
|
27
|
+
@configuration ||= Configuration.new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def configure
|
|
31
|
+
yield(configuration)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
23
35
|
# Helpers exposed to the Rails views
|
|
24
36
|
module Helpers
|
|
25
37
|
# The methods are added here by the helper files
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fontawesome_cdn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenCodeForge
|
|
@@ -30,8 +30,8 @@ dependencies:
|
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: '9.0'
|
|
32
32
|
description: |
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
FontawesomeCdn provides simple Rails helpers to load Font Awesome (Free or Pro) via CDN or Kit,
|
|
34
|
+
and render icons using a flexible, class-based API.
|
|
35
35
|
email:
|
|
36
36
|
- contact@opencodeforge.com
|
|
37
37
|
executables: []
|
|
@@ -44,6 +44,7 @@ files:
|
|
|
44
44
|
- README.md
|
|
45
45
|
- Rakefile
|
|
46
46
|
- lib/fontawesome_cdn.rb
|
|
47
|
+
- lib/fontawesome_cdn/configuration.rb
|
|
47
48
|
- lib/fontawesome_cdn/helpers/icon.rb
|
|
48
49
|
- lib/fontawesome_cdn/helpers/include_font_awesome.rb
|
|
49
50
|
- lib/fontawesome_cdn/railtie.rb
|
|
@@ -73,5 +74,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
74
|
requirements: []
|
|
74
75
|
rubygems_version: 3.7.2
|
|
75
76
|
specification_version: 4
|
|
76
|
-
summary:
|
|
77
|
+
summary: Rails helpers to load Font Awesome via CDN or Kit and render icons in views
|
|
77
78
|
test_files: []
|