railsglyphs 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a23c4b18acfe00c2a6486291700489bd80156bf929e6dea279593f62256c67c
4
+ data.tar.gz: 59d535e3009fe32d8d4fb20b7613b245f25287b1f450704b69ba91763ceabdff
5
+ SHA512:
6
+ metadata.gz: b2754fe87b0c34d7f285118442234a2749082a368bac6a730d18832652218115b9add22d225c35dbfdb522888b1dc3cc90b3942ebc46ab0e4118c04d35968576
7
+ data.tar.gz: b0503a41316ea08a90495f06c64c7197e295142fcecd04f0533b565175bf884dcf6c194399a173f6e2ef0d9facfcfb04b45afa2265fb82ec992cb9cdffed2c17
@@ -0,0 +1,49 @@
1
+ require "erb"
2
+ require 'digest'
3
+
4
+ module Railsglyphs
5
+ module IconHelper
6
+ ICON_CACHE = {}
7
+
8
+ # Returns the absolute path to the gem's asset directory
9
+ def self.gem_asset_path
10
+ File.expand_path("../../assets/icons", __dir__)
11
+ end
12
+
13
+ # Optionally allow the icon path to be overridden in the host app
14
+ def self.icon_base_path
15
+ @icon_base_path || gem_asset_path
16
+ end
17
+
18
+ def self.icon_base_path=(path)
19
+ @icon_base_path = path
20
+ end
21
+
22
+ def icon(style, name, text = nil, html_options = {})
23
+ text, html_options = nil, text if text.is_a?(Hash)
24
+ height = html_options[:size] || 24
25
+ width = html_options[:size] || 24
26
+ html_options.delete(:size)
27
+
28
+ svg_path = File.join(Railsglyphs::IconHelper.icon_base_path, style.to_s, "#{name}.svg")
29
+ raise ArgumentError, "Icon '#{name}' with style '#{style}' not found at #{svg_path}." unless File.exist?(svg_path)
30
+
31
+ cache_key = "#{style}-#{name}-#{Digest::MD5.hexdigest(text.to_s)}-#{height}-#{width}"
32
+
33
+ svg_content = ICON_CACHE[cache_key] ||= begin
34
+ svg = File.read(svg_path)
35
+ svg.gsub!("<svg", "<svg style=\"display: inline-block;\" height=\"#{height}\" width=\"#{width}\"")
36
+ svg.html_safe
37
+ end
38
+
39
+ if html_options[:class]
40
+ html_options[:class] = html_options[:class].strip
41
+ end
42
+ html_options['aria-hidden'] ||= true
43
+
44
+ html = content_tag(:i, svg_content, html_options)
45
+ html << ' ' << text.to_s unless text.blank?
46
+ html
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require "rails/railtie"
2
+
3
+ module Railsglyphs
4
+ class Railtie < Rails::Railtie
5
+ initializer "railsglyphs.helpers" do
6
+ ActiveSupport.on_load(:action_view) do
7
+ include Railsglyphs::IconHelper
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsGlyphs
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "railsglyphs/version"
4
+ require "railsglyphs/icon_helper"
5
+ require "railsglyphs/railtie" if defined?(Rails)
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railsglyphs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor S. Keenan
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-06-05 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '6.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
26
+ description: Simple helper utility for using SVG icons within your Rails project.
27
+ email:
28
+ - me@victorkeenan.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/railsglyphs.rb
34
+ - lib/railsglyphs/icon_helper.rb
35
+ - lib/railsglyphs/railtie.rb
36
+ - lib/railsglyphs/version.rb
37
+ homepage: https://www.victorkeenan.com/projects/railsglyphs/
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://www.victorkeenan.com/projects/railsglyphs/
42
+ source_code_uri: https://github.com/VictorSK/railsglyphs/
43
+ changelog_uri: https://github.com/VictorSK/railsglyphs/blob/main/CHANGELOG.md
44
+ rubygems_mfa_required: 'true'
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.6.3
60
+ specification_version: 4
61
+ summary: Simple helper utility for using SVG icons within your Rails project.
62
+ test_files: []