Sha256: 34da25e44675e9e2faa829ff6a2c6b194218932d46d750e8e574a891e9e43040

Contents?: true

Size: 1.87 KB

Versions: 3

Compression:

Stored size: 1.87 KB

Contents

module Redbreast
  module Command
    # Class for generating image tests
    class ImageTestGenerator
      include Helper::Terminal
      include Helper::General

      def self.init
        new.call
      end

      def call
        filtered_bundles = bundles.select { |bundle| bundle[:outputTestPathImages] }
        return if filtered_bundles.empty?

        prompt.say('Generating images test resources...')
        generate_test_sources(bundles, app_name)
        success('Images test resources generated!')
      end

      private

      def generate_test_sources(bundles, app_name)
        bundles.each do |bundle|
          image_names = pull_asset_names(bundle[:assetsSearchPath])
          bundle_language = bundle[:language] || programming_language
          write_tests(image_names, bundle, bundle_language, app_name)
        end
      end

      # Serializing data

      def write_tests(image_names, bundle, programming_language, app_name)
        output_path = bundle[:outputTestPathImages]

        return if output_path.to_s.empty?

        case programming_language.downcase
        when 'objc'
          serializer = Redbreast::Serializer::ObjC
          template_generator = Redbreast::TemplateGenerator::ImageTest::ObjC
        when 'swift'
          serializer = Redbreast::Serializer::Swift
          template_generator = Redbreast::TemplateGenerator::ImageTest::Swift
        when 'swiftui'
          serializer = Redbreast::Serializer::SwiftUI
          template_generator = Redbreast::TemplateGenerator::ImageTest::SwiftUI
        end
        serializer.new(image_names, bundle, app_name).save(output_source_path: output_path, template_generator: template_generator.new, generate_colors: false)

      end

      # Pulling data

      def pull_asset_names(assetsSearchPath)
        Redbreast::Crawler::Image
          .image_names_uniq(assetsSearchPath)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redbreast-1.4.2 lib/redbreast/commands/image_test_generator.rb
redbreast-1.4.1 lib/redbreast/commands/image_test_generator.rb
redbreast-1.4.0 lib/redbreast/commands/image_test_generator.rb