Module: LocoMotion::Icons::Installer
- Defined in:
- lib/loco_motion/icons/installer.rb
Overview
Syncs icon libraries into a target directory (a host application's
app/assets/svg/icons by default) using the icons gem. Backs the
install generator and the icons rake tasks (:add, :cache, :sync).
The sync clones each library from its upstream repository (git is required at install time only); the resulting SVGs are then committed to the host app and read directly from disk at render time.
Class Method Summary collapse
-
.add(libraries, target:) ⇒ Array<String>
The library names that were synced.
Class Method Details
.add(libraries, target:) ⇒ Array<String>
Returns The library names that were synced.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/loco_motion/icons/installer.rb', line 26 def add(libraries, target:) require "icons" require "fileutils" names = Array(libraries).map(&:to_s).reject(&:empty?) ::FileUtils.mkdir_p(target) ::Icons.configure { |config| config.icons_path = target } names.each do |library| # Clear any existing copy first. The `icons` gem moves the freshly # cloned set into `<target>/<library>`, and that move silently no-ops # when the directory already exists — so without this, re-syncing a # library (to update it, or to refresh the cache) does nothing. ::FileUtils.rm_rf(::File.join(target, library)) ::Icons::Sync.new(library).now end # The icons gem clones into a `tmp/icons` working directory; clean it # up. ::FileUtils.rm_rf("tmp/icons") names end |