danger-localizationlinter 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +167 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +25 -0
- data/danger-localizationlinter.gemspec +60 -0
- data/ext/localizationlinter/helper/validate_wording_cli.rb +21 -0
- data/ext/localizationlinter/localizationlinter.rb +331 -0
- data/ext/localizationlinter/swiftgen_localizables_check.stencil +36 -0
- data/lib/danger_localizationlinter.rb +3 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/localizationlinter/gem_version.rb +5 -0
- data/lib/localizationlinter/plugin.rb +96 -0
- data/spec/Test/Podfile +6 -0
- data/spec/Test/Podfile.lock +16 -0
- data/spec/Test/Pods/SwiftGen/CHANGELOG.md +1357 -0
- data/spec/Test/Pods/SwiftGen/LICENCE +21 -0
- data/spec/Test/Pods/SwiftGen/README.md +892 -0
- data/spec/Test/Pods/SwiftGen/bin/swiftgen +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift4.stencil +43 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift5.stencil +43 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/swift4.stencil +84 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/swift5.stencil +84 -0
- data/spec/Test/Pods/SwiftGen/templates/coredata/swift4.stencil +211 -0
- data/spec/Test/Pods/SwiftGen/templates/coredata/swift5.stencil +211 -0
- data/spec/Test/Pods/SwiftGen/templates/fonts/swift4.stencil +110 -0
- data/spec/Test/Pods/SwiftGen/templates/fonts/swift5.stencil +113 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift4.stencil +157 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift5.stencil +159 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift4.stencil +60 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift5.stencil +60 -0
- data/spec/Test/Pods/SwiftGen/templates/json/inline-swift4.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/json/inline-swift5.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift4.stencil +112 -0
- data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift5.stencil +112 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift4.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift5.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift4.stencil +117 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift5.stencil +117 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift4.stencil +97 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift5.stencil +97 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/objc-h.stencil +66 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/objc-m.stencil +90 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift4.stencil +102 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift5.stencil +102 -0
- data/spec/Test/Pods/SwiftGen/templates/xcassets/swift4.stencil +266 -0
- data/spec/Test/Pods/SwiftGen/templates/xcassets/swift5.stencil +274 -0
- data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift4.stencil +92 -0
- data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift5.stencil +92 -0
- data/spec/Test/Test.xcodeproj/project.pbxproj +406 -0
- data/spec/Test/Test.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/spec/Test/Test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/spec/Test/Test.xcworkspace/contents.xcworkspacedata +10 -0
- data/spec/Test/Test.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/spec/Test/Test/AppDelegate.swift +36 -0
- data/spec/Test/Test/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- data/spec/Test/Test/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
- data/spec/Test/Test/Assets.xcassets/Contents.json +6 -0
- data/spec/Test/Test/ContentView.swift +21 -0
- data/spec/Test/Test/Info.plist +62 -0
- data/spec/Test/Test/SceneDelegate.swift +63 -0
- data/spec/Test/Test/all_target_main_language.yml +1 -0
- data/spec/Test/Test/en.lproj/LaunchScreen.storyboard +25 -0
- data/spec/Test/Test/en.lproj/localizable.strings +3 -0
- data/spec/Test/Test/fr.lproj/LaunchScreen.storyboard +25 -0
- data/spec/Test/Test/fr.lproj/localizable.strings +3 -0
- data/spec/localizationofficer_spec.rb +116 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/fixtures/all_target_main_language.yml +1 -0
- data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.strings +8 -0
- data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.stringsdict +30 -0
- data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.strings +11 -0
- data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.stringsdict +30 -0
- data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.strings +11 -0
- data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.stringsdict +30 -0
- metadata +491 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if files %}
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
6
|
+
import Foundation
|
7
|
+
|
8
|
+
// swiftlint:disable superfluous_disable_command
|
9
|
+
// swiftlint:disable file_length
|
10
|
+
|
11
|
+
// MARK: - Plist Files
|
12
|
+
{% macro fileBlock file %}
|
13
|
+
{% call documentBlock file file.document %}
|
14
|
+
{% endmacro %}
|
15
|
+
{% macro documentBlock file document %}
|
16
|
+
{% set rootType %}{% call typeBlock document.metadata %}{% endset %}
|
17
|
+
{% if document.metadata.type == "Array" %}
|
18
|
+
{{accessModifier}} static let items: {{rootType}} = {% call valueBlock document.data document.metadata %}
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
20
|
+
{% for key,value in document.metadata.properties %}
|
21
|
+
{{accessModifier}} {% call propertyBlock key value document.data %}
|
22
|
+
{% endfor %}
|
23
|
+
{% else %}
|
24
|
+
{{accessModifier}} static let value: {{rootType}} = {% call valueBlock document.data document.metadata %}
|
25
|
+
{% endif %}
|
26
|
+
{% endmacro %}
|
27
|
+
{% macro typeBlock metadata %}{% filter removeNewlines:"leading" %}
|
28
|
+
{% if metadata.type == "Array" %}
|
29
|
+
[{% call typeBlock metadata.element %}]
|
30
|
+
{% elif metadata.type == "Dictionary" %}
|
31
|
+
[String: Any]
|
32
|
+
{% else %}
|
33
|
+
{{metadata.type}}
|
34
|
+
{% endif %}
|
35
|
+
{% endfilter %}{% endmacro %}
|
36
|
+
{% macro propertyBlock key metadata data %}{% filter removeNewlines:"leading" %}
|
37
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
38
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
39
|
+
static let {{propertyName}}: {{propertyType}} = {% call valueBlock data[key] metadata %}
|
40
|
+
{% endfilter %}{% endmacro %}
|
41
|
+
{% macro valueBlock value metadata %}{% filter removeNewlines:"leading" %}
|
42
|
+
{% if metadata.type == "String" %}
|
43
|
+
"{{ value }}"
|
44
|
+
{% elif metadata.type == "Date" %}
|
45
|
+
Date(timeIntervalSinceReferenceDate: {{ value.timeIntervalSinceReferenceDate }})
|
46
|
+
{% elif metadata.type == "Optional" %}
|
47
|
+
nil
|
48
|
+
{% elif metadata.type == "Array" and value %}
|
49
|
+
[{% for value in value %}
|
50
|
+
{% call valueBlock value metadata.element.items[forloop.counter0]|default:metadata.element %}
|
51
|
+
{{ ", " if not forloop.last }}
|
52
|
+
{% endfor %}]
|
53
|
+
{% elif metadata.type == "Dictionary" %}
|
54
|
+
[{% for key,value in value %}
|
55
|
+
"{{key}}": {% call valueBlock value metadata.properties[key] %}
|
56
|
+
{{ ", " if not forloop.last }}
|
57
|
+
{% empty %}
|
58
|
+
:
|
59
|
+
{% endfor %}]
|
60
|
+
{% elif metadata.type == "Bool" %}
|
61
|
+
{% if value %}true{% else %}false{% endif %}
|
62
|
+
{% else %}
|
63
|
+
{{ value }}
|
64
|
+
{% endif %}
|
65
|
+
{% endfilter %}{% endmacro %}
|
66
|
+
|
67
|
+
// swiftlint:disable identifier_name line_length number_separator type_body_length
|
68
|
+
{{accessModifier}} enum {{param.enumName|default:"PlistFiles"}} {
|
69
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
70
|
+
{% for file in files %}
|
71
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
72
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
73
|
+
}
|
74
|
+
{% endfor %}
|
75
|
+
{% else %}
|
76
|
+
{% call fileBlock files.first %}
|
77
|
+
{% endif %}
|
78
|
+
}
|
79
|
+
// swiftlint:enable identifier_name line_length number_separator type_body_length
|
80
|
+
{% else %}
|
81
|
+
// No files found
|
82
|
+
{% endif %}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if files %}
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
6
|
+
import Foundation
|
7
|
+
|
8
|
+
// swiftlint:disable superfluous_disable_command
|
9
|
+
// swiftlint:disable file_length
|
10
|
+
|
11
|
+
// MARK: - Plist Files
|
12
|
+
{% macro fileBlock file %}
|
13
|
+
{% call documentBlock file file.document %}
|
14
|
+
{% endmacro %}
|
15
|
+
{% macro documentBlock file document %}
|
16
|
+
{% set rootType %}{% call typeBlock document.metadata %}{% endset %}
|
17
|
+
{% if document.metadata.type == "Array" %}
|
18
|
+
{{accessModifier}} static let items: {{rootType}} = {% call valueBlock document.data document.metadata %}
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
20
|
+
{% for key,value in document.metadata.properties %}
|
21
|
+
{{accessModifier}} {% call propertyBlock key value document.data %}
|
22
|
+
{% endfor %}
|
23
|
+
{% else %}
|
24
|
+
{{accessModifier}} static let value: {{rootType}} = {% call valueBlock document.data document.metadata %}
|
25
|
+
{% endif %}
|
26
|
+
{% endmacro %}
|
27
|
+
{% macro typeBlock metadata %}{% filter removeNewlines:"leading" %}
|
28
|
+
{% if metadata.type == "Array" %}
|
29
|
+
[{% call typeBlock metadata.element %}]
|
30
|
+
{% elif metadata.type == "Dictionary" %}
|
31
|
+
[String: Any]
|
32
|
+
{% else %}
|
33
|
+
{{metadata.type}}
|
34
|
+
{% endif %}
|
35
|
+
{% endfilter %}{% endmacro %}
|
36
|
+
{% macro propertyBlock key metadata data %}{% filter removeNewlines:"leading" %}
|
37
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
38
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
39
|
+
static let {{propertyName}}: {{propertyType}} = {% call valueBlock data[key] metadata %}
|
40
|
+
{% endfilter %}{% endmacro %}
|
41
|
+
{% macro valueBlock value metadata %}{% filter removeNewlines:"leading" %}
|
42
|
+
{% if metadata.type == "String" %}
|
43
|
+
"{{ value }}"
|
44
|
+
{% elif metadata.type == "Date" %}
|
45
|
+
Date(timeIntervalSinceReferenceDate: {{ value.timeIntervalSinceReferenceDate }})
|
46
|
+
{% elif metadata.type == "Optional" %}
|
47
|
+
nil
|
48
|
+
{% elif metadata.type == "Array" and value %}
|
49
|
+
[{% for value in value %}
|
50
|
+
{% call valueBlock value metadata.element.items[forloop.counter0]|default:metadata.element %}
|
51
|
+
{{ ", " if not forloop.last }}
|
52
|
+
{% endfor %}]
|
53
|
+
{% elif metadata.type == "Dictionary" %}
|
54
|
+
[{% for key,value in value %}
|
55
|
+
"{{key}}": {% call valueBlock value metadata.properties[key] %}
|
56
|
+
{{ ", " if not forloop.last }}
|
57
|
+
{% empty %}
|
58
|
+
:
|
59
|
+
{% endfor %}]
|
60
|
+
{% elif metadata.type == "Bool" %}
|
61
|
+
{% if value %}true{% else %}false{% endif %}
|
62
|
+
{% else %}
|
63
|
+
{{ value }}
|
64
|
+
{% endif %}
|
65
|
+
{% endfilter %}{% endmacro %}
|
66
|
+
|
67
|
+
// swiftlint:disable identifier_name line_length number_separator type_body_length
|
68
|
+
{{accessModifier}} enum {{param.enumName|default:"PlistFiles"}} {
|
69
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
70
|
+
{% for file in files %}
|
71
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
72
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
73
|
+
}
|
74
|
+
{% endfor %}
|
75
|
+
{% else %}
|
76
|
+
{% call fileBlock files.first %}
|
77
|
+
{% endif %}
|
78
|
+
}
|
79
|
+
// swiftlint:enable identifier_name line_length number_separator type_body_length
|
80
|
+
{% else %}
|
81
|
+
// No files found
|
82
|
+
{% endif %}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if files %}
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
6
|
+
import Foundation
|
7
|
+
|
8
|
+
// swiftlint:disable superfluous_disable_command
|
9
|
+
// swiftlint:disable file_length
|
10
|
+
|
11
|
+
// MARK: - Plist Files
|
12
|
+
{% macro fileBlock file %}
|
13
|
+
{% call documentBlock file file.document %}
|
14
|
+
{% endmacro %}
|
15
|
+
{% macro documentBlock file document %}
|
16
|
+
{% set rootType %}{% call typeBlock document.metadata %}{% endset %}
|
17
|
+
{% if document.metadata.type == "Array" %}
|
18
|
+
{{accessModifier}} static let items: {{rootType}} = arrayFromPlist(at: "{% call transformPath file.path %}")
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
20
|
+
private static let _document = PlistDocument(path: "{% call transformPath file.path %}")
|
21
|
+
|
22
|
+
{% for key,value in document.metadata.properties %}
|
23
|
+
{{accessModifier}} {% call propertyBlock key value %}
|
24
|
+
{% endfor %}
|
25
|
+
{% else %}
|
26
|
+
// Unsupported root type `{{rootType}}`
|
27
|
+
{% endif %}
|
28
|
+
{% endmacro %}
|
29
|
+
{% macro typeBlock metadata %}{% filter removeNewlines:"leading" %}
|
30
|
+
{% if metadata.type == "Array" %}
|
31
|
+
[{% call typeBlock metadata.element %}]
|
32
|
+
{% elif metadata.type == "Dictionary" %}
|
33
|
+
[String: Any]
|
34
|
+
{% else %}
|
35
|
+
{{metadata.type}}
|
36
|
+
{% endif %}
|
37
|
+
{% endfilter %}{% endmacro %}
|
38
|
+
{% macro propertyBlock key metadata %}{% filter removeNewlines:"leading" %}
|
39
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
40
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
41
|
+
static let {{propertyName}}: {{propertyType}} = _document["{{key}}"]
|
42
|
+
{% endfilter %}{% endmacro %}
|
43
|
+
{% macro transformPath path %}{% filter removeNewlines %}
|
44
|
+
{% if param.preservePath %}
|
45
|
+
{{path}}
|
46
|
+
{% else %}
|
47
|
+
{{path|basename}}
|
48
|
+
{% endif %}
|
49
|
+
{% endfilter %}{% endmacro %}
|
50
|
+
|
51
|
+
// swiftlint:disable identifier_name line_length type_body_length
|
52
|
+
{{accessModifier}} enum {{param.enumName|default:"PlistFiles"}} {
|
53
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
54
|
+
{% for file in files %}
|
55
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
56
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
57
|
+
}
|
58
|
+
{% endfor %}
|
59
|
+
{% else %}
|
60
|
+
{% call fileBlock files.first %}
|
61
|
+
{% endif %}
|
62
|
+
}
|
63
|
+
// swiftlint:enable identifier_name line_length type_body_length
|
64
|
+
|
65
|
+
// MARK: - Implementation Details
|
66
|
+
|
67
|
+
private func arrayFromPlist<T>(at path: String) -> [T] {
|
68
|
+
{% if param.lookupFunction %}
|
69
|
+
guard let url = {{param.lookupFunction}}(path),
|
70
|
+
{% else %}
|
71
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
72
|
+
{% endif %}
|
73
|
+
let data = NSArray(contentsOf: url) as? [T] else {
|
74
|
+
fatalError("Unable to load PLIST at path: \(path)")
|
75
|
+
}
|
76
|
+
return data
|
77
|
+
}
|
78
|
+
|
79
|
+
private struct PlistDocument {
|
80
|
+
let data: [String: Any]
|
81
|
+
|
82
|
+
init(path: String) {
|
83
|
+
{% if param.lookupFunction %}
|
84
|
+
guard let url = {{param.lookupFunction}}(path),
|
85
|
+
{% else %}
|
86
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
87
|
+
{% endif %}
|
88
|
+
let data = NSDictionary(contentsOf: url) as? [String: Any] else {
|
89
|
+
fatalError("Unable to load PLIST at path: \(path)")
|
90
|
+
}
|
91
|
+
self.data = data
|
92
|
+
}
|
93
|
+
|
94
|
+
subscript<T>(key: String) -> T {
|
95
|
+
guard let result = data[key] as? T else {
|
96
|
+
fatalError("Property '\(key)' is not of type \(T.self)")
|
97
|
+
}
|
98
|
+
return result
|
99
|
+
}
|
100
|
+
}
|
101
|
+
{% if not param.bundle and not param.lookupFunction %}
|
102
|
+
|
103
|
+
// swiftlint:disable convenience_type
|
104
|
+
private final class BundleToken {
|
105
|
+
static let bundle: Bundle = {
|
106
|
+
#if SWIFT_PACKAGE
|
107
|
+
return Bundle.module
|
108
|
+
#else
|
109
|
+
return Bundle(for: BundleToken.self)
|
110
|
+
#endif
|
111
|
+
}()
|
112
|
+
}
|
113
|
+
// swiftlint:enable convenience_type
|
114
|
+
{% endif %}
|
115
|
+
{% else %}
|
116
|
+
// No files found
|
117
|
+
{% endif %}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if files %}
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
6
|
+
import Foundation
|
7
|
+
|
8
|
+
// swiftlint:disable superfluous_disable_command
|
9
|
+
// swiftlint:disable file_length
|
10
|
+
|
11
|
+
// MARK: - Plist Files
|
12
|
+
{% macro fileBlock file %}
|
13
|
+
{% call documentBlock file file.document %}
|
14
|
+
{% endmacro %}
|
15
|
+
{% macro documentBlock file document %}
|
16
|
+
{% set rootType %}{% call typeBlock document.metadata %}{% endset %}
|
17
|
+
{% if document.metadata.type == "Array" %}
|
18
|
+
{{accessModifier}} static let items: {{rootType}} = arrayFromPlist(at: "{% call transformPath file.path %}")
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
20
|
+
private static let _document = PlistDocument(path: "{% call transformPath file.path %}")
|
21
|
+
|
22
|
+
{% for key,value in document.metadata.properties %}
|
23
|
+
{{accessModifier}} {% call propertyBlock key value %}
|
24
|
+
{% endfor %}
|
25
|
+
{% else %}
|
26
|
+
// Unsupported root type `{{rootType}}`
|
27
|
+
{% endif %}
|
28
|
+
{% endmacro %}
|
29
|
+
{% macro typeBlock metadata %}{% filter removeNewlines:"leading" %}
|
30
|
+
{% if metadata.type == "Array" %}
|
31
|
+
[{% call typeBlock metadata.element %}]
|
32
|
+
{% elif metadata.type == "Dictionary" %}
|
33
|
+
[String: Any]
|
34
|
+
{% else %}
|
35
|
+
{{metadata.type}}
|
36
|
+
{% endif %}
|
37
|
+
{% endfilter %}{% endmacro %}
|
38
|
+
{% macro propertyBlock key metadata %}{% filter removeNewlines:"leading" %}
|
39
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
40
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
41
|
+
static let {{propertyName}}: {{propertyType}} = _document["{{key}}"]
|
42
|
+
{% endfilter %}{% endmacro %}
|
43
|
+
{% macro transformPath path %}{% filter removeNewlines %}
|
44
|
+
{% if param.preservePath %}
|
45
|
+
{{path}}
|
46
|
+
{% else %}
|
47
|
+
{{path|basename}}
|
48
|
+
{% endif %}
|
49
|
+
{% endfilter %}{% endmacro %}
|
50
|
+
|
51
|
+
// swiftlint:disable identifier_name line_length type_body_length
|
52
|
+
{{accessModifier}} enum {{param.enumName|default:"PlistFiles"}} {
|
53
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
54
|
+
{% for file in files %}
|
55
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
56
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
57
|
+
}
|
58
|
+
{% endfor %}
|
59
|
+
{% else %}
|
60
|
+
{% call fileBlock files.first %}
|
61
|
+
{% endif %}
|
62
|
+
}
|
63
|
+
// swiftlint:enable identifier_name line_length type_body_length
|
64
|
+
|
65
|
+
// MARK: - Implementation Details
|
66
|
+
|
67
|
+
private func arrayFromPlist<T>(at path: String) -> [T] {
|
68
|
+
{% if param.lookupFunction %}
|
69
|
+
guard let url = {{param.lookupFunction}}(path),
|
70
|
+
{% else %}
|
71
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
72
|
+
{% endif %}
|
73
|
+
let data = NSArray(contentsOf: url) as? [T] else {
|
74
|
+
fatalError("Unable to load PLIST at path: \(path)")
|
75
|
+
}
|
76
|
+
return data
|
77
|
+
}
|
78
|
+
|
79
|
+
private struct PlistDocument {
|
80
|
+
let data: [String: Any]
|
81
|
+
|
82
|
+
init(path: String) {
|
83
|
+
{% if param.lookupFunction %}
|
84
|
+
guard let url = {{param.lookupFunction}}(path),
|
85
|
+
{% else %}
|
86
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
87
|
+
{% endif %}
|
88
|
+
let data = NSDictionary(contentsOf: url) as? [String: Any] else {
|
89
|
+
fatalError("Unable to load PLIST at path: \(path)")
|
90
|
+
}
|
91
|
+
self.data = data
|
92
|
+
}
|
93
|
+
|
94
|
+
subscript<T>(key: String) -> T {
|
95
|
+
guard let result = data[key] as? T else {
|
96
|
+
fatalError("Property '\(key)' is not of type \(T.self)")
|
97
|
+
}
|
98
|
+
return result
|
99
|
+
}
|
100
|
+
}
|
101
|
+
{% if not param.bundle and not param.lookupFunction %}
|
102
|
+
|
103
|
+
// swiftlint:disable convenience_type
|
104
|
+
private final class BundleToken {
|
105
|
+
static let bundle: Bundle = {
|
106
|
+
#if SWIFT_PACKAGE
|
107
|
+
return Bundle.module
|
108
|
+
#else
|
109
|
+
return Bundle(for: BundleToken.self)
|
110
|
+
#endif
|
111
|
+
}()
|
112
|
+
}
|
113
|
+
// swiftlint:enable convenience_type
|
114
|
+
{% endif %}
|
115
|
+
{% else %}
|
116
|
+
// No files found
|
117
|
+
{% endif %}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if tables.count > 0 %}
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
6
|
+
import Foundation
|
7
|
+
|
8
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
9
|
+
|
10
|
+
// MARK: - Strings
|
11
|
+
|
12
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
13
|
+
{% for type in types %}
|
14
|
+
{% if type == "String" %}
|
15
|
+
_ p{{forloop.counter}}: Any
|
16
|
+
{% else %}
|
17
|
+
_ p{{forloop.counter}}: {{type}}
|
18
|
+
{% endif %}
|
19
|
+
{{ ", " if not forloop.last }}
|
20
|
+
{% endfor %}
|
21
|
+
{% endfilter %}{% endmacro %}
|
22
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
23
|
+
{% for type in types %}
|
24
|
+
{% if type == "String" %}
|
25
|
+
String(describing: p{{forloop.counter}})
|
26
|
+
{% elif type == "UnsafeRawPointer" %}
|
27
|
+
Int(bitPattern: p{{forloop.counter}})
|
28
|
+
{% else %}
|
29
|
+
p{{forloop.counter}}
|
30
|
+
{% endif %}
|
31
|
+
{{ ", " if not forloop.last }}
|
32
|
+
{% endfor %}
|
33
|
+
{% endfilter %}{% endmacro %}
|
34
|
+
{% macro recursiveBlock table item %}
|
35
|
+
{% for string in item.strings %}
|
36
|
+
{% if not param.noComments %}
|
37
|
+
/// {{string.translation}}
|
38
|
+
{% endif %}
|
39
|
+
{% if string.types %}
|
40
|
+
{{accessModifier}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
|
41
|
+
return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
|
42
|
+
}
|
43
|
+
{% elif param.lookupFunction %}
|
44
|
+
{# custom localization function is mostly used for in-app lang selection, so we want the loc to be recomputed at each call for those (hence the computed var) #}
|
45
|
+
{{accessModifier}} static var {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}") }
|
46
|
+
{% else %}
|
47
|
+
{{accessModifier}} static let {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}")
|
48
|
+
{% endif %}
|
49
|
+
{% endfor %}
|
50
|
+
{% for child in item.children %}
|
51
|
+
{% call recursiveBlock table child %}
|
52
|
+
{% endfor %}
|
53
|
+
{% endmacro %}
|
54
|
+
// swiftlint:disable function_parameter_count identifier_name line_length type_body_length
|
55
|
+
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
|
56
|
+
{{accessModifier}} enum {{enumName}} {
|
57
|
+
{% if tables.count > 1 or param.forceFileNameEnum %}
|
58
|
+
{% for table in tables %}
|
59
|
+
{{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
60
|
+
{% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %}
|
61
|
+
}
|
62
|
+
{% endfor %}
|
63
|
+
{% else %}
|
64
|
+
{% call recursiveBlock tables.first.name tables.first.levels %}
|
65
|
+
{% endif %}
|
66
|
+
}
|
67
|
+
// swiftlint:enable function_parameter_count identifier_name line_length type_body_length
|
68
|
+
|
69
|
+
// MARK: - Implementation Details
|
70
|
+
|
71
|
+
extension {{enumName}} {
|
72
|
+
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
73
|
+
{% if param.lookupFunction %}
|
74
|
+
let format = {{ param.lookupFunction }}(key, table)
|
75
|
+
{% else %}
|
76
|
+
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: nil, table: table)
|
77
|
+
{% endif %}
|
78
|
+
return String(format: format, locale: Locale.current, arguments: args)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
{% if not param.bundle and not param.lookupFunction %}
|
82
|
+
|
83
|
+
// swiftlint:disable convenience_type
|
84
|
+
private final class BundleToken {
|
85
|
+
static let bundle: Bundle = {
|
86
|
+
#if SWIFT_PACKAGE
|
87
|
+
return Bundle.module
|
88
|
+
#else
|
89
|
+
return Bundle(for: BundleToken.self)
|
90
|
+
#endif
|
91
|
+
}()
|
92
|
+
}
|
93
|
+
// swiftlint:enable convenience_type
|
94
|
+
{% endif %}
|
95
|
+
{% else %}
|
96
|
+
// No string found
|
97
|
+
{% endif %}
|