fontawesome_cdn 0.3.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9b8e3919d1d4dcb36bf6a9bb3e9f5def25c525492794326c1a85a0b589eacda
4
- data.tar.gz: c1ba2a30811e630037485f5a0b5e48bf182f73602e9f8ba46f4a7f64c4b00d46
3
+ metadata.gz: 17a69f882df20af599d2070ad9249f1759d14fc0b14bea47c109b0a15d157d0e
4
+ data.tar.gz: 187ff7f8c50fd6edaa022217c4d526ee63f447cd46590b2f037bd76f988189e9
5
5
  SHA512:
6
- metadata.gz: d53ec45865ff84d2f644f74153078ad9245d9de09fedd107ba533431a25d20c05ce5ad5390886ee84a3285678db9f9b8a87d17354f7e331f5a4f1b8d303d390a
7
- data.tar.gz: a28fb12557609a8f5be06f0a9a9f1dc6b4689d971a367145720eee27b1ed57c5b2d31da1cdd49d6b7e234fc894a854dac52e1bd1fd43ef3e4058d3f6c5a0fde9
6
+ metadata.gz: c71799ae50fc7baf58f5057d58e96f047f079fff04ce4a97bc919b3769c4e3ba8a401c07cc1280980e2d0e2583246a3589c71184da9d6f736fddcf9e10dc0fda
7
+ data.tar.gz: de8a29cdc724e752652a6f116ed0010ad76eff35952a810b343b71eeaf22d87ff759937b6c9a1a9734c025e8b10ebce2d8391baac9a4dcac59ae63eb6ca749c7
data/CHANGELOG.md CHANGED
@@ -6,6 +6,42 @@ This project follows [Semantic Versioning](https://semver.org).
6
6
 
7
7
  ---
8
8
 
9
+ ## 1.0.0
10
+
11
+ This release marks the **first stable version** of FontawesomeCdn.
12
+ The public API is now considered stable and will follow Semantic Versioning.
13
+
14
+ ### Changed
15
+ - Stabilized the `icon` helper API with a fully class-based approach.
16
+ - Removed legacy `style:` and `pack:` options in favor of direct Font Awesome classes.
17
+ - Default family and style are now applied automatically via configuration.
18
+ - The `classic` family is implicit and no longer rendered as `fa-classic`.
19
+ - When using the `brands` family, no style class is automatically injected.
20
+
21
+ ### Added
22
+ - Added `fa:` option as a convenience shortcut to pass space-separated Font Awesome tokens
23
+ (automatically prefixed with `fa-`).
24
+ - Added global configuration options:
25
+ - `default_family`
26
+ - `default_style`
27
+ - `default_aria_hidden`
28
+
29
+ ### Examples
30
+ ```erb
31
+ <%= icon "user" %>
32
+ <%= icon "gear", "Settings" %>
33
+ <%= icon "bell", class: "fa-regular fa-2x fa-shake" %>
34
+ <%= icon "bell", fa: "regular 2x shake" %>
35
+ <%= icon "github", "Source code", fa: "brands", class: "link" %>
36
+ ```
37
+
38
+ ### Notes
39
+ - No validation or conflict resolution is applied when multiple styles or families are provided.
40
+ - Users are free to combine classes as needed for experimentation or advanced use cases.
41
+ - Versions prior to `1.0.0` should be considered experimental.
42
+
43
+ ---
44
+
9
45
  ## 0.3.0
10
46
 
11
47
  ### Changed
data/README.md CHANGED
@@ -27,9 +27,9 @@ bundle install
27
27
 
28
28
  ## 🚀 Usage
29
29
 
30
- ## 1️⃣ Load Font Awesome in your layout
30
+ ### 1️⃣ Load Font Awesome (in your layout)
31
31
 
32
- ### **Option A — Load from cdnjs (Font Awesome Free)**
32
+ #### **Option A — Load from cdnjs (Font Awesome Free)**
33
33
 
34
34
  Place inside your `<head>`:
35
35
 
@@ -45,7 +45,7 @@ This generates:
45
45
 
46
46
  ---
47
47
 
48
- ### **Option B — Load a Font Awesome Kit (supports Pro)**
48
+ #### **Option B — Load a Font Awesome Kit (supports Pro)**
49
49
 
50
50
  If you have a Font Awesome Pro subscription, you can load your Kit:
51
51
 
@@ -64,23 +64,47 @@ This generates:
64
64
 
65
65
  ---
66
66
 
67
- ## 2️⃣ Render icons in views
67
+ ### 2️⃣ Render icons (in views)
68
+
69
+ Basic usage:
68
70
 
69
71
  ```erb
70
72
  <%= icon "user" %>
71
73
  <%= icon "gear", "Settings" %>
72
- <%= icon "trash-can", "Delete", style: :regular %>
73
- <%= icon "github", pack: :brands, class: "fa-2x fa-shake" %>
74
+ <%= icon "bell", class: "fa-regular fa-2x fa-shake" %>
75
+ ```
76
+
77
+ #### Using the `fa:` shortcut
78
+
79
+ For convenience, you can use the `fa:` option to pass **space-separated Font Awesome tokens**, automatically prefixed with `fa-`.
80
+
81
+ ```erb
82
+ <%= icon "bell", fa: "regular 2x shake" %>
83
+ <%= icon "github", "Source code", fa: "brands", class: "link" %>
84
+ ```
85
+
86
+ ---
87
+
88
+ ## ⚙️ Configuration
89
+
90
+ FontawesomeCdn allows you to define default icon behavior that will be **automatically applied to all icons**, unless explicitly overridden at render time.
91
+
92
+ ```rb
93
+ # config/initializers/fontawesome_cdn.rb
94
+ FontawesomeCdn.configure do |config|
95
+ config.default_family = "classic"
96
+ config.default_style = "solid"
97
+ config.default_aria_hidden = true
98
+ end
74
99
  ```
75
100
 
76
- ### Options
101
+ By default, these settings are used to determine which Font Awesome family and style are added to each icon.
102
+ If a family or style is explicitly provided via `class:` or `fa:`, it will be used instead of the defaults.
77
103
 
78
- | Option | Description |
79
- |--------|-------------|
80
- | `style:` | `:solid`, `:regular`, `:light`, `:thin`, `:semibold` (default: `:solid`) |
81
- | `pack:` | Use `:brands` when using Font Awesome Brands |
82
- | `class:` | Additional CSS classes |
83
- | `aria-hidden:` | Passed as-is |
104
+ Defaults:
105
+ - `classic` is implicit (no `fa-classic`)
106
+ - default style is injected automatically
107
+ - `brands` does not inject a style
84
108
 
85
109
  ---
86
110
 
@@ -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
- ICON_STYLES = %w[solid regular light thin semibold].freeze
7
- DEFAULT_ICON_STYLE = "solid"
6
+ FAMILIES = %w[
7
+ classic duotone sharp sharp-duotone brands chisel etch jelly notdog slab
8
+ thumbprint utility whiteboard
9
+ ].freeze
8
10
 
9
- # Main helper for displaying an icon
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 "trash-can", "Delete", style: :regular %>
14
- # <%= icon "github", pack: :brands, class: "fa-2x fa-shake" %>
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,48 @@ module FontawesomeCdn
20
40
  text = nil
21
41
  end
22
42
 
23
- pack_class, style_class = build_pack_and_style_classes(options)
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
- options[:class] = [pack_class, style_class, "fa-#{name}", options[:class]].compact.join(" ")
26
- options["aria-hidden"] = true unless options.key?("aria-hidden") || options.key?(:"aria-hidden")
50
+ class_tokens = options.delete(:class).to_s.split
51
+ fa_tokens = options.delete(:fa).to_s.split.map { |t| "fa-#{t}" }
27
52
 
28
- icon_tag = tag.i(nil, **options)
53
+ tokens = (class_tokens + fa_tokens).uniq
29
54
 
30
- text.nil? || text.to_s.strip.empty? ? icon_tag : safe_join([icon_tag, " ", text.to_s])
31
- end
55
+ family = tokens
56
+ .map { |t| t.delete_prefix("fa-") }
57
+ .find { |t| FAMILIES.include?(t) } || FontawesomeCdn.configuration.default_family.to_s
32
58
 
33
- private
59
+ style = tokens
60
+ .map { |t| t.delete_prefix("fa-") }
61
+ .find { |t| STYLES.include?(t) } || FontawesomeCdn.configuration.default_style.to_s
34
62
 
35
- # Classes:
36
- # - style → fa-solid / fa-regular / ...
37
- # - pack → fa-brands / ...
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"
63
+ # remove family + style from tokens so they can't reappear later
64
+ tokens.delete("fa-#{family}")
65
+ tokens.delete("fa-#{style}")
43
66
 
44
- validate_icon_style_and_pack!(style, pack)
67
+ classes = []
68
+ classes << "fa-#{family}" unless family == "classic"
69
+ classes << "fa-#{style}" unless family == "brands"
70
+ classes << "fa-#{name}"
71
+ classes.concat(tokens)
45
72
 
46
- [pack, style].compact.map { |c| "fa-#{c}" }
47
- end
73
+ icon_tag = content_tag(:i, nil, class: classes.uniq.join(" "), "aria-hidden": aria_hidden)
74
+ return icon_tag if text.nil? || text.to_s.empty?
48
75
 
49
- #
50
- # Icon validation
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)
76
+ safe_join([icon_tag, ERB::Util.html_escape(text.to_s)], " ")
55
77
  end
56
78
 
57
- def raise_style_used_as_pack_error(pack)
58
- raise ArgumentError, <<~MSG
59
- fontawesome_cdn: #{pack.inspect} is a style, not a pack.
60
- Use style: #{pack.inspect} instead.
61
- MSG
62
- end
79
+ private
63
80
 
64
- def raise_unsupported_icon_style_error(style)
65
- raise ArgumentError, <<~MSG
66
- fontawesome_cdn: unsupported icon style #{style.inspect}.
67
- Supported styles: #{ICON_STYLES.join(", ")}
68
- MSG
81
+ def extract_family_and_style(tokens)
82
+ family = tokens.find { |t| FAMILIES.include?(t) }
83
+ style = tokens.find { |t| STYLES.include?(t) }
84
+ [family, style]
69
85
  end
70
86
  end
71
87
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Current version of the FontawesomeCdn gem.
4
4
  module FontawesomeCdn
5
- VERSION = "0.3.0"
5
+ VERSION = "1.0.0"
6
6
  end
@@ -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: 0.3.0
4
+ version: 1.0.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
- Provides Rails view helpers to load Font Awesome either from cdnjs or from official
34
- Font Awesome Kits (including Pro), along with a clean icon helper.
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: Simple Rails helpers to load Font Awesome (Free or Pro Kit) via CDN.
77
+ summary: Rails helpers to load Font Awesome via CDN or Kit and render icons in views
77
78
  test_files: []