ascona 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8287078537d984be67b63cfdce58534dbe6614bb5c917c8051caa4b9ee6183f4
4
+ data.tar.gz: 1393e656146786b20803a5723a2df72568bb32e1a5da3259e869e7f282b7ad1d
5
+ SHA512:
6
+ metadata.gz: e7aa21e79c9d161f1be827e30920842e8d7caf7425fa79cc27b593228a7b5f94259fd910cfba83144df8403da8efdef82fa735a4f9dfe9e6c492701e65a4c256
7
+ data.tar.gz: f7acf773a8c162fed5170d03efb7026b9a013734c6bfce73aea2bef1e91677d51b6e83c40a5ba18703beffe0e09059d1903e4c7e4f649cff3074869479b5115d
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Samuenti
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,97 @@
1
+ # Ascona
2
+
3
+ Use SVG icons in Ruby.
4
+
5
+ Ascona loads your SVG icons into memory at boot. Fast lookups, simple helper.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'ascona'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Setup
16
+
17
+ Generate the initializer:
18
+
19
+ ```bash
20
+ rails generate ascona:install
21
+ ```
22
+
23
+ Or create `config/initializers/ascona.rb` manually:
24
+
25
+ ```ruby
26
+ Ascona.configure do |config|
27
+ config.icon_path = "app/assets/icons"
28
+ config.default_library = :lucide
29
+ end
30
+ ```
31
+
32
+ ## Supported Libraries
33
+
34
+ | Library | Link |
35
+ |---------|------|
36
+ | Lucide | [lucide.dev](https://lucide.dev) |
37
+
38
+
39
+ ## Downloading Icons
40
+
41
+ ```bash
42
+ ascona list # Show available libraries
43
+ ascona download lucide # Download all icons
44
+ ascona download heroicons --variant=outline # Download specific variant
45
+ ```
46
+
47
+ ## Folder Structure
48
+
49
+ Each SVG library should be stored in separate folders (create custom libraries by adding a new folder):
50
+
51
+ ```
52
+ app/assets/icons/
53
+ lucide/
54
+ star.svg
55
+ arrow-left.svg
56
+ heroicons/
57
+ outline/
58
+ check.svg
59
+ solid/
60
+ check.svg
61
+ ```
62
+
63
+ The name of the folder will be used as the library name.
64
+
65
+ ## Usage
66
+
67
+ ```erb
68
+ <%= icon "star" %>
69
+ <%= icon "star", class: "w-5 h-5" %>
70
+ <%= icon "star", library: :heroicons, variant: :outline %>
71
+ ```
72
+
73
+ Attributes are added directly to the `<svg>` tag.
74
+
75
+ ## Variants
76
+
77
+ Some libraries have variants. Set defaults per library (for rendering only):
78
+
79
+ ```ruby
80
+ config.default_variants = { heroicons: :outline }
81
+ ```
82
+
83
+ 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
+
85
+ ## Non-Rails
86
+
87
+ Include the helper manually:
88
+
89
+ ```ruby
90
+ include Ascona::Helper
91
+ ```
92
+
93
+ Call `Ascona.load` before using icons.
94
+
95
+ ## License
96
+
97
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/exe/ascona ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ascona"
5
+ require "ascona/cli"
6
+
7
+ Ascona::CLI.start(ARGV)
data/lib/ascona/cli.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "library"
5
+
6
+ module Ascona
7
+ class CLI < Thor
8
+ desc "list", "List available icon libraries"
9
+ def list
10
+ libraries = Library.available
11
+ if libraries.empty?
12
+ puts "No libraries available"
13
+ else
14
+ puts "Available libraries:"
15
+ libraries.each { |lib| puts " - #{lib}" }
16
+ end
17
+ end
18
+
19
+ desc "download LIBRARY", "Download icons from a library"
20
+ option :variant, type: :string, desc: "Download specific variant only"
21
+ def download(library)
22
+ unless Library.available.include?(library)
23
+ puts "Unknown library: #{library}"
24
+ puts "Run 'ascona list' to see available libraries"
25
+ return
26
+ end
27
+
28
+ destination = File.join(Ascona.configuration.icon_path, library)
29
+ puts "Downloading #{library} icons to #{destination}..."
30
+ Library.download(library, destination, variant: options[:variant])
31
+ puts "Done!"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ class Configuration
5
+ attr_accessor :icon_path, :default_library, :default_variants
6
+
7
+ def initialize
8
+ @icon_path = "app/assets/icons"
9
+ @default_library = nil
10
+ @default_variants = {}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ module Helper
5
+ def icon(name, library: nil, variant: nil, **attributes)
6
+ library ||= Ascona.configuration.default_library
7
+ raise ArgumentError, "No library specified and no default set" unless library
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
+ return svg if attributes.empty?
14
+
15
+ inject_attributes(svg, attributes)
16
+ end
17
+
18
+ private
19
+
20
+ def inject_attributes(svg, attributes)
21
+ attrs_string = attributes.map { |k, v| %(#{k.to_s.gsub("_", "-")}="#{v}") }.join(" ")
22
+ svg.sub("<svg", "<svg #{attrs_string}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ module Libraries
5
+ module Lucide
6
+ CONFIG = {
7
+ repo: "lucide-icons/lucide",
8
+ path: "icons",
9
+ branch: "main"
10
+ }.freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "fileutils"
5
+ require "tmpdir"
6
+ require "rubygems/package"
7
+ require "zlib"
8
+
9
+ module Ascona
10
+ module Library
11
+ def self.available
12
+ Dir.glob(File.join(__dir__, "libraries", "*.rb")).map do |f|
13
+ File.basename(f, ".rb")
14
+ end
15
+ end
16
+
17
+ def self.config_for(name)
18
+ require_relative "libraries/#{name}"
19
+ Ascona::Libraries.const_get(name.capitalize)::CONFIG
20
+ end
21
+
22
+ def self.download(name, destination, variant: nil)
23
+ config = config_for(name)
24
+
25
+ Dir.mktmpdir do |tmp_dir|
26
+ extracted_dir = download_and_extract(config, tmp_dir)
27
+ copy_to_destination(config, extracted_dir, destination, variant)
28
+ end
29
+ end
30
+
31
+ def self.download_and_extract(config, tmp_dir)
32
+ tar_path = File.join(tmp_dir, "repo.tar.gz")
33
+ download_tar(config[:repo], config[:branch], tar_path)
34
+ extract_tar(tar_path, tmp_dir)
35
+ Dir.glob(File.join(tmp_dir, "*")).find { |f| File.directory?(f) }
36
+ end
37
+
38
+ def self.copy_to_destination(config, extracted_dir, destination, variant)
39
+ if config[:variants]
40
+ copy_variants(extracted_dir, config[:variants], destination, variant)
41
+ else
42
+ copy_icons(extracted_dir, config[:path], destination)
43
+ end
44
+ end
45
+
46
+ def self.download_tar(repo, branch, tar_path)
47
+ uri = URI("https://github.com/#{repo}/archive/refs/heads/#{branch}.tar.gz")
48
+ response = Net::HTTP.get_response(uri)
49
+ response = Net::HTTP.get_response(URI(response["location"])) while response.is_a?(Net::HTTPRedirection)
50
+ File.binwrite(tar_path, response.body)
51
+ end
52
+
53
+ def self.extract_tar(tar_path, tmp_dir)
54
+ File.open(tar_path, "rb") do |file|
55
+ Zlib::GzipReader.wrap(file) do |gz|
56
+ Gem::Package::TarReader.new(gz) { |tar| extract_entries(tar, tmp_dir) }
57
+ end
58
+ end
59
+ end
60
+
61
+ def self.extract_entries(tar, tmp_dir)
62
+ tar.each do |entry|
63
+ next unless entry.file?
64
+
65
+ path = File.join(tmp_dir, entry.full_name)
66
+ FileUtils.mkdir_p(File.dirname(path))
67
+ File.binwrite(path, entry.read)
68
+ end
69
+ end
70
+
71
+ def self.copy_variants(extracted_dir, variants, destination, only_variant)
72
+ variants.each do |variant_name, variant_path|
73
+ next if only_variant && only_variant != variant_name
74
+
75
+ variant_dest = File.join(destination, variant_name)
76
+ copy_icons(extracted_dir, variant_path, variant_dest)
77
+ end
78
+ end
79
+
80
+ def self.copy_icons(extracted_dir, icons_path, destination)
81
+ source = File.join(extracted_dir, icons_path)
82
+
83
+ FileUtils.mkdir_p(destination)
84
+ Dir.glob(File.join(source, "*.svg")).each do |svg|
85
+ FileUtils.cp(svg, destination)
86
+ end
87
+ end
88
+
89
+ private_class_method :download_and_extract, :copy_to_destination,
90
+ :download_tar, :extract_tar, :extract_entries, :copy_variants, :copy_icons
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ class Railtie < Rails::Railtie
5
+ initializer "ascona.load_icons" do
6
+ Ascona.load
7
+ end
8
+
9
+ initializer "ascona.helper" do
10
+ ActiveSupport.on_load(:action_view) do
11
+ include Ascona::Helper
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ class Registry
5
+ def initialize
6
+ @icons = {}
7
+ end
8
+
9
+ def load(path)
10
+ Dir.glob(File.join(path, "*")).each do |library_dir|
11
+ next unless File.directory?(library_dir)
12
+
13
+ library_name = File.basename(library_dir).to_sym
14
+ @icons[library_name] = {}
15
+
16
+ load_library(library_dir, library_name)
17
+ end
18
+ end
19
+
20
+ def get(name, library:, variant: nil)
21
+ library_icons = @icons[library]
22
+ return nil unless library_icons
23
+
24
+ if variant
25
+ library_icons.dig(variant.to_sym, name)
26
+ else
27
+ library_icons[name]
28
+ end
29
+ end
30
+
31
+ def libraries
32
+ @icons.keys
33
+ end
34
+
35
+ private
36
+
37
+ def load_library(library_dir, library_name)
38
+ has_variants = Dir.glob(File.join(library_dir, "*")).any? { |f| File.directory?(f) }
39
+
40
+ if has_variants
41
+ load_variants(library_dir, library_name)
42
+ else
43
+ load_flat(library_dir, library_name)
44
+ end
45
+ end
46
+
47
+ def load_variants(library_dir, library_name)
48
+ Dir.glob(File.join(library_dir, "*")).each do |variant_dir|
49
+ next unless File.directory?(variant_dir)
50
+
51
+ load_variant(variant_dir, library_name)
52
+ end
53
+ end
54
+
55
+ def load_variant(variant_dir, library_name)
56
+ variant_name = File.basename(variant_dir).to_sym
57
+ @icons[library_name][variant_name] = {}
58
+
59
+ Dir.glob(File.join(variant_dir, "*.svg")).each do |file|
60
+ icon_name = File.basename(file, ".svg").to_sym
61
+ @icons[library_name][variant_name][icon_name] = File.read(file)
62
+ end
63
+ end
64
+
65
+ def load_flat(library_dir, library_name)
66
+ Dir.glob(File.join(library_dir, "*.svg")).each do |file|
67
+ icon_name = File.basename(file, ".svg").to_sym
68
+ @icons[library_name][icon_name] = File.read(file)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ascona.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ascona/version"
4
+ require_relative "ascona/configuration"
5
+ require_relative "ascona/registry"
6
+ require_relative "ascona/helper"
7
+
8
+ module Ascona
9
+ class Error < StandardError; end
10
+
11
+ class << self
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield(configuration)
18
+ end
19
+
20
+ def registry
21
+ @registry ||= Registry.new
22
+ end
23
+
24
+ def load
25
+ registry.load(configuration.icon_path)
26
+ end
27
+ end
28
+ end
29
+
30
+ require_relative "ascona/railtie" if defined?(Rails)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ascona
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def copy_initializer
9
+ copy_file "initializer.rb", "config/initializers/ascona.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Ascona.configure do |config|
4
+ # config.icon_path = "app/assets/icons"
5
+ # config.default_library = :lucide
6
+
7
+ # Set default variants per library (only for libraries with variants):
8
+ # config.default_variants = { heroicons: :outline }
9
+ end
data/sig/ascona.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Ascona
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascona
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuenti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A Ruby gem for using SVG icons.
28
+ email:
29
+ - contact@samuenti.com
30
+ executables:
31
+ - ascona
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - exe/ascona
39
+ - lib/ascona.rb
40
+ - lib/ascona/cli.rb
41
+ - lib/ascona/configuration.rb
42
+ - lib/ascona/helper.rb
43
+ - lib/ascona/libraries/lucide.rb
44
+ - lib/ascona/library.rb
45
+ - lib/ascona/railtie.rb
46
+ - lib/ascona/registry.rb
47
+ - lib/ascona/version.rb
48
+ - lib/generators/ascona/install_generator.rb
49
+ - lib/generators/ascona/templates/initializer.rb
50
+ - sig/ascona.rbs
51
+ homepage: https://github.com/samuenti/ascona
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/samuenti/ascona
56
+ source_code_uri: https://github.com/samuenti/ascona
57
+ rubygems_mfa_required: 'true'
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.2.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.4.19
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Use SVG icons in Ruby
77
+ test_files: []