Class: Unmagic::Icon::Library::Source

Inherits:
Object
  • Object
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/devicons.rb,
lib/unmagic/icon/library/source/heroicons.rb,
lib/unmagic/icon/library/source/simple_icons.rb,
lib/unmagic/icon/library/source/material_file_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: Devicons, DownloadError, Error, ExtractionError, Feather, Heroicons, Lucide, MaterialFileIcons, Silk, SimpleIcons, Tabler

Constant Summary collapse

REGISTRY =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



36
37
38
# File 'lib/unmagic/icon/library/source.rb', line 36

def all
  REGISTRY.values
end

.archive(value = nil) ⇒ Object



69
70
71
# File 'lib/unmagic/icon/library/source.rb', line 69

def archive(value = nil)
  value ? @archive = value : @archive
end

.description(value = nil) ⇒ Object



61
62
63
# File 'lib/unmagic/icon/library/source.rb', line 61

def description(value = nil)
  value ? @description = value : @description
end

.dir(value = nil) ⇒ Object

On-disk directory name; defaults to the key.



74
75
76
# File 'lib/unmagic/icon/library/source.rb', line 74

def dir(value = nil)
  value ? @dir = value.to_s : (@dir || key.to_s)
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/unmagic/icon/library/source.rb', line 44

def exists?(name)
  REGISTRY.key?(name.to_sym)
end

.extract(*patterns) ⇒ Object

Glob patterns (relative to the extracted archive) of svgs to copy.



79
80
81
# File 'lib/unmagic/icon/library/source.rb', line 79

def extract(*patterns)
  patterns.empty? ? (@extract || []) : @extract = patterns
end

.extract_into(mapping = nil) ⇒ Object

Map source directories to target subdirectories (e.g. heroicons sizes).



84
85
86
# File 'lib/unmagic/icon/library/source.rb', line 84

def extract_into(mapping = nil)
  mapping ? @extract_into = mapping : @extract_into
end

.find(name) ⇒ Object



40
41
42
# File 'lib/unmagic/icon/library/source.rb', line 40

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) —-



50
51
52
53
54
55
# File 'lib/unmagic/icon/library/source.rb', line 50

def key(value = nil)
  return @key unless value

  @key = value.to_sym
  REGISTRY[@key] = self
end

.title(value = nil) ⇒ Object



57
58
59
# File 'lib/unmagic/icon/library/source.rb', line 57

def title(value = nil)
  value ? @title = value : @title
end

.url(value = nil) ⇒ Object



65
66
67
# File 'lib/unmagic/icon/library/source.rb', line 65

def url(value = nil)
  value ? @url = value : @url
end

Instance Method Details

#download(target_dir: default_target_dir, force: false) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/unmagic/icon/library/source.rb', line 89

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