Sha256: 81c39088827b7eeb8e0a2006d3a2a64455c8ddf7bf55a859572b9372c9556ecc

Contents?: true

Size: 1.8 KB

Versions: 8

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

REPO_URL = 'https://github.com/twbs/icons.git'
REPO_NAME = 'twbs-icons'
ICONS_PACK_MODULE_PATH = 'lib/phlex/icons/bootstrap.rb'
ICONS_PACK_PATH = 'lib/phlex/icons/bootstrap'

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

  # rubocop:disable #{ROBOCOP_DISABLE_WARNINGS}
  module Phlex
    module Icons
      module Bootstrap
        class <%= icon_name %> < Base
          def view_template
            <%= icon %>
          end
        end
      end
    end
  end
  # rubocop:enable #{ROBOCOP_DISABLE_WARNINGS}
TEMPLATE

REPLACEMENTS = {
  '0-' => 'zero-',
  '1-' => 'one-',
  '2-' => 'two-',
  '3-' => 'three-',
  '4-' => 'four-',
  '5-' => 'five-',
  '6-' => 'six-',
  '7-' => 'seven-',
  '8-' => 'eight-',
  '9-' => 'nine-',
  '123' => 'one-two-three'
}.freeze

def main
  run_generator do
    new_version = JSON.parse(File.read("generators/#{REPO_NAME}/package.json"))['version']
    update_icon_path_version(new_version)

    icon_file_paths.tqdm.each { create_icon_component(_1) }
  end
end

def icon_file_paths
  Dir.glob("generators/#{REPO_NAME}/icons/*")
end

def create_icon_component(icon_file_path)
  File.write(
    File.join(ICONS_PACK_PATH, component_file_name(icon_file_path, REPLACEMENTS)),
    TEMPLATE.result_with_hash(
      icon_name: component_class_name(icon_file_path, REPLACEMENTS),
      icon: read_and_convert_icon(icon_file_path)
    )
  )
end

def read_and_convert_icon(icon_file_path)
  icon_file_content = File.read(icon_file_path)
                          .sub(/class="bi [^"]*"/, '')
                          .sub('width="16"', '')
                          .sub('height="16"', '')

  Phlexing::Converter.convert(icon_file_content)
                     .sub('svg(', "svg(\nclass: classes,")
end

main if __FILE__ == $PROGRAM_NAME

Version data entries

8 entries across 8 versions & 8 rubygems

Version Path
phlex-icons-tabler-0.17.0 generators/bootstrap.rb
phlex-icons-bootstrap-0.17.0 generators/bootstrap.rb
phlex-icons-flag-0.17.0 generators/bootstrap.rb
phlex-icons-remix-0.17.0 generators/bootstrap.rb
phlex-icons-0.17.0 generators/bootstrap.rb
phlex-icons-hero-0.17.0 generators/bootstrap.rb
phlex-icons-radix-0.17.0 generators/bootstrap.rb
phlex-icons-lucide-0.17.0 generators/bootstrap.rb