ascona 0.1.2 → 0.1.3

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: e552faf28b1003107b30f7a4cfa0463d50eeba70c3d4c54b7cf7da216e4e6a37
4
- data.tar.gz: c920983c5eead44035bf32df7741951778131df9450d66ef256568c2adffb183
3
+ metadata.gz: e82c6a0457f3bf0faf2b1f16d86672d6eea193cb73b52ac8270fb051adc317dc
4
+ data.tar.gz: 8e1c0d4150d0f02189a08b4b6df7e7ba73b9e1ef6938d18f53d9104cc27e86ba
5
5
  SHA512:
6
- metadata.gz: 815c00c080456a6bfcf54a85104e91cd702f80f784b856a9398e3630245a9e30cf7e7a2d9141988566f8f71337ecc4d4a92be487d835acfef8cb8078232e1d0b
7
- data.tar.gz: 276f173cd17cb4a93da418dedebb1fbbe75ccaad00ee14895cebe79b7c35e0c0295e4de6b33e4956e2a97ea77479ce40e90fe53f7871111e4a3efc7438cc7a41
6
+ metadata.gz: 238499050f9d7ad71f179273f6b43dab26e792486f5f0c01fa63bc0ab0e1ffc6989803639483c6679ad4ff302a6fd5e828379d8a6d269879e87e0ff6687a8e3e
7
+ data.tar.gz: 288b759f528fdd142c5fc33c83ed327869d883fffb5025c4ec42c1b141314c4a3a658f84a2768cc71b7d21e3d03271056d6a4221623c58f474f3889f80dcfff8
data/README.md CHANGED
@@ -93,6 +93,19 @@ config.default_variants = { heroicons: :outline }
93
93
 
94
94
  Note: Some libraries have no default variant. You must specify one when downloading (`--variant=outline`) and when rendering (`variant: :outline`) unless set in config.
95
95
 
96
+ ## External Mode
97
+
98
+ By default, icons are inlined as SVG markup. For pages with many icons, use `external: true` to render `<img>` tags instead. This keeps the HTML lightweight and lets the browser cache icons individually.
99
+
100
+ ```erb
101
+ <%= icon "star", external: true %>
102
+ <%= icon "ch", library: :flags, external: true, class: "h-8 w-8" %>
103
+ ```
104
+
105
+ External mode uses Rails' `image_path`, so icons are automatically served from your configured `asset_host` (e.g. a CDN).
106
+
107
+ **Tradeoff:** External icons can't be styled with CSS properties like `currentColor`. Use inline (default) for UI icons that need to match text color, and external for decorative icons like flags.
108
+
96
109
  ## Non-Rails
97
110
 
98
111
  Include the helper manually:
data/lib/ascona/helper.rb CHANGED
@@ -2,26 +2,37 @@
2
2
 
3
3
  module Ascona
4
4
  module Helper
5
- def icon(name, library: nil, variant: nil, size: nil, **attributes)
5
+ def icon(name, library: nil, variant: nil, size: nil, external: false, **attributes)
6
6
  library ||= Ascona.configuration.default_library
7
7
  raise ArgumentError, "No library specified and no default set" unless library
8
8
 
9
- variant ||= Ascona.configuration.default_variants[library.to_sym]
10
- svg = Ascona.registry.get(name.to_sym, library: library.to_sym, variant: variant)
11
- raise ArgumentError, "Icon '#{name}' not found in library '#{library}'" unless svg
12
-
13
9
  size ||= Ascona.configuration.default_size
14
10
  if size
15
11
  size_class = "w-#{size} h-#{size}"
16
12
  attributes[:class] = attributes[:class] ? "#{attributes[:class]} #{size_class}" : size_class
17
13
  end
18
14
 
15
+ if external
16
+ return icon_external(name, library: library, variant: variant, **attributes)
17
+ end
18
+
19
+ variant ||= Ascona.configuration.default_variants[library.to_sym]
20
+ svg = Ascona.registry.get(name.to_sym, library: library.to_sym, variant: variant)
21
+ raise ArgumentError, "Icon '#{name}' not found in library '#{library}'" unless svg
22
+
19
23
  svg = inject_attributes(svg, attributes) unless attributes.empty?
20
24
  svg.html_safe
21
25
  end
22
26
 
23
27
  private
24
28
 
29
+ def icon_external(name, library:, variant: nil, **attributes)
30
+ path = variant ? "#{library}/#{variant}/#{name}.svg" : "#{library}/#{name}.svg"
31
+ attributes[:alt] ||= name.to_s
32
+ attributes[:src] = image_path(path)
33
+ tag.img(**attributes)
34
+ end
35
+
25
36
  def inject_attributes(svg, attributes)
26
37
  attrs_string = attributes.map { |k, v| %(#{k.to_s.gsub("_", "-")}="#{v}") }.join(" ")
27
38
  svg.sub("<svg", "<svg #{attrs_string}")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ascona
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuenti
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 4.0.3
72
+ rubygems_version: 4.0.6
73
73
  specification_version: 4
74
74
  summary: Use SVG icons in Ruby
75
75
  test_files: []