danger-localizationlinter 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,60 @@
|
|
|
1
|
+
// swiftlint:disable all
|
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
3
|
+
|
|
4
|
+
{% if platform and storyboards %}
|
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
|
6
|
+
{% set isAppKit %}{% if platform == "macOS" %}true{% endif %}{% endset %}
|
|
7
|
+
// swiftlint:disable sorted_imports
|
|
8
|
+
import Foundation
|
|
9
|
+
{% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %}
|
|
10
|
+
import {{module}}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
|
|
13
|
+
// swiftlint:disable superfluous_disable_command
|
|
14
|
+
// swiftlint:disable file_length
|
|
15
|
+
|
|
16
|
+
// MARK: - Storyboard Segues
|
|
17
|
+
|
|
18
|
+
// swiftlint:disable explicit_type_interface identifier_name line_length type_body_length type_name
|
|
19
|
+
{{accessModifier}} enum {{param.enumName|default:"StoryboardSegue"}} {
|
|
20
|
+
{% for storyboard in storyboards where storyboard.segues %}
|
|
21
|
+
{{accessModifier}} enum {{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}: String, SegueType {
|
|
22
|
+
{% for segue in storyboard.segues %}
|
|
23
|
+
{% set segueID %}{{segue.identifier|swiftIdentifier:"pretty"|lowerFirstWord}}{% endset %}
|
|
24
|
+
case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %}
|
|
25
|
+
{% endfor %}
|
|
26
|
+
}
|
|
27
|
+
{% endfor %}
|
|
28
|
+
}
|
|
29
|
+
// swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name
|
|
30
|
+
|
|
31
|
+
// MARK: - Implementation Details
|
|
32
|
+
|
|
33
|
+
{{accessModifier}} protocol SegueType: RawRepresentable {}
|
|
34
|
+
|
|
35
|
+
{{accessModifier}} extension {% if isAppKit %}NSSeguePerforming{% else %}UIViewController{% endif %} {
|
|
36
|
+
func perform<S: SegueType>(segue: S, sender: Any? = nil) where S.RawValue == String {
|
|
37
|
+
let identifier = {% if isAppKit %}NSStoryboardSegue.Identifier({% endif %}segue.rawValue{% if isAppKit %}){% endif %}
|
|
38
|
+
performSegue{% if isAppKit %}?{% endif %}(withIdentifier: identifier, sender: sender)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
{{accessModifier}} extension SegueType where RawValue == String {
|
|
43
|
+
init?(_ segue: {% if isAppKit %}NS{% else %}UI{% endif %}StoryboardSegue) {
|
|
44
|
+
{% if isAppKit %}
|
|
45
|
+
#if swift(>=4.2)
|
|
46
|
+
guard let identifier = segue.identifier else { return nil }
|
|
47
|
+
#else
|
|
48
|
+
guard let identifier = segue.identifier?.rawValue else { return nil }
|
|
49
|
+
#endif
|
|
50
|
+
{% else %}
|
|
51
|
+
guard let identifier = segue.identifier else { return nil }
|
|
52
|
+
{% endif %}
|
|
53
|
+
self.init(rawValue: identifier)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
{% elif storyboards %}
|
|
57
|
+
// Mixed AppKit and UIKit storyboard files found, please invoke swiftgen with these separately
|
|
58
|
+
{% else %}
|
|
59
|
+
// No storyboard found
|
|
60
|
+
{% endif %}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// swiftlint:disable all
|
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
3
|
+
|
|
4
|
+
{% if platform and storyboards %}
|
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
|
6
|
+
{% set isAppKit %}{% if platform == "macOS" %}true{% endif %}{% endset %}
|
|
7
|
+
// swiftlint:disable sorted_imports
|
|
8
|
+
import Foundation
|
|
9
|
+
{% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %}
|
|
10
|
+
import {{module}}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
|
|
13
|
+
// swiftlint:disable superfluous_disable_command
|
|
14
|
+
// swiftlint:disable file_length
|
|
15
|
+
|
|
16
|
+
// MARK: - Storyboard Segues
|
|
17
|
+
|
|
18
|
+
// swiftlint:disable explicit_type_interface identifier_name line_length type_body_length type_name
|
|
19
|
+
{{accessModifier}} enum {{param.enumName|default:"StoryboardSegue"}} {
|
|
20
|
+
{% for storyboard in storyboards where storyboard.segues %}
|
|
21
|
+
{{accessModifier}} enum {{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}: String, SegueType {
|
|
22
|
+
{% for segue in storyboard.segues %}
|
|
23
|
+
{% set segueID %}{{segue.identifier|swiftIdentifier:"pretty"|lowerFirstWord}}{% endset %}
|
|
24
|
+
case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %}
|
|
25
|
+
{% endfor %}
|
|
26
|
+
}
|
|
27
|
+
{% endfor %}
|
|
28
|
+
}
|
|
29
|
+
// swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name
|
|
30
|
+
|
|
31
|
+
// MARK: - Implementation Details
|
|
32
|
+
|
|
33
|
+
{{accessModifier}} protocol SegueType: RawRepresentable {}
|
|
34
|
+
|
|
35
|
+
{{accessModifier}} extension {% if isAppKit %}NSSeguePerforming{% else %}UIViewController{% endif %} {
|
|
36
|
+
func perform<S: SegueType>(segue: S, sender: Any? = nil) where S.RawValue == String {
|
|
37
|
+
let identifier = {% if isAppKit %}NSStoryboardSegue.Identifier({% endif %}segue.rawValue{% if isAppKit %}){% endif %}
|
|
38
|
+
performSegue{% if isAppKit %}?{% endif %}(withIdentifier: identifier, sender: sender)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
{{accessModifier}} extension SegueType where RawValue == String {
|
|
43
|
+
init?(_ segue: {% if isAppKit %}NS{% else %}UI{% endif %}StoryboardSegue) {
|
|
44
|
+
{% if isAppKit %}
|
|
45
|
+
#if swift(>=4.2)
|
|
46
|
+
guard let identifier = segue.identifier else { return nil }
|
|
47
|
+
#else
|
|
48
|
+
guard let identifier = segue.identifier?.rawValue else { return nil }
|
|
49
|
+
#endif
|
|
50
|
+
{% else %}
|
|
51
|
+
guard let identifier = segue.identifier else { return nil }
|
|
52
|
+
{% endif %}
|
|
53
|
+
self.init(rawValue: identifier)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
{% elif storyboards %}
|
|
57
|
+
// Mixed AppKit and UIKit storyboard files found, please invoke swiftgen with these separately
|
|
58
|
+
{% else %}
|
|
59
|
+
// No storyboard found
|
|
60
|
+
{% 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: - JSON 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
|
+
{% elif metadata.type == "Optional" %}
|
|
33
|
+
Any?
|
|
34
|
+
{% else %}
|
|
35
|
+
{{metadata.type}}
|
|
36
|
+
{% endif %}
|
|
37
|
+
{% endfilter %}{% endmacro %}
|
|
38
|
+
{% macro propertyBlock key metadata data %}{% filter removeNewlines:"leading" %}
|
|
39
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
|
40
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
|
41
|
+
static let {{propertyName}}: {{propertyType}} = {% call valueBlock data[key] metadata %}
|
|
42
|
+
{% endfilter %}{% endmacro %}
|
|
43
|
+
{% macro valueBlock value metadata %}{% filter removeNewlines:"leading" %}
|
|
44
|
+
{% if metadata.type == "String" %}
|
|
45
|
+
"{{ value }}"
|
|
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:"JSONFiles"}} {
|
|
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: - JSON 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
|
+
{% elif metadata.type == "Optional" %}
|
|
33
|
+
Any?
|
|
34
|
+
{% else %}
|
|
35
|
+
{{metadata.type}}
|
|
36
|
+
{% endif %}
|
|
37
|
+
{% endfilter %}{% endmacro %}
|
|
38
|
+
{% macro propertyBlock key metadata data %}{% filter removeNewlines:"leading" %}
|
|
39
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
|
40
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
|
41
|
+
static let {{propertyName}}: {{propertyType}} = {% call valueBlock data[key] metadata %}
|
|
42
|
+
{% endfilter %}{% endmacro %}
|
|
43
|
+
{% macro valueBlock value metadata %}{% filter removeNewlines:"leading" %}
|
|
44
|
+
{% if metadata.type == "String" %}
|
|
45
|
+
"{{ value }}"
|
|
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:"JSONFiles"}} {
|
|
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,112 @@
|
|
|
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: - JSON 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}} = objectFromJSON(at: "{% call transformPath file.path %}")
|
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
|
20
|
+
private static let _document = JSONDocument(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
|
+
{{accessModifier}} static let value: {{rootType}} = objectFromJSON(at: "{% call transformPath file.path %}")
|
|
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
|
+
{% elif metadata.type == "Optional" %}
|
|
35
|
+
Any?
|
|
36
|
+
{% else %}
|
|
37
|
+
{{metadata.type}}
|
|
38
|
+
{% endif %}
|
|
39
|
+
{% endfilter %}{% endmacro %}
|
|
40
|
+
{% macro propertyBlock key metadata %}{% filter removeNewlines:"leading" %}
|
|
41
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
|
42
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
|
43
|
+
static let {{propertyName}}: {{propertyType}} = _document["{{key}}"]
|
|
44
|
+
{% endfilter %}{% endmacro %}
|
|
45
|
+
{% macro transformPath path %}{% filter removeNewlines %}
|
|
46
|
+
{% if param.preservePath %}
|
|
47
|
+
{{path}}
|
|
48
|
+
{% else %}
|
|
49
|
+
{{path|basename}}
|
|
50
|
+
{% endif %}
|
|
51
|
+
{% endfilter %}{% endmacro %}
|
|
52
|
+
|
|
53
|
+
// swiftlint:disable identifier_name line_length type_body_length
|
|
54
|
+
{{accessModifier}} enum {{param.enumName|default:"JSONFiles"}} {
|
|
55
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
|
56
|
+
{% for file in files %}
|
|
57
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
58
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
|
59
|
+
}
|
|
60
|
+
{% endfor %}
|
|
61
|
+
{% else %}
|
|
62
|
+
{% call fileBlock files.first %}
|
|
63
|
+
{% endif %}
|
|
64
|
+
}
|
|
65
|
+
// swiftlint:enable identifier_name line_length type_body_length
|
|
66
|
+
|
|
67
|
+
// MARK: - Implementation Details
|
|
68
|
+
|
|
69
|
+
private func objectFromJSON<T>(at path: String) -> T {
|
|
70
|
+
{% if param.lookupFunction %}
|
|
71
|
+
guard let url = {{param.lookupFunction}}(path),
|
|
72
|
+
{% else %}
|
|
73
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
|
74
|
+
{% endif %}
|
|
75
|
+
let json = try? JSONSerialization.jsonObject(with: Data(contentsOf: url), options: []),
|
|
76
|
+
let result = json as? T else {
|
|
77
|
+
fatalError("Unable to load JSON at path: \(path)")
|
|
78
|
+
}
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private struct JSONDocument {
|
|
83
|
+
let data: [String: Any]
|
|
84
|
+
|
|
85
|
+
init(path: String) {
|
|
86
|
+
self.data = objectFromJSON(at: path)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
subscript<T>(key: String) -> T {
|
|
90
|
+
guard let result = data[key] as? T else {
|
|
91
|
+
fatalError("Property '\(key)' is not of type \(T.self)")
|
|
92
|
+
}
|
|
93
|
+
return result
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
{% if not param.bundle and not param.lookupFunction %}
|
|
97
|
+
|
|
98
|
+
// swiftlint:disable convenience_type
|
|
99
|
+
private final class BundleToken {
|
|
100
|
+
static let bundle: Bundle = {
|
|
101
|
+
#if SWIFT_PACKAGE
|
|
102
|
+
return Bundle.module
|
|
103
|
+
#else
|
|
104
|
+
return Bundle(for: BundleToken.self)
|
|
105
|
+
#endif
|
|
106
|
+
}()
|
|
107
|
+
}
|
|
108
|
+
// swiftlint:enable convenience_type
|
|
109
|
+
{% endif %}
|
|
110
|
+
{% else %}
|
|
111
|
+
// No files found
|
|
112
|
+
{% endif %}
|
|
@@ -0,0 +1,112 @@
|
|
|
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: - JSON 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}} = objectFromJSON(at: "{% call transformPath file.path %}")
|
|
19
|
+
{% elif document.metadata.type == "Dictionary" %}
|
|
20
|
+
private static let _document = JSONDocument(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
|
+
{{accessModifier}} static let value: {{rootType}} = objectFromJSON(at: "{% call transformPath file.path %}")
|
|
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
|
+
{% elif metadata.type == "Optional" %}
|
|
35
|
+
Any?
|
|
36
|
+
{% else %}
|
|
37
|
+
{{metadata.type}}
|
|
38
|
+
{% endif %}
|
|
39
|
+
{% endfilter %}{% endmacro %}
|
|
40
|
+
{% macro propertyBlock key metadata %}{% filter removeNewlines:"leading" %}
|
|
41
|
+
{% set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
|
|
42
|
+
{% set propertyType %}{% call typeBlock metadata %}{% endset %}
|
|
43
|
+
static let {{propertyName}}: {{propertyType}} = _document["{{key}}"]
|
|
44
|
+
{% endfilter %}{% endmacro %}
|
|
45
|
+
{% macro transformPath path %}{% filter removeNewlines %}
|
|
46
|
+
{% if param.preservePath %}
|
|
47
|
+
{{path}}
|
|
48
|
+
{% else %}
|
|
49
|
+
{{path|basename}}
|
|
50
|
+
{% endif %}
|
|
51
|
+
{% endfilter %}{% endmacro %}
|
|
52
|
+
|
|
53
|
+
// swiftlint:disable identifier_name line_length type_body_length
|
|
54
|
+
{{accessModifier}} enum {{param.enumName|default:"JSONFiles"}} {
|
|
55
|
+
{% if files.count > 1 or param.forceFileNameEnum %}
|
|
56
|
+
{% for file in files %}
|
|
57
|
+
{{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
58
|
+
{% filter indent:2 %}{% call fileBlock file %}{% endfilter %}
|
|
59
|
+
}
|
|
60
|
+
{% endfor %}
|
|
61
|
+
{% else %}
|
|
62
|
+
{% call fileBlock files.first %}
|
|
63
|
+
{% endif %}
|
|
64
|
+
}
|
|
65
|
+
// swiftlint:enable identifier_name line_length type_body_length
|
|
66
|
+
|
|
67
|
+
// MARK: - Implementation Details
|
|
68
|
+
|
|
69
|
+
private func objectFromJSON<T>(at path: String) -> T {
|
|
70
|
+
{% if param.lookupFunction %}
|
|
71
|
+
guard let url = {{param.lookupFunction}}(path),
|
|
72
|
+
{% else %}
|
|
73
|
+
guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
|
|
74
|
+
{% endif %}
|
|
75
|
+
let json = try? JSONSerialization.jsonObject(with: Data(contentsOf: url), options: []),
|
|
76
|
+
let result = json as? T else {
|
|
77
|
+
fatalError("Unable to load JSON at path: \(path)")
|
|
78
|
+
}
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private struct JSONDocument {
|
|
83
|
+
let data: [String: Any]
|
|
84
|
+
|
|
85
|
+
init(path: String) {
|
|
86
|
+
self.data = objectFromJSON(at: path)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
subscript<T>(key: String) -> T {
|
|
90
|
+
guard let result = data[key] as? T else {
|
|
91
|
+
fatalError("Property '\(key)' is not of type \(T.self)")
|
|
92
|
+
}
|
|
93
|
+
return result
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
{% if not param.bundle and not param.lookupFunction %}
|
|
97
|
+
|
|
98
|
+
// swiftlint:disable convenience_type
|
|
99
|
+
private final class BundleToken {
|
|
100
|
+
static let bundle: Bundle = {
|
|
101
|
+
#if SWIFT_PACKAGE
|
|
102
|
+
return Bundle.module
|
|
103
|
+
#else
|
|
104
|
+
return Bundle(for: BundleToken.self)
|
|
105
|
+
#endif
|
|
106
|
+
}()
|
|
107
|
+
}
|
|
108
|
+
// swiftlint:enable convenience_type
|
|
109
|
+
{% endif %}
|
|
110
|
+
{% else %}
|
|
111
|
+
// No files found
|
|
112
|
+
{% endif %}
|