Sha256: d227bf8165294b04a0075b06c2e919e8fe69913dec12278fe9f80328ede25989

Contents?: true

Size: 1.62 KB

Versions: 63

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

REPO_URL = 'https://github.com/tailwindlabs/heroicons.git'
REPO_NAME = 'tailwindlabs-heroicons'
ICONS_PACK_PATH = 'lib/phlex/icons/hero'

TEMPLATE = ERB.new <<~TEMPLATE
  # frozen_string_literal: true

  # rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
  module Phlex
    module Icons
      module Hero
        class <%= icon_name %> < Base
          def solid
            <%= solid_icon %>
          end

          def outline
            <%= outline_icon %>
          end
        end
      end
    end
  end
  # rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
TEMPLATE

def main
  run_generator { icon_file_names.tqdm.each { create_icon_component(_1) } }
end

def icon_file_names
  Dir.glob("generators/#{REPO_NAME}/optimized/24/solid/*").map { |file| File.basename(file) }
end

def create_icon_component(icon_file_name)
  File.write(
    File.join(ICONS_PACK_PATH, component_file_name(icon_file_name)),
    TEMPLATE.result_with_hash(
      icon_name: component_class_name(icon_file_name),
      solid_icon: read_and_convert_icon(solid_icon_file_path(icon_file_name)),
      outline_icon: read_and_convert_icon(outline_icon_file_path(icon_file_name))
    )
  )
end

def read_and_convert_icon(icon_file_path)
  icon_file_content = File.read(icon_file_path)
  Phlexing::Converter.convert(icon_file_content).sub('svg(', "svg(\nclass: classes,")
end

def solid_icon_file_path(icon_file_name)
  "generators/#{REPO_NAME}/optimized/24/solid/#{icon_file_name}"
end

def outline_icon_file_path(icon_file_name)
  "generators/#{REPO_NAME}/optimized/24/outline/#{icon_file_name}"
end

main if __FILE__ == $PROGRAM_NAME

Version data entries

63 entries across 63 versions & 8 rubygems

Version Path
phlex-icons-0.4.0 generators/hero.rb
phlex-icons-0.3.0 generators/hero.rb
phlex-icons-0.2.0 generators/hero.rb