Sha256: 4a37d8c6708df6b273f5929ce91927471e5ed9883354658f7460dbfc9dae83ba

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "protos"
require "phlex"
require "dry/inflector"

require_relative "icon/version"
require_relative "icon/heroicon"
require_relative "icon/inhouse"
require_relative "icon/component"
require_relative "icon/heroicon_component"

module Protos
  module Icon
    # Your code goes here...
    class Error < StandardError; end
    MissingIcon = Class.new(Error)

    GEM_ROOT = Pathname.new(__dir__).join("..", "..").expand_path
    public_constant :GEM_ROOT

    INFLECTOR = Dry::Inflector.new

    def self.lookup(constant, name)
      klass = "#{constant}::#{name}"
      INFLECTOR.constantize(klass)
    rescue NameError
      nil
    end

    def self.find(name)
      [Heroicon, Inhouse].each do |constant|
        component = lookup(constant, INFLECTOR.camelize(name))
        return component if component
      end

      raise MissingIcon, "Unknown icon: #{name}"
    end

    def icon(name, ...)
      component = Protos::Icon
        .find(name)
        .new(...)
      render component
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
protos-icon-0.4.1 lib/protos/icon.rb
protos-icon-0.4.0 lib/protos/icon.rb