Skip to content

Commit

Permalink
Phosphor Icons (#40)
Browse files Browse the repository at this point in the history
* Added basics for Phosphor

- https://phosphoricons.com/
- https://github.com/phosphor-icons/core/

* Set up all variants
  • Loading branch information
eelcoj authored Dec 15, 2024
1 parent 61fb32b commit 5e9b32a
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ icon "check", stroke_width: 2
- [Feather](https://github.com/feathericons/feather)
- [Heroicons](https://github.com/tailwindlabs/heroicons)
- [Lucide](https://github.com/lucide-icons/lucide)
- [Phosphor](https://github.com/phosphor-icons/core)
- [Tabler](https://github.com/tabler/tabler-icons)


Expand Down
28 changes: 25 additions & 3 deletions lib/generators/rails_icons/initializer_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ def insert_custom_configuration
insert_into_file INITIALIZER, "\n#{custom_configuration}", after: "custom: {"
end

def create_custom_directory
FileUtils.mkdir_p(File.join(options[:destination], options[:custom]))
end
def create_custom_directory = FileUtils.mkdir_p(File.join(options[:destination], options[:custom]))

def library_configuration
configs = {
feather: feather_config,
heroicons: heroicons_config,
lucide: lucide_config,
phosphor: phosphor_config,
tabler: tabler_config
}

Expand Down Expand Up @@ -112,6 +111,29 @@ def lucide_config
RB
end

def phosphor_config
<<~RB.indent(2)
# Override Phosphor defaults
# config.libraries.phosphor.bold.default.css = "size-6"
# config.libraries.phosphor.bold.default.data = {}
# config.libraries.phosphor.duotone.default.css = "size-6"
# config.libraries.phosphor.duotone.default.data = {}
# config.libraries.phosphor.fill.default.css = "size-6"
# config.libraries.phosphor.fill.default.data = {}
# config.libraries.phosphor.light.default.css = "size-6"
# config.libraries.phosphor.light.default.data = {}
# config.libraries.phosphor.regular.default.css = "size-6"
# config.libraries.phosphor.regular.default.data = {}
# config.libraries.phosphor.thin.default.css = "size-6"
# config.libraries.phosphor.thin.default.data = {}
RB
end

def tabler_config
<<~RB.indent(2)
# Override Tabler defaults
Expand Down
2 changes: 2 additions & 0 deletions lib/rails_icons/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative "configuration/feather"
require_relative "configuration/heroicons"
require_relative "configuration/lucide"
require_relative "configuration/phosphor"
require_relative "configuration/tabler"

module RailsIcons
Expand Down Expand Up @@ -48,6 +49,7 @@ def set_libraries_config
@config.libraries.feather = Configuration::Feather.new.config
@config.libraries.heroicons = Configuration::Heroicons.new.config
@config.libraries.lucide = Configuration::Lucide.new.config
@config.libraries.phosphor = Configuration::Phosphor.new.config
@config.libraries.tabler = Configuration::Tabler.new.config
end
end
Expand Down
94 changes: 94 additions & 0 deletions lib/rails_icons/configuration/phosphor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

module RailsIcons
class Configuration
class Phosphor
def config
ActiveSupport::OrderedOptions.new.tap do |options|
options.default_variant = :regular

setup_bold_config(options)
setup_duotone_config(options)
setup_fill_config(options)
setup_light_config(options)
setup_regular_config(options)
setup_thin_config(options)
end
end

private

def setup_bold_config(options)
options.bold = ActiveSupport::OrderedOptions.new
options.bold.default = default_bold_options
end

def default_bold_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end

def setup_duotone_config(options)
options.duotone = ActiveSupport::OrderedOptions.new
options.duotone.default = default_duotone_options
end

def default_duotone_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end

def setup_fill_config(options)
options.fill = ActiveSupport::OrderedOptions.new
options.fill.default = default_fill_options
end

def default_fill_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end

def setup_light_config(options)
options.light = ActiveSupport::OrderedOptions.new
options.light.default = default_light_options
end

def default_light_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end

def setup_regular_config(options)
options.regular = ActiveSupport::OrderedOptions.new
options.regular.default = default_regular_options
end

def default_regular_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end

def setup_thin_config(options)
options.thin = ActiveSupport::OrderedOptions.new
options.thin.default = default_thin_options
end

def default_thin_options
ActiveSupport::OrderedOptions.new.tap do |options|
options.css = "size-6"
options.data = {}
end
end
end
end
end
13 changes: 13 additions & 0 deletions lib/rails_icons/libraries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def all
}
},

phosphor: {
name: "phosphor",
url: "https://github.com/phosphor-icons/core.git",
variants: {
bold: "raw/bold",
duotone: "raw/duotone",
fill: "raw/fill",
light: "raw/light",
regular: "raw/regular",
thin: "raw/thin"
}
},

tabler: {
name: "tabler",
url: "https://github.com/tabler/tabler-icons.git",
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/assets/svg/icons/phosphor/duotone/acorn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/dummy/app/assets/svg/icons/phosphor/regular/acorn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/generators/initializer_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class InitializerGeneratorTest < Rails::Generators::TestCase
end
end

test "generator creates the initializer with Phosphor library" do
run_generator %w[--libraries=phosphor]

assert_file "config/initializers/rails_icons.rb" do |file|
assert_match "# Override Phosphor defaults", file
refute_match "Tabler", file
end
end

test "generator creates the initializer with tabler library" do
run_generator %w[--libraries=tabler]

Expand Down
16 changes: 7 additions & 9 deletions test/icon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,35 @@ class IconTest < ActiveSupport::TestCase
end
end

test "without variant, using default configuration, it returns a SVG" do
test "default library (heroicons)" do
assert_nothing_raised do
icon("academic-cap")
end
end

test "using feather library, it returns a SVG" do
test "feather" do
assert_nothing_raised do
icon("activity", library: "feather")
end
end

test "using lucide library, it returns a SVG" do
test "lucide" do
assert_nothing_raised do
icon("graduation-cap", library: "lucide")
end
end

test "using lucide library, without passing variant, it returns a SVG" do
test "phosphor" do
assert_nothing_raised do
icon("graduation-cap", library: "lucide")
icon("acorn", library: "phosphor")
end
end

test "using tabler library, it returns a SVG" do
assert_nothing_raised do
icon("thumbs-up", library: "tabler")
icon("acorn", library: "phosphor", variant: :duotone)
end
end

test "using tabler library, without passing variant, it returns a SVG" do
test "tabler" do
assert_nothing_raised do
icon("thumbs-up", library: "tabler")
end
Expand Down

0 comments on commit 5e9b32a

Please sign in to comment.