fontawesome_cdn 0.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 +7 -0
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +76 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +12 -0
- data/lib/fontawesome_cdn/helpers.rb +96 -0
- data/lib/fontawesome_cdn/railtie.rb +15 -0
- data/lib/fontawesome_cdn/version.rb +6 -0
- data/lib/fontawesome_cdn.rb +9 -0
- data/sig/fontawesome_cdn.rbs +4 -0
- metadata +71 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f0227d9efe942dd8a799b7f22bf81e8e90ac47d3f9b2ffe86b1fe71ff2bb80c5
|
|
4
|
+
data.tar.gz: 26af6254b9978d1a289ec4c2de04db8b997e895cf2589aa3f69a3133d6596dbb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 341e6dfd4d3ce75275d8a7b8ada5e53705776feb01ac925c680c9fdcca2c2909a28cc242050b3c75e1596922489edaa122eb4b64c3b983c2709a08fddefdac7c
|
|
7
|
+
data.tar.gz: 64c3662608445300d8b8c0840af73fee0a246ccab95b94794c8574b9d740e07e608b682ad054fddbd908675c52e2053210f6b98788df462c41bb06ee3769427c
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
This project follows [Semantic Versioning](https://semver.org).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Initial release
|
|
13
|
+
- Rails helper to load Font Awesome from cdnjs with SRI integrity
|
|
14
|
+
- Explicit Font Awesome version selection
|
|
15
|
+
- `icon` helper to render Font Awesome icons in Rails views
|
|
16
|
+
- Support for Font Awesome 7
|
|
17
|
+
- Compatibility with Rails 7 and Rails 8
|
|
18
|
+
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Contributing to FontawesomeCdn
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! ๐
|
|
4
|
+
This project aims to stay **simple, explicit, and focused**.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## โ
Philosophy
|
|
9
|
+
|
|
10
|
+
Before opening a pull request, please keep in mind:
|
|
11
|
+
|
|
12
|
+
- The gem must remain **small**
|
|
13
|
+
- No asset pipeline integration
|
|
14
|
+
- No JavaScript
|
|
15
|
+
- No configuration complexity
|
|
16
|
+
- CDN-based usage only
|
|
17
|
+
|
|
18
|
+
If a change adds complexity without clear value, it will likely be declined.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## ๐ Development setup
|
|
23
|
+
|
|
24
|
+
Clone the repository and install dependencies:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bundle install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Run the test suite:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
bundle exec rspec
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Run the linter:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bundle exec rubocop
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
All checks **must be green** before submitting a pull request.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## โ
Tests
|
|
47
|
+
|
|
48
|
+
- New features must include tests
|
|
49
|
+
- Bug fixes should include a regression test
|
|
50
|
+
- RSpec is used for testing
|
|
51
|
+
- RuboCop must pass with no offenses
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## ๐ฆ Supported versions
|
|
56
|
+
|
|
57
|
+
- Ruby: **3.0+**
|
|
58
|
+
- Rails: **7.x and 8.x**
|
|
59
|
+
- Font Awesome: supported versions listed in the README
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ๐ Pull requests
|
|
64
|
+
|
|
65
|
+
When submitting a pull request:
|
|
66
|
+
|
|
67
|
+
1. Keep changes small and focused
|
|
68
|
+
2. Explain the **why**, not just the **what**
|
|
69
|
+
3. Ensure CI passes
|
|
70
|
+
4. Update documentation if needed
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## ๐งพ License
|
|
75
|
+
|
|
76
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 OpenCodeForge
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# ๐จ FontawesomeCdn
|
|
2
|
+
|
|
3
|
+
[](https://github.com/OpenCodeForge/fontawesome_cdn/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
Simple Rails helpers to load **Font Awesome via CDN** and render icons in views.
|
|
6
|
+
|
|
7
|
+
โ
Compatible with **Font Awesome 7**
|
|
8
|
+
โ
Compatible with **Rails 8**
|
|
9
|
+
โ
No asset pipeline
|
|
10
|
+
โ
No JavaScript
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐ฆ Installation
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "fontawesome_cdn"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ๐ Usage
|
|
28
|
+
|
|
29
|
+
### Load Font Awesome (layout)
|
|
30
|
+
|
|
31
|
+
Place this helper in your layout, inside `<head>`.
|
|
32
|
+
|
|
33
|
+
```erb
|
|
34
|
+
<%= fontawesome_cdn_stylesheet_tag "7.0.1" %>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
### Render icons (views)
|
|
40
|
+
|
|
41
|
+
Use this helper anywhere in your views or partials.
|
|
42
|
+
|
|
43
|
+
```erb
|
|
44
|
+
<%= icon "fa-solid", "user" %>
|
|
45
|
+
<%= icon "fa-regular", "bell", class: "fa-2x" %>
|
|
46
|
+
<%= icon "fa-brands", "font-awesome", "Font Awesome" %>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## โ
Supported Font Awesome versions
|
|
52
|
+
|
|
53
|
+
Font Awesome is loaded directly from **cdnjs**.
|
|
54
|
+
|
|
55
|
+
**Supported versions** (with verified SRI):
|
|
56
|
+
|
|
57
|
+
- โ
**7.0.1**
|
|
58
|
+
- โ
**7.0.0**
|
|
59
|
+
- โ
**6.7.2**
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ๐ License
|
|
64
|
+
|
|
65
|
+
MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FontawesomeCdn
|
|
4
|
+
BASE_URL = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome"
|
|
5
|
+
|
|
6
|
+
# Font Awesome versions supported by the gem
|
|
7
|
+
# SRI hashes provided by cdnjs for all.min.css
|
|
8
|
+
INTEGRITY_MAP = {
|
|
9
|
+
"7.0.1" => "sha512-2SwdPD6INVrV/lHTZbO2nodKhrnDdJK9/kg2XD1r9uGqPo1cUbujc+IYdlYdEErWNu69gVcYgdxlmVmzTWnetw==",
|
|
10
|
+
"7.0.0" => "sha512-DxV+EoADOkOygM4IR9yXP8Sb2qwgidEmeqAEmDKIOfPRQZOWbXCzLC6vjbZyy0vPisbH2SyW27+ddLVCN+OMzQ==",
|
|
11
|
+
"6.7.2" => "sha512-Evv84Mr4kqVGRNSgIGL/F/aIDqQb7xQ2vcrdIwxfjThSH8CSR7PBEakCr51Ck+w+/U6swU2Im1vVX0SVk9ABhg=="
|
|
12
|
+
}.freeze
|
|
13
|
+
|
|
14
|
+
SUPPORTED_VERSIONS = INTEGRITY_MAP.keys.freeze
|
|
15
|
+
|
|
16
|
+
# Helpers exposed to Rails views.
|
|
17
|
+
#
|
|
18
|
+
# Provides:
|
|
19
|
+
# - fontawesome_cdn_stylesheet_tag(version)
|
|
20
|
+
# - icon(style, name, text = nil, html_options = {})
|
|
21
|
+
module Helpers
|
|
22
|
+
# Stylesheet helper for loading Font Awesome via CDN
|
|
23
|
+
#
|
|
24
|
+
# Usage:
|
|
25
|
+
#
|
|
26
|
+
# <%= fontawesome_cdn_stylesheet_tag "7.0.1" %>
|
|
27
|
+
#
|
|
28
|
+
# Raises ArgumentError if version is not supported.
|
|
29
|
+
#
|
|
30
|
+
def fontawesome_cdn_stylesheet_tag(version = nil, **options)
|
|
31
|
+
validate_fontawesome_version!(version)
|
|
32
|
+
|
|
33
|
+
href = "#{FontawesomeCdn::BASE_URL}/#{version}/css/all.min.css"
|
|
34
|
+
|
|
35
|
+
attrs = {
|
|
36
|
+
rel: "stylesheet",
|
|
37
|
+
href: href,
|
|
38
|
+
integrity: FontawesomeCdn::INTEGRITY_MAP[version],
|
|
39
|
+
crossorigin: "anonymous",
|
|
40
|
+
referrerpolicy: "no-referrer"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
tag.link(**attrs, **options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Main helper for displaying an icon
|
|
47
|
+
#
|
|
48
|
+
# <%= icon "fa-solid", "user" %>
|
|
49
|
+
# <%= icon "fa-regular", "bell", class: "fa-2x fa-shake" %>
|
|
50
|
+
# <%= icon "fa-brands", "font-awesome", "Font Awesome" %>
|
|
51
|
+
# <%= icon "fa-solid", "check", "aria-hidden": false %>
|
|
52
|
+
#
|
|
53
|
+
def icon(style, name, text = nil, html_options = {})
|
|
54
|
+
if text.is_a?(Hash)
|
|
55
|
+
html_options = text
|
|
56
|
+
text = nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
classes = [style, "fa-#{name}", html_options[:class]].compact
|
|
60
|
+
html_options[:class] = classes.join(" ")
|
|
61
|
+
html_options["aria-hidden"] ||= true
|
|
62
|
+
|
|
63
|
+
icon_tag = tag.i(nil, **html_options)
|
|
64
|
+
|
|
65
|
+
text.blank? ? icon_tag : safe_join([icon_tag, " ", text.to_s])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def validate_fontawesome_version!(version)
|
|
71
|
+
raise_version_required_error if version.nil?
|
|
72
|
+
raise_version_type_error(version) unless version.is_a?(String)
|
|
73
|
+
raise_version_not_supported_error(version) unless FontawesomeCdn::SUPPORTED_VERSIONS.include?(version)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def raise_version_required_error
|
|
77
|
+
raise ArgumentError, <<~MSG
|
|
78
|
+
fontawesome_cdn: Font Awesome version is required.
|
|
79
|
+
Usage: <%= fontawesome_cdn_stylesheet_tag "7.x.x" %>
|
|
80
|
+
MSG
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def raise_version_type_error(version)
|
|
84
|
+
raise ArgumentError, <<~MSG
|
|
85
|
+
fontawesome_cdn: version must be a String, got #{version.class}
|
|
86
|
+
MSG
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def raise_version_not_supported_error(version)
|
|
90
|
+
raise ArgumentError, <<~MSG
|
|
91
|
+
fontawesome_cdn: Font Awesome version #{version.inspect} is not supported.
|
|
92
|
+
Supported versions: #{FontawesomeCdn::SUPPORTED_VERSIONS.join(", ")}
|
|
93
|
+
MSG
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/railtie"
|
|
4
|
+
require "fontawesome_cdn/helpers"
|
|
5
|
+
|
|
6
|
+
module FontawesomeCdn
|
|
7
|
+
# Railtie for loading FontawesomeCdn helpers into Rails.
|
|
8
|
+
class Railtie < ::Rails::Railtie
|
|
9
|
+
initializer "fontawesome_cdn.view_helpers" do
|
|
10
|
+
ActiveSupport.on_load(:action_view) do
|
|
11
|
+
include FontawesomeCdn::Helpers
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fontawesome_cdn
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- OpenCodeForge
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: railties
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
description: |
|
|
27
|
+
Tiny Rails helpers to load Font Awesome via CDN and render icons.
|
|
28
|
+
No asset pipeline integration, no JavaScript, no magic.
|
|
29
|
+
email:
|
|
30
|
+
- contact@opencodeforge.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- CONTRIBUTING.md
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- lib/fontawesome_cdn.rb
|
|
41
|
+
- lib/fontawesome_cdn/helpers.rb
|
|
42
|
+
- lib/fontawesome_cdn/railtie.rb
|
|
43
|
+
- lib/fontawesome_cdn/version.rb
|
|
44
|
+
- sig/fontawesome_cdn.rbs
|
|
45
|
+
homepage: https://github.com/OpenCodeForge/fontawesome_cdn
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
metadata:
|
|
49
|
+
homepage_uri: https://github.com/OpenCodeForge/fontawesome_cdn
|
|
50
|
+
source_code_uri: https://github.com/OpenCodeForge/fontawesome_cdn
|
|
51
|
+
bug_tracker_uri: https://github.com/OpenCodeForge/fontawesome_cdn/issues
|
|
52
|
+
changelog_uri: https://github.com/OpenCodeForge/fontawesome_cdn/blob/main/CHANGELOG.md
|
|
53
|
+
rubygems_mfa_required: 'true'
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
requirements: []
|
|
68
|
+
rubygems_version: 3.7.2
|
|
69
|
+
specification_version: 4
|
|
70
|
+
summary: Simple Rails helpers to load Font Awesome from a CDN.
|
|
71
|
+
test_files: []
|