Class: Unmagic::Icon::Library::Source
- Inherits:
-
Object
- Object
- Unmagic::Icon::Library::Source
show all
- Defined in:
- lib/unmagic/icon/library/source.rb,
lib/unmagic/icon/library/source/silk.rb,
lib/unmagic/icon/library/source/lucide.rb,
lib/unmagic/icon/library/source/tabler.rb,
lib/unmagic/icon/library/source/feather.rb,
lib/unmagic/icon/library/source/iconoir.rb,
lib/unmagic/icon/library/source/devicons.rb,
lib/unmagic/icon/library/source/octicons.rb,
lib/unmagic/icon/library/source/phosphor.rb,
lib/unmagic/icon/library/source/heroicons.rb,
lib/unmagic/icon/library/source/simple_icons.rb,
lib/unmagic/icon/library/source/coloured_icons.rb,
lib/unmagic/icon/library/source/bootstrap_icons.rb,
lib/unmagic/icon/library/source/material_file_icons.rb,
lib/unmagic/icon/library/source/material_design_icons.rb
Overview
A downloadable source for an icon library: its metadata and how to fetch
it. Each library is a subclass that declares metadata with the class-level
DSL; the base carries the shared download/extract/manifest plumbing. A
subclass overrides #write_manifest to generate a mapping, or #acquire to
use a different transport.
Defined Under Namespace
Classes: BootstrapIcons, ColouredIcons, Devicons, DownloadError, Error, ExtractionError, Feather, Heroicons, Iconoir, Lucide, MaterialDesignIcons, MaterialFileIcons, Octicons, Phosphor, Silk, SimpleIcons, Tabler
Constant Summary
collapse
- REGISTRY =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.all ⇒ Object
37
38
39
|
# File 'lib/unmagic/icon/library/source.rb', line 37
def all
REGISTRY.values
end
|
.archive(value = nil) ⇒ Object
70
71
72
|
# File 'lib/unmagic/icon/library/source.rb', line 70
def archive(value = nil)
value ? @archive = value : @archive
end
|
.description(value = nil) ⇒ Object
62
63
64
|
# File 'lib/unmagic/icon/library/source.rb', line 62
def description(value = nil)
value ? @description = value : @description
end
|
.dir(value = nil) ⇒ Object
On-disk directory name; defaults to the key.
75
76
77
|
# File 'lib/unmagic/icon/library/source.rb', line 75
def dir(value = nil)
value ? @dir = value.to_s : (@dir || key.to_s)
end
|
.exists?(name) ⇒ Boolean
45
46
47
|
# File 'lib/unmagic/icon/library/source.rb', line 45
def exists?(name)
REGISTRY.key?(name.to_sym)
end
|
Glob patterns (relative to the extracted archive) of svgs to copy.
80
81
82
|
# File 'lib/unmagic/icon/library/source.rb', line 80
def (*patterns)
patterns.empty? ? (@extract || []) : @extract = patterns
end
|
Map source directories to target subdirectories (e.g. heroicons sizes).
85
86
87
|
# File 'lib/unmagic/icon/library/source.rb', line 85
def (mapping = nil)
mapping ? @extract_into = mapping : @extract_into
end
|
.find(name) ⇒ Object
41
42
43
|
# File 'lib/unmagic/icon/library/source.rb', line 41
def find(name)
REGISTRY[name.to_sym] or raise ArgumentError, "Unknown library: #{name}"
end
|
.key(value = nil) ⇒ Object
---- metadata DSL (each setter doubles as a reader) ----
51
52
53
54
55
56
|
# File 'lib/unmagic/icon/library/source.rb', line 51
def key(value = nil)
return @key unless value
@key = value.to_sym
REGISTRY[@key] = self
end
|
.title(value = nil) ⇒ Object
58
59
60
|
# File 'lib/unmagic/icon/library/source.rb', line 58
def title(value = nil)
value ? @title = value : @title
end
|
.url(value = nil) ⇒ Object
66
67
68
|
# File 'lib/unmagic/icon/library/source.rb', line 66
def url(value = nil)
value ? @url = value : @url
end
|
Instance Method Details
#download(target_dir: default_target_dir, force: false) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/unmagic/icon/library/source.rb', line 90
def download(target_dir: default_target_dir, force: false)
target_dir = Pathname(target_dir)
if target_dir.exist? && !force
puts "→ Skipping #{self.class.title} (already exists at #{target_dir}, use force: true to re-download)"
return
end
puts "→ Downloading #{self.class.title}..."
puts " #{self.class.description}"
acquire(target_dir)
puts " ✓ Downloaded #{count_svgs(target_dir)} icons to #{target_dir}"
end
|