Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justalever committed Sep 19, 2024
1 parent 883c108 commit 56071c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
21 changes: 21 additions & 0 deletions lib/railsui_icon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "railsui_icon/version"
require "railsui_icon/engine"
require "railsui_icon/railtie"
require "railsui_icon/helpers"
require "railsui_icon/icon"
require "railsui_icon/configuration"

module RailsuiIcon
class << self
attr_accessor :configuration

def configure
self.configuration ||= Configuration.new
yield(configuration)
end

def root
File.dirname(__dir__)
end
end
end
19 changes: 13 additions & 6 deletions lib/railsui_icon/icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ def render_standard_icon
def render_custom_path(custom_path)
return warning if custom_path.blank?

# Strip leading slashes from custom_path
sanitized_path = custom_path.sub(%r{^/}, '')

# Extract file name from sanitized_path
file_name = File.basename(URI.parse(sanitized_path).path)
# Extract file name from custom_path
file_name = File.basename(URI.parse(custom_path).path)

# Attempt to find the asset in subdirectories of app/assets/images
asset_path = find_asset_path(sanitized_path)
asset_path = find_asset_path(file_name)

raise ArgumentError, "Asset path cannot be found" if asset_path.nil?

Expand All @@ -72,6 +69,16 @@ def render_custom_path(custom_path)

private

def find_asset_path(file_name)
# Check in the main app/assets/images directory
path = Rails.root.join('app/assets/images', file_name)
return path.to_s if File.exist?(path)

# Check in any subdirectories within app/assets/images
Dir[Rails.root.join('app/assets/images/**/*', file_name)].first
end
private

def find_asset_path(file_name)
# Check in the main app/assets/images directory
path = Rails.root.join('app/assets/images', file_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/railsui_icon/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RailsuiIcon
VERSION = "1.1.0"
VERSION = "1.1.1"
end

0 comments on commit 56071c6

Please sign in to comment.