phlex-icons-remix 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2d66c30eab49173a6a6a18e85ca7884ac484350bebf6f465cc5df2dcb7080d7
4
- data.tar.gz: 9bac12577d0d2b5a0dc7ee28c643609f11624d6816677fb82dc3158b12fc6d17
3
+ metadata.gz: f6c21eca776c471d855307fec09079b679cdcf48791101eb8507c72ca0e0e301
4
+ data.tar.gz: 11667fb9034a1516d5ca339d256896bd342cff93b8d740ff70c760b85073db29
5
5
  SHA512:
6
- metadata.gz: 5a39e56dcd0e8ec49195b3051709335d5b6813bef0bc6fb49314dae4a4887902528c7cc545b0cf3906d1c2090377287bdf579b1d7bb937359580891bdac6ad38
7
- data.tar.gz: 4387ccc4702f2314fb57ea6d110daa06d50a18686ca38d0c9e0fea0e8eac022590be0aeb6d3c14ded4f9e4d8ad6d6ac481867332c54e185642efcc09f7f5d6d6
6
+ metadata.gz: e7fbede384fae5afb92579012f853798b9a83ecca222d127a4ac94bfedc4192a1a961dfaf01a58de5e809517207ef044351a1dd7af87e028438e43eacdfa4b20
7
+ data.tar.gz: c98480dab4e08aa020d2c73a93c41be4ccf1dc0d765dba42f2a8260c47455abf4dd44ccf5105e20e525f7c16d312f3f38acaec24d668242af9fd5cf075f599ce
data/README.md CHANGED
@@ -10,13 +10,14 @@
10
10
 
11
11
  # Phlex::Icons
12
12
 
13
- General icons extension for [Phlex](https://phlex.fun). Includes more than 🎨 7,300 icons from:
13
+ General icons extension for [Phlex](https://phlex.fun). Includes more than 🎨 12,000 icons from:
14
14
  - [Bootstrap Icons](https://icons.getbootstrap.com) (2,000+)
15
15
  - [Flag Icons](https://flagicons.lipis.dev) (250+)
16
16
  - [Heroicons](https://heroicons.com) (300+)
17
17
  - [Lucide Icons](https://lucide.dev/icons) (1,500+)
18
18
  - [RadixUI Icons](https://radix-ui.com/icons) (300+)
19
19
  - [Remix Icons](https://remixicon.com) (2,800+)
20
+ - [Tabler Icons](https://tabler.io/icons) (4,800+)
20
21
 
21
22
  And happy to extend to other icon packs!
22
23
 
@@ -40,6 +41,16 @@ If bundler is not being used to manage dependencies, install the gem by executin
40
41
  gem install phlex-icons
41
42
  ```
42
43
 
44
+ If you don't want to add all icon packs to your application, you can add a specific icon pack by using one (or multiple) of the following gems:
45
+
46
+ - [phlex-icons-bootstrap](https://rubygems.org/gems/phlex-icons-bootstrap)
47
+ - [phlex-icons-flag](https://rubygems.org/gems/phlex-icons-flag)
48
+ - [phlex-icons-hero](https://rubygems.org/gems/phlex-icons-hero)
49
+ - [phlex-icons-lucide](https://rubygems.org/gems/phlex-icons-lucide)
50
+ - [phlex-icons-radix](https://rubygems.org/gems/phlex-icons-radix)
51
+ - [phlex-icons-remix](https://rubygems.org/gems/phlex-icons-remix)
52
+ - [phlex-icons-tabler](https://rubygems.org/gems/phlex-icons-tabler)
53
+
43
54
  ## Configuration
44
55
 
45
56
  The gem provides global configuration options, and per icons pack configuration options.
@@ -96,8 +107,44 @@ Nothing to configure for RadixUI Icons.
96
107
 
97
108
  Nothing to configure for Remix Icons.
98
109
 
110
+ ### Tabler Icons configuration
111
+
112
+ ```ruby
113
+ Phlex::Icons::Tabler.configure do |config|
114
+ config.default_variant = :outline # or :filled
115
+ end
116
+
117
+ # OR
118
+
119
+ Phlex::Icons::Tabler.configuration.default_variant = :outline # or :filled
120
+ ```
121
+
99
122
  ## Usage
100
123
 
124
+ ### With `Phlex::Kit`
125
+
126
+ ```ruby
127
+ require 'phlex_icons'
128
+
129
+ class PhlexIcons < Phlex::HTML
130
+ include Phlex::Icons
131
+
132
+ def view_template
133
+ div do
134
+ Bootstrap::House(classes: 'size-4')
135
+ Flag::Sa(variant: :rectangle, classes: 'size-4')
136
+ Hero::Home(variant: :solid, classes: 'size-4')
137
+ Lucide::House(classes: 'size-4')
138
+ Radix::Home(classes: 'size-4')
139
+ Remix::HomeLine(classes: 'size-4')
140
+ Tabler::Home(variant: :filled, classes: 'size-4')
141
+ end
142
+ end
143
+ end
144
+ ```
145
+
146
+ ### Without `Phlex::Kit`
147
+
101
148
  ```ruby
102
149
  require 'phlex_icons'
103
150
 
@@ -110,6 +157,7 @@ class PhlexIcons < Phlex::HTML
110
157
  render Phlex::Icons::Lucide::House.new(classes: 'size-4')
111
158
  render Phlex::Icons::Radix::Home.new(classes: 'size-4')
112
159
  render Phlex::Icons::Remix::HomeLine.new(classes: 'size-4')
160
+ render Phlex::Icons::Tabler::Home.new(variant: :filled, classes: 'size-4')
113
161
  end
114
162
  end
115
163
  end
data/generators/helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'erb'
4
4
  require 'fileutils'
5
+ require 'zeitwerk' # Needed by Phlexing
5
6
  require 'phlexing'
6
7
  require 'tqdm'
7
8
 
@@ -19,8 +20,9 @@ def run_generator(&block)
19
20
 
20
21
  print '⌛ Creating icon components...'
21
22
  yield block
22
- puts "\r🎉 Icon components created successfully!"
23
+ puts "\e[2K\r🎉 Icon components created successfully!"
23
24
 
25
+ make_components_lazy_loadable(ICONS_PACK_PATH)
24
26
  run_rubocop(ICONS_PACK_PATH)
25
27
  delete_repo(REPO_NAME)
26
28
  end
@@ -29,14 +31,14 @@ def clone_repo(repo_url, repo_name)
29
31
  print "⌛ Cloning '#{repo_name}' repo..."
30
32
 
31
33
  if Dir.exist?("generators/#{repo_name}")
32
- puts "\r✅ '#{repo_name}' repo already exists"
34
+ puts "\e[2K\r✅ '#{repo_name}' repo already exists"
33
35
 
34
36
  return
35
37
  end
36
38
 
37
39
  system!("git clone #{repo_url} generators/#{repo_name}")
38
40
 
39
- puts "\r🎉 '#{repo_name}' repo cloned successfully!"
41
+ puts "\e[2K\r🎉 '#{repo_name}' repo cloned successfully!"
40
42
  end
41
43
 
42
44
  def prepare_phlex_icons_pack_directory(icons_pack_path)
@@ -50,13 +52,13 @@ def prepare_phlex_icons_pack_directory(icons_pack_path)
50
52
  File.delete(file)
51
53
  end
52
54
 
53
- puts "\r🎉 '#{icons_pack_path}' directory prepared successfully!"
55
+ puts "\e[2K\r🎉 '#{icons_pack_path}' directory prepared successfully!"
54
56
  end
55
57
 
56
58
  def component_file_name(icon_file_name, replacements = nil)
57
59
  replacements ||= {}
58
60
 
59
- icon_name = File.basename(icon_file_name, '.svg')
61
+ icon_name = File.basename(icon_file_name, File.extname(icon_file_name))
60
62
 
61
63
  replacements.each do |key, value|
62
64
  icon_name = icon_name.gsub(key, value) if icon_name.start_with?(key)
@@ -68,13 +70,32 @@ end
68
70
  def component_class_name(icon_file_name, replacements = nil)
69
71
  replacements ||= {}
70
72
 
71
- icon_name = File.basename(icon_file_name, '.svg')
73
+ icon_name = File.basename(icon_file_name, File.extname(icon_file_name))
72
74
 
73
75
  replacements.each do |key, value|
74
76
  icon_name = icon_name.gsub(key, value) if icon_name.start_with?(key)
75
77
  end
76
78
 
77
- icon_name.gsub('-', ' ').split.map(&:capitalize).join
79
+ icon_name.gsub(/[-_]/, ' ').split.map(&:capitalize).join
80
+ end
81
+
82
+ def make_components_lazy_loadable(path)
83
+ print '⌛ Making components lazy-loadable...'
84
+
85
+ autoload_lines = Dir.glob("#{path}/*.rb").map do |file|
86
+ next if ['base.rb', 'configuration.rb'].include?(File.basename(file))
87
+
88
+ " autoload :#{component_class_name(file)}, '#{file.split('/', 2).last.chomp(File.extname(file))}'"
89
+ end.compact.join("\n")
90
+
91
+ new_content = File.read("#{path}.rb").gsub(
92
+ /# auto-generated autoload: start.*# auto-generated autoload: end/m,
93
+ "# auto-generated autoload: start\n#{autoload_lines}\n # auto-generated autoload: end"
94
+ )
95
+
96
+ File.write("#{path}.rb", new_content)
97
+
98
+ puts "\e[2K\r🎉 Components are lazy-loadable!"
78
99
  end
79
100
 
80
101
  def run_rubocop(path)
@@ -86,7 +107,7 @@ def run_rubocop(path)
86
107
  File.write(file, File.read(file).gsub('rubocop:enable ,', 'rubocop:enable '))
87
108
  end
88
109
 
89
- puts "\r🎉 RuboCop ran successfully!"
110
+ puts "\e[2K\r🎉 RuboCop ran successfully!"
90
111
  end
91
112
 
92
113
  def delete_repo(repo_name)
@@ -94,7 +115,7 @@ def delete_repo(repo_name)
94
115
 
95
116
  FileUtils.rm_rf("generators/#{repo_name}")
96
117
 
97
- puts "\r🎉 '#{repo_name}' repo deleted successfully!"
118
+ puts "\e[2K\r🎉 '#{repo_name}' repo deleted successfully!"
98
119
  end
99
120
 
100
121
  def system!(command)
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ REPO_URL = 'https://github.com/tabler/tabler-icons.git'
6
+ REPO_NAME = 'tabler-tabler-icons'
7
+ ICONS_PACK_PATH = 'lib/phlex/icons/tabler'
8
+
9
+ TEMPLATE = ERB.new <<~TEMPLATE
10
+ # frozen_string_literal: true
11
+
12
+ # rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
13
+ module Phlex
14
+ module Icons
15
+ module Tabler
16
+ class <%= icon_name %> < Base
17
+ def filled
18
+ <%= filled_icon %>
19
+ end
20
+
21
+ def outline
22
+ <%= outline_icon %>
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ # rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
29
+ TEMPLATE
30
+
31
+ def main
32
+ run_generator { icon_file_names.tqdm.each { create_icon_component(_1) } }
33
+ end
34
+
35
+ def icon_file_names
36
+ Dir.glob("generators/#{REPO_NAME}/icons/outline/*").map { |file| File.basename(file) }
37
+ end
38
+
39
+ def create_icon_component(icon_file_name)
40
+ File.write(
41
+ File.join(ICONS_PACK_PATH, component_file_name(icon_file_name)),
42
+ TEMPLATE.result_with_hash(
43
+ icon_name: component_class_name(icon_file_name),
44
+ filled_icon: read_and_convert_icon(filled_icon_file_path(icon_file_name)),
45
+ outline_icon: read_and_convert_icon(outline_icon_file_path(icon_file_name))
46
+ )
47
+ )
48
+ end
49
+
50
+ def read_and_convert_icon(icon_file_path)
51
+ return 'raise NotImplementedError' unless File.exist?(icon_file_path)
52
+
53
+ icon_file_content = File.read(icon_file_path)
54
+ .gsub!(/<!--.*?-->/m, '')
55
+ .sub('width="24"', '')
56
+ .sub('height="24"', '')
57
+
58
+ Phlexing::Converter.convert(icon_file_content).sub('svg(', "svg(\nclass: classes,")
59
+ end
60
+
61
+ def filled_icon_file_path(icon_file_name)
62
+ "generators/#{REPO_NAME}/icons/filled/#{icon_file_name}"
63
+ end
64
+
65
+ def outline_icon_file_path(icon_file_name)
66
+ "generators/#{REPO_NAME}/icons/outline/#{icon_file_name}"
67
+ end
68
+
69
+ main if __FILE__ == $PROGRAM_NAME