Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option-less sync #45

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,19 @@ Need to use an icon from another library?
2. add the (SVG) icons to the created directory **app/assets/svg/icons/simple_icons**;

Every custom icon can now be used with the same interface as first-party icon libraries.

```ruby
icon "apple", library: "simple_icons", class: "text-black"
```


## Sync icons

If a library gets updated, sync the icons to your app by running

To sync all installed libraries, run
```bash
rails generate rails_icons:sync --libraries=LIBRARY_NAME
rails generate rails_icons:sync
```

**Example**
To sync only a specific library, run
```bash
rails generate rails_icons:sync --libraries=heroicons

Expand Down
16 changes: 14 additions & 2 deletions lib/generators/rails_icons/sync_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ class SyncGenerator < Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

def sync_icons
raise "[Rails Icons] Not a valid library" if options[:libraries].empty?
raise "[Rails Icons] Not a valid library" if libraries.empty?

options[:libraries].each { Sync::Engine.new(_1).sync }
libraries.each { Sync::Engine.new(_1).sync }
end

private

def libraries
options[:libraries].presence || synced_libraries
end

def synced_libraries
RailsIcons.libraries.keys.map(&:to_s).select do |library|
Dir.exist?(File.join(RailsIcons.configuration.destination_path, library.to_s))
end
end
end
end
Loading