Class: PolyglotIos::Serializer::Language::Swift

Inherits:
Base
  • Object
show all
Defined in:
lib/ios_polyglot_cli/serializers/languages/languages_serializer_swift.rb

Instance Attribute Summary

Attributes inherited from Base

#languages

Instance Method Summary collapse

Methods inherited from Base

#initialize, #render

Constructor Details

This class inherits a constructor from PolyglotIos::Serializer::Language::Base

Instance Method Details

#save(sources_path) ⇒ Object



8
9
10
11
12
# File 'lib/ios_polyglot_cli/serializers/languages/languages_serializer_swift.rb', line 8

def save(sources_path)
  FileUtils.mkdir_p sources_path unless File.exist? sources_path
  output_path = File.join(sources_path, "Language.swift")
  File.write(output_path, render)
end

#templateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ios_polyglot_cli/serializers/languages/languages_serializer_swift.rb', line 14

def template()
<<-TEMPLATE
import Foundation

public struct Language: Sendable {

    public let name: String
    public let localName: String
    public let locale: String
    public let languageCode: String

<% @languages.each do |language| -%>
    public static let <%= language.clean_name %> = Language(name: "<%= language.name %>", localName: "<%= language.local_name %>", locale: "<%= language.locale %>", languageCode: "<%= language.code %>")
<% end -%>

    public static let all = [
<% @languages.each_with_index do |language, i| -%>
Language.<%= language.clean_name %><%= i == (@languages.size - 1) ? "" : "," %>
<% end -%>
    ]

}
TEMPLATE
end