Class: PolyglotIos::Serializer::Language::Swift
- Inherits:
-
Base
- Object
- Base
- PolyglotIos::Serializer::Language::Swift
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
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
|
#template ⇒ Object
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()
"import Foundation\n\npublic struct Language: Sendable {\n\n public let name: String\n public let localName: String\n public let locale: String\n public let languageCode: String\n\n<% @languages.each do |language| -%>\n public static let <%= language.clean_name %> = Language(name: \"<%= language.name %>\", localName: \"<%= language.local_name %>\", locale: \"<%= language.locale %>\", languageCode: \"<%= language.code %>\")\n<% end -%>\n\n public static let all = [\n<% @languages.each_with_index do |language, i| -%>\nLanguage.<%= language.clean_name %><%= i == (@languages.size - 1) ? \"\" : \",\" %>\n<% end -%>\n ]\n\n}\n"
end
|