Skip to content

Commit

Permalink
Add variant icon classes instead of forcing users to pass variant to …
Browse files Browse the repository at this point in the history
…the initializer
  • Loading branch information
AliOsm committed Dec 15, 2024
1 parent 93a8359 commit 5925bf9
Show file tree
Hide file tree
Showing 11,007 changed files with 132,053 additions and 28 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
phlex-icons (2.1.0)
phlex-icons (2.2.0)
phlex (>= 1.11)

GEM
Expand Down
27 changes: 27 additions & 0 deletions generators/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
REPO_NAME = 'lipis-flag-icons'
ICONS_PACK_MODULE_PATH = 'lib/phlex-icons/flag.rb'
ICONS_PACK_PATH = 'lib/phlex-icons/flag'
VARIANTS = [:square, :rectangle]

TEMPLATE = ERB.new <<~TEMPLATE
# frozen_string_literal: true
Expand All @@ -27,6 +28,22 @@ def rectangle
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
TEMPLATE

VARIANT_TEMPLATE = ERB.new <<~VARIANT_TEMPLATE
# frozen_string_literal: true
# rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
module PhlexIcons
module Flag
class <%= icon_name %><%= variant.to_s.capitalize %> < Base
def view_template
render <%= icon_name %>.new(variant: :<%= variant %>)
end
end
end
end
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
VARIANT_TEMPLATE

def main
run_generator do
new_version = JSON.parse(File.read("generators/#{REPO_NAME}/package.json"))['version']
Expand All @@ -49,6 +66,16 @@ def create_icon_component(icon_file_name)
rectangle_icon: read_and_convert_icon(rectangle_icon_file_path(icon_file_name))
)
)

VARIANTS.each do |variant|
File.write(
File.join(ICONS_PACK_PATH, variant_component_file_name(icon_file_name, variant)),
VARIANT_TEMPLATE.result_with_hash(
icon_name: component_class_name(icon_file_name),
variant: variant
)
)
end
end

def read_and_convert_icon(icon_file_path)
Expand Down
4 changes: 4 additions & 0 deletions generators/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def component_file_name(icon_file_name, replacements = nil)
"#{icon_name.gsub('-', '_')}.rb"
end

def variant_component_file_name(icon_file_name, variant)
"#{component_file_name(icon_file_name).gsub('.rb', '')}_#{variant.to_s.downcase}.rb"
end

def component_class_name(icon_file_name, replacements = nil)
replacements ||= {}

Expand Down
27 changes: 27 additions & 0 deletions generators/hero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
REPO_NAME = 'tailwindlabs-heroicons'
ICONS_PACK_MODULE_PATH = 'lib/phlex-icons/hero.rb'
ICONS_PACK_PATH = 'lib/phlex-icons/hero'
VARIANTS = [:solid, :outline]

TEMPLATE = ERB.new <<~TEMPLATE
# frozen_string_literal: true
Expand All @@ -27,6 +28,22 @@ def outline
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
TEMPLATE

VARIANT_TEMPLATE = ERB.new <<~VARIANT_TEMPLATE
# frozen_string_literal: true
# rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
module PhlexIcons
module Hero
class <%= icon_name %><%= variant.to_s.capitalize %> < Base
def view_template
render <%= icon_name %>.new(variant: :<%= variant %>)
end
end
end
end
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
VARIANT_TEMPLATE

def main
run_generator do
new_version = JSON.parse(File.read("generators/#{REPO_NAME}/package.json"))['version']
Expand All @@ -49,6 +66,16 @@ def create_icon_component(icon_file_name)
outline_icon: read_and_convert_icon(outline_icon_file_path(icon_file_name))
)
)

VARIANTS.each do |variant|
File.write(
File.join(ICONS_PACK_PATH, variant_component_file_name(icon_file_name, variant)),
VARIANT_TEMPLATE.result_with_hash(
icon_name: component_class_name(icon_file_name),
variant: variant
)
)
end
end

def read_and_convert_icon(icon_file_path)
Expand Down
27 changes: 27 additions & 0 deletions generators/tabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
REPO_NAME = 'tabler-tabler-icons'
ICONS_PACK_MODULE_PATH = 'lib/phlex-icons/tabler.rb'
ICONS_PACK_PATH = 'lib/phlex-icons/tabler'
VARIANTS = [:filled, :outline]

TEMPLATE = ERB.new <<~TEMPLATE
# frozen_string_literal: true
Expand All @@ -27,6 +28,22 @@ def outline
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
TEMPLATE

VARIANT_TEMPLATE = ERB.new <<~VARIANT_TEMPLATE
# frozen_string_literal: true
# rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
module PhlexIcons
module Tabler
class <%= icon_name %><%= variant.to_s.capitalize %> < Base
def view_template
render <%= icon_name %>.new(variant: :<%= variant %>)
end
end
end
end
# rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
VARIANT_TEMPLATE

def main
run_generator do
new_version = JSON.parse(File.read("generators/#{REPO_NAME}/package.json"))['version']
Expand All @@ -49,6 +66,16 @@ def create_icon_component(icon_file_name)
outline_icon: read_and_convert_icon(outline_icon_file_path(icon_file_name))
)
)

VARIANTS.each do |variant|
File.write(
File.join(ICONS_PACK_PATH, variant_component_file_name(icon_file_name, variant)),
VARIANT_TEMPLATE.result_with_hash(
icon_name: component_class_name(icon_file_name),
variant: variant
)
)
end
end

def read_and_convert_icon(icon_file_path)
Expand Down
Loading

0 comments on commit 5925bf9

Please sign in to comment.