Sha256: 5a42c440b0babc8013a2c8ebcfccb838d1d0c942757f2c40614c56b2839bc95c

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

module Twine
  module Formatters
    class QKRStringSwift < Abstract
      def format_name
        'qkr_string_swift'
      end

      def extension
        '.swift'
      end

      def can_handle_directory?(path)
        true
      end

      def default_file_name
        'QKRString+extension.swift'
      end

      def determine_language_given_path(path)
        return @twine_file.language_codes[0]
      end

      def output_path_for_language(lang)
        ""
      end

      def read(io, lang)
      end

      def format_header(lang)
        "/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n */"
      end

      def format_sections(twine_file, lang)
        result = "import Foundation\n"
        result += "import QualiacKernel\n\n"
        result += "// swiftlint:disable identifier_name line_length superfluous_disable_command\n"
        result += "extension QKRString {\n"
        
        result += super + "\n"

        result += "}\n"
        result += "// swiftlint:enable identifier_name line_length superfluous_disable_command\n"
      end

      def format_section_header(section)
        "\t/********** #{section.name} **********/\n"
      end

      def key_value_pattern
        "\tvar %{key}: String { return load(\"%{key}\", in: Bundle.main, table: \"Localizable\") }\n"
      end

      def format_key(key)
        if ["class", "deinit", "enum", "func", "import", "init", "internal", "let", "operator", "private", "protocol",
            "public", "static", "struct", "subscript", "typealias", "var"].include? key
          key = "`#{key}`"
        end
        
        key
      end

      def format_value(value)
        escape_quotes(value)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qualiac_twine-0.0.10 lib/qualiac_twine/formatter/qkr_string_swift.rb