ascona 0.1.1 → 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 +4 -4
- data/.github/workflows/push_gem.yml +28 -0
- data/README.md +25 -1
- data/lib/ascona/configuration.rb +2 -1
- data/lib/ascona/helper.rb +18 -1
- data/lib/ascona/version.rb +1 -1
- data/lib/generators/ascona/templates/initializer.rb +3 -0
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e82c6a0457f3bf0faf2b1f16d86672d6eea193cb73b52ac8270fb051adc317dc
|
|
4
|
+
data.tar.gz: 8e1c0d4150d0f02189a08b4b6df7e7ba73b9e1ef6938d18f53d9104cc27e86ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 238499050f9d7ad71f179273f6b43dab26e792486f5f0c01fa63bc0ab0e1ffc6989803639483c6679ad4ff302a6fd5e828379d8a6d269879e87e0ff6687a8e3e
|
|
7
|
+
data.tar.gz: 288b759f528fdd142c5fc33c83ed327869d883fffb5025c4ec42c1b141314c4a3a658f84a2768cc71b7d21e3d03271056d6a4221623c58f474f3889f80dcfff8
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Push Gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- v*
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
push:
|
|
13
|
+
if: github.repository == 'samuenti/ascona'
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: write
|
|
18
|
+
id-token: write
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- name: Set up Ruby
|
|
23
|
+
uses: ruby/setup-ruby@v1
|
|
24
|
+
with:
|
|
25
|
+
bundler-cache: true
|
|
26
|
+
ruby-version: ruby
|
|
27
|
+
|
|
28
|
+
- uses: rubygems/release-gem@v1
|
data/README.md
CHANGED
|
@@ -66,11 +66,22 @@ The name of the folder will be used as the library name.
|
|
|
66
66
|
|
|
67
67
|
```erb
|
|
68
68
|
<%= icon "star" %>
|
|
69
|
+
<%= icon "star", size: 5 %>
|
|
69
70
|
<%= icon "star", class: "w-5 h-5" %>
|
|
70
71
|
<%= icon "star", library: :heroicons, variant: :outline %>
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
The `size` option adds Tailwind classes `w-{size} h-{size}`.
|
|
75
|
+
|
|
76
|
+
## Default Size
|
|
77
|
+
|
|
78
|
+
Set a default size for all icons:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
config.default_size = 5
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Icons without an explicit `size` will use this default.
|
|
74
85
|
|
|
75
86
|
## Variants
|
|
76
87
|
|
|
@@ -82,6 +93,19 @@ config.default_variants = { heroicons: :outline }
|
|
|
82
93
|
|
|
83
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.
|
|
84
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
|
+
|
|
85
109
|
## Non-Rails
|
|
86
110
|
|
|
87
111
|
Include the helper manually:
|
data/lib/ascona/configuration.rb
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
module Ascona
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor :icon_path, :default_library, :default_variants
|
|
5
|
+
attr_accessor :icon_path, :default_library, :default_variants, :default_size
|
|
6
6
|
|
|
7
7
|
def initialize
|
|
8
8
|
@icon_path = "app/assets/icons"
|
|
9
9
|
@default_library = nil
|
|
10
10
|
@default_variants = {}
|
|
11
|
+
@default_size = nil
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
data/lib/ascona/helper.rb
CHANGED
|
@@ -2,10 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
module Ascona
|
|
4
4
|
module Helper
|
|
5
|
-
def icon(name, library: nil, variant: 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
|
+
size ||= Ascona.configuration.default_size
|
|
10
|
+
if size
|
|
11
|
+
size_class = "w-#{size} h-#{size}"
|
|
12
|
+
attributes[:class] = attributes[:class] ? "#{attributes[:class]} #{size_class}" : size_class
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
if external
|
|
16
|
+
return icon_external(name, library: library, variant: variant, **attributes)
|
|
17
|
+
end
|
|
18
|
+
|
|
9
19
|
variant ||= Ascona.configuration.default_variants[library.to_sym]
|
|
10
20
|
svg = Ascona.registry.get(name.to_sym, library: library.to_sym, variant: variant)
|
|
11
21
|
raise ArgumentError, "Icon '#{name}' not found in library '#{library}'" unless svg
|
|
@@ -16,6 +26,13 @@ module Ascona
|
|
|
16
26
|
|
|
17
27
|
private
|
|
18
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
|
+
|
|
19
36
|
def inject_attributes(svg, attributes)
|
|
20
37
|
attrs_string = attributes.map { |k, v| %(#{k.to_s.gsub("_", "-")}="#{v}") }.join(" ")
|
|
21
38
|
svg.sub("<svg", "<svg #{attrs_string}")
|
data/lib/ascona/version.rb
CHANGED
|
@@ -6,4 +6,7 @@ Ascona.configure do |config|
|
|
|
6
6
|
|
|
7
7
|
# Set default variants per library (only for libraries with variants):
|
|
8
8
|
# config.default_variants = { heroicons: :outline }
|
|
9
|
+
|
|
10
|
+
# Set default size for all icons (uses Tailwind classes w-{size} h-{size}):
|
|
11
|
+
# config.default_size = 5
|
|
9
12
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ascona
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuenti
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: thor
|
|
@@ -32,6 +31,7 @@ executables:
|
|
|
32
31
|
extensions: []
|
|
33
32
|
extra_rdoc_files: []
|
|
34
33
|
files:
|
|
34
|
+
- ".github/workflows/push_gem.yml"
|
|
35
35
|
- LICENSE.txt
|
|
36
36
|
- README.md
|
|
37
37
|
- Rakefile
|
|
@@ -55,7 +55,6 @@ metadata:
|
|
|
55
55
|
homepage_uri: https://github.com/samuenti/ascona
|
|
56
56
|
source_code_uri: https://github.com/samuenti/ascona
|
|
57
57
|
rubygems_mfa_required: 'true'
|
|
58
|
-
post_install_message:
|
|
59
58
|
rdoc_options: []
|
|
60
59
|
require_paths:
|
|
61
60
|
- lib
|
|
@@ -70,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
70
69
|
- !ruby/object:Gem::Version
|
|
71
70
|
version: '0'
|
|
72
71
|
requirements: []
|
|
73
|
-
rubygems_version:
|
|
74
|
-
signing_key:
|
|
72
|
+
rubygems_version: 4.0.6
|
|
75
73
|
specification_version: 4
|
|
76
74
|
summary: Use SVG icons in Ruby
|
|
77
75
|
test_files: []
|