lucide-ruby 0.1.6 → 0.1.102
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 +4 -4
- data/README.md +2 -2
- data/lib/lucide_ruby/release_resolver.rb +83 -0
- data/lib/lucide_ruby/tasks/lucide.rake +26 -70
- data/lib/lucide_ruby/version.rb +1 -1
- data/lib/lucide_ruby.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2546e86c5a6e81e1539bb2f5a686e07fc35e8db7d7c5e24b659991f8b8f73802
|
|
4
|
+
data.tar.gz: 3e361dadf8dea940464a75eb89ac077aa821ca55e34ebaeb0ce5ff4c6f3e2502
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6461817a0d2c090249acf2ff5e5a42161b652ec94d867b6787b2b80fe88ae41f24e0680883b9010d6186c6da21400a0846c5944d800594248d73df43ea0590f
|
|
7
|
+
data.tar.gz: 3d62e5c658a201ce402b551e659c3809d6a823a68c347d2fa413821712ec5d13b3ebd6d7806f494bc7401cd7a2c6c49aa0637a8af1b4d0aba204aa474dc56be2
|
data/README.md
CHANGED
|
@@ -24,7 +24,7 @@ This will:
|
|
|
24
24
|
|
|
25
25
|
1. Create a config initializer at `config/initializers/lucide_ruby.rb`
|
|
26
26
|
2. Create the icon directory at `app/assets/icons/lucide/`
|
|
27
|
-
3. Download all Lucide SVG icons from the latest release
|
|
27
|
+
3. Download all Lucide SVG icons from the latest release that includes packaged assets
|
|
28
28
|
|
|
29
29
|
Commit the icons to version control so deploys don't need to re-sync.
|
|
30
30
|
|
|
@@ -76,7 +76,7 @@ end
|
|
|
76
76
|
Downloads and extracts Lucide icons from GitHub releases.
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
|
-
# Sync latest version
|
|
79
|
+
# Sync latest version with packaged assets
|
|
80
80
|
rake lucide:sync
|
|
81
81
|
|
|
82
82
|
# Pin to a specific version
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module LucideRuby
|
|
8
|
+
module ReleaseResolver
|
|
9
|
+
REPOSITORY_API_URL = "https://api.github.com/repos/lucide-icons/lucide"
|
|
10
|
+
ASSET_NAME_PATTERN = /^lucide-icons-.*\.zip$/
|
|
11
|
+
|
|
12
|
+
extend self
|
|
13
|
+
|
|
14
|
+
def resolve(version: nil)
|
|
15
|
+
version ? resolve_version(version) : resolve_latest
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def resolve_latest
|
|
19
|
+
releases = fetch_json("#{REPOSITORY_API_URL}/releases?per_page=30")
|
|
20
|
+
|
|
21
|
+
release = releases.find do |candidate|
|
|
22
|
+
next false if candidate["draft"] || candidate["prerelease"]
|
|
23
|
+
|
|
24
|
+
release_asset(candidate)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
unless release
|
|
28
|
+
raise LucideRuby::SyncError, "Could not find a Lucide release with downloadable assets"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
release_info(release)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def resolve_version(version)
|
|
35
|
+
release = fetch_json("#{REPOSITORY_API_URL}/releases/tags/#{version}")
|
|
36
|
+
release_info(release, fallback_version: version)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def release_asset(release)
|
|
40
|
+
release.fetch("assets", []).find do |asset|
|
|
41
|
+
asset["name"]&.match?(ASSET_NAME_PATTERN)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def release_info(release, fallback_version: nil)
|
|
46
|
+
asset = release_asset(release)
|
|
47
|
+
version = release["tag_name"] || fallback_version
|
|
48
|
+
|
|
49
|
+
unless asset
|
|
50
|
+
raise LucideRuby::SyncError, "Could not find lucide-icons zip for release #{version}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
version: version,
|
|
55
|
+
download_url: asset["browser_download_url"]
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def fetch_json(url)
|
|
60
|
+
response = make_request(URI(url))
|
|
61
|
+
JSON.parse(response.body)
|
|
62
|
+
rescue JSON::ParserError => error
|
|
63
|
+
raise LucideRuby::SyncError, "Invalid response from GitHub: #{error.message}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def make_request(uri)
|
|
67
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
68
|
+
http.use_ssl = (uri.scheme == "https")
|
|
69
|
+
http.open_timeout = 15
|
|
70
|
+
http.read_timeout = 60
|
|
71
|
+
|
|
72
|
+
request = Net::HTTP::Get.new(uri)
|
|
73
|
+
request["User-Agent"] = "lucide-ruby/#{LucideRuby::VERSION}"
|
|
74
|
+
request["Accept"] = "application/vnd.github+json"
|
|
75
|
+
|
|
76
|
+
response = http.request(request)
|
|
77
|
+
|
|
78
|
+
return response if response.is_a?(Net::HTTPSuccess)
|
|
79
|
+
|
|
80
|
+
raise LucideRuby::SyncError, "GitHub request failed: #{response.code} #{response.message}"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "uri"
|
|
5
|
-
require "json"
|
|
6
5
|
require "fileutils"
|
|
7
6
|
require "tmpdir"
|
|
8
7
|
require "zip"
|
|
@@ -15,52 +14,53 @@ namespace :lucide do
|
|
|
15
14
|
|
|
16
15
|
puts "Fetching Lucide icons..."
|
|
17
16
|
|
|
18
|
-
# Determine download URL
|
|
19
17
|
if version
|
|
20
|
-
|
|
18
|
+
release = LucideRuby::ReleaseResolver.resolve(version: version)
|
|
19
|
+
download_url = release[:download_url]
|
|
20
|
+
version = release[:version]
|
|
21
21
|
puts "Pinned version: #{version}"
|
|
22
22
|
else
|
|
23
|
-
puts "Fetching latest release..."
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
puts "Fetching latest release with assets..."
|
|
24
|
+
release = LucideRuby::ReleaseResolver.resolve
|
|
25
|
+
download_url = release[:download_url]
|
|
26
|
+
version = release[:version]
|
|
27
27
|
puts "Latest version: #{version}"
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
Dir.mktmpdir("lucide-sync") do |tmpdir|
|
|
31
31
|
zip_path = File.join(tmpdir, "lucide-icons.zip")
|
|
32
|
-
extract_path = File.join(tmpdir, "extracted")
|
|
33
32
|
|
|
34
33
|
# Download
|
|
35
34
|
puts "Downloading #{download_url}..."
|
|
36
35
|
download_file(download_url, zip_path)
|
|
37
36
|
puts "Downloaded #{File.size(zip_path)} bytes"
|
|
38
37
|
|
|
39
|
-
# Extract
|
|
40
|
-
FileUtils.mkdir_p(extract_path)
|
|
41
|
-
extract_zip(zip_path, extract_path)
|
|
42
|
-
|
|
43
|
-
# Find SVG files in extracted archive
|
|
44
|
-
svg_source = find_svg_directory(extract_path)
|
|
45
|
-
|
|
46
|
-
if svg_source.nil?
|
|
47
|
-
raise LucideRuby::SyncError, "No SVG files found in the downloaded archive"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
svg_files = Dir.glob(File.join(svg_source, "*.svg"))
|
|
51
|
-
puts "Found #{svg_files.size} icons"
|
|
52
|
-
|
|
53
|
-
# Atomic replace: write to temp dir, then swap
|
|
38
|
+
# Extract SVGs directly from zip
|
|
54
39
|
staging_path = "#{icon_path}.staging"
|
|
55
40
|
backup_path = "#{icon_path}.backup"
|
|
56
41
|
|
|
57
42
|
FileUtils.rm_rf(staging_path)
|
|
58
43
|
FileUtils.mkdir_p(staging_path)
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
svg_count = 0
|
|
46
|
+
Zip::File.open(zip_path) do |zip_file|
|
|
47
|
+
zip_file.each do |entry|
|
|
48
|
+
next if entry.directory?
|
|
49
|
+
next unless entry.name.end_with?(".svg")
|
|
50
|
+
|
|
51
|
+
dest = File.join(staging_path, File.basename(entry.name))
|
|
52
|
+
File.binwrite(dest, entry.get_input_stream.read)
|
|
53
|
+
svg_count += 1
|
|
54
|
+
end
|
|
62
55
|
end
|
|
63
56
|
|
|
57
|
+
if svg_count == 0
|
|
58
|
+
FileUtils.rm_rf(staging_path)
|
|
59
|
+
raise LucideRuby::SyncError, "No SVG files found in the downloaded archive"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
puts "Found #{svg_count} icons"
|
|
63
|
+
|
|
64
64
|
# Write version file
|
|
65
65
|
File.write(File.join(staging_path, ".lucide-version"), version)
|
|
66
66
|
|
|
@@ -73,7 +73,7 @@ namespace :lucide do
|
|
|
73
73
|
# Clear cache
|
|
74
74
|
LucideRuby.cache.clear!
|
|
75
75
|
|
|
76
|
-
puts "Synced #{
|
|
76
|
+
puts "Synced #{svg_count} Lucide icons (#{version}) to #{icon_path}"
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -98,20 +98,6 @@ namespace :lucide do
|
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
def fetch_latest_release_url
|
|
102
|
-
uri = URI("https://api.github.com/repos/lucide-icons/lucide/releases/latest")
|
|
103
|
-
response = make_request(uri)
|
|
104
|
-
|
|
105
|
-
data = JSON.parse(response.body)
|
|
106
|
-
asset = data["assets"]&.find { |a| a["name"]&.match?(/^lucide-icons-.*\.zip$/) }
|
|
107
|
-
|
|
108
|
-
unless asset
|
|
109
|
-
raise LucideRuby::SyncError, "Could not find lucide-icons zip in latest release"
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
asset["browser_download_url"]
|
|
113
|
-
end
|
|
114
|
-
|
|
115
101
|
def download_file(url, destination, redirect_limit = 5)
|
|
116
102
|
raise LucideRuby::SyncError, "Too many redirects" if redirect_limit == 0
|
|
117
103
|
|
|
@@ -141,33 +127,3 @@ def make_request(uri)
|
|
|
141
127
|
http.request(request)
|
|
142
128
|
end
|
|
143
129
|
|
|
144
|
-
def extract_zip(zip_path, extract_path)
|
|
145
|
-
real_extract_path = File.realpath(extract_path)
|
|
146
|
-
|
|
147
|
-
Zip::File.open(zip_path) do |zip_file|
|
|
148
|
-
zip_file.each do |entry|
|
|
149
|
-
entry_path = File.join(real_extract_path, entry.name)
|
|
150
|
-
|
|
151
|
-
# Prevent zip slip - expand_path normalizes ".." segments
|
|
152
|
-
unless File.expand_path(entry_path).start_with?(real_extract_path)
|
|
153
|
-
raise LucideRuby::SyncError, "Zip slip detected: #{entry.name}"
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
if entry.directory?
|
|
157
|
-
FileUtils.mkdir_p(entry_path)
|
|
158
|
-
else
|
|
159
|
-
FileUtils.mkdir_p(File.dirname(entry_path))
|
|
160
|
-
entry.extract(entry_path)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def find_svg_directory(extract_path)
|
|
167
|
-
# Look for SVGs directly or in subdirectories
|
|
168
|
-
if Dir.glob(File.join(extract_path, "*.svg")).any?
|
|
169
|
-
return extract_path
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
Dir.glob(File.join(extract_path, "**", "*.svg")).first&.then { |f| File.dirname(f) }
|
|
173
|
-
end
|
data/lib/lucide_ruby/version.rb
CHANGED
data/lib/lucide_ruby.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "lucide_ruby/configuration"
|
|
|
8
8
|
require_relative "lucide_ruby/errors"
|
|
9
9
|
require_relative "lucide_ruby/cache"
|
|
10
10
|
require_relative "lucide_ruby/icon"
|
|
11
|
+
require_relative "lucide_ruby/release_resolver"
|
|
11
12
|
require_relative "lucide_ruby/view_helpers"
|
|
12
13
|
require_relative "lucide_ruby/railtie" if defined?(Rails)
|
|
13
14
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lucide-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.102
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- lucide-ruby contributors
|
|
@@ -68,6 +68,7 @@ files:
|
|
|
68
68
|
- lib/lucide_ruby/errors.rb
|
|
69
69
|
- lib/lucide_ruby/icon.rb
|
|
70
70
|
- lib/lucide_ruby/railtie.rb
|
|
71
|
+
- lib/lucide_ruby/release_resolver.rb
|
|
71
72
|
- lib/lucide_ruby/tasks/lucide.rake
|
|
72
73
|
- lib/lucide_ruby/version.rb
|
|
73
74
|
- lib/lucide_ruby/view_helpers.rb
|
|
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
93
|
- !ruby/object:Gem::Version
|
|
93
94
|
version: '0'
|
|
94
95
|
requirements: []
|
|
95
|
-
rubygems_version: 4.0.
|
|
96
|
+
rubygems_version: 4.0.7
|
|
96
97
|
specification_version: 4
|
|
97
98
|
summary: Rails view helpers for rendering Lucide SVG icons inline
|
|
98
99
|
test_files: []
|