phlex-icons-bootstrap 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: 632cd61961f0396e66f20f7a2eaa4f4058a43180a701e2f4b69fcec613020ae9
4
- data.tar.gz: a7666dd524871e0d6532dfd60a645ff0d4b844a2d536833b214913be262cc5a7
3
+ metadata.gz: e5f18ff8086cca6839fd6484b8593f7e5c8fbbab96c94bd634c21b51d94e77a6
4
+ data.tar.gz: 4e2780860605e8a0ff0d20a7cda60be51930a7380b1632fc221e25cea6451762
5
5
  SHA512:
6
- metadata.gz: 36ac18d0032266ced4afb12292c4edf37ab28faedb9461422aa979f6d614550401c35de1f5e292bfcd20740575e378b317c13cef99012622b38fa22eae708a87
7
- data.tar.gz: d4e3499e1085efed5645ec6a36e5925629bc68b4e73ce9f3173916ff9ee0d6483adea8cc55c024124663062f4a4e7e2d4e94dc4dcca1ca6c1ea39fbc0eba0f9f
6
+ metadata.gz: 1f60a466a6d38b37e93e72526af0bb43aa5404e6db31fd85a3559e33e5f28d94da14a2166c707e71acc6d0ca39e693a5ddaf6913280fb278b13e2859b37003fb
7
+ data.tar.gz: 1c0ef0195eb4e6985fc696ebffb7662f6f41fe7a7369c5c63b7f0b35a2664bc9ad3bb961d1272b47d8b9907d37601d2e4bce75064727fab77170c9da2df42f33
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