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,266 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if catalogs %}
|
5
|
+
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
|
6
|
+
{% set arResourceGroupType %}{{param.arResourceGroupTypeName|default:"ARResourceGroupAsset"}}{% endset %}
|
7
|
+
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
|
8
|
+
{% set dataType %}{{param.dataTypeName|default:"DataAsset"}}{% endset %}
|
9
|
+
{% set imageType %}{{param.imageTypeName|default:"ImageAsset"}}{% endset %}
|
10
|
+
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
|
11
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
12
|
+
#if os(macOS)
|
13
|
+
import AppKit
|
14
|
+
#elseif os(iOS)
|
15
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
16
|
+
import ARKit
|
17
|
+
{% endif %}
|
18
|
+
import UIKit
|
19
|
+
#elseif os(tvOS) || os(watchOS)
|
20
|
+
import UIKit
|
21
|
+
#endif
|
22
|
+
|
23
|
+
// Deprecated typealiases
|
24
|
+
{% if resourceCount.color > 0 %}
|
25
|
+
@available(*, deprecated, renamed: "{{colorType}}.Color", message: "This typealias will be removed in SwiftGen 7.0")
|
26
|
+
{{accessModifier}} typealias {{param.colorAliasName|default:"AssetColorTypeAlias"}} = {{colorType}}.Color
|
27
|
+
{% endif %}
|
28
|
+
{% if resourceCount.image > 0 %}
|
29
|
+
@available(*, deprecated, renamed: "{{imageType}}.Image", message: "This typealias will be removed in SwiftGen 7.0")
|
30
|
+
{{accessModifier}} typealias {{param.imageAliasName|default:"AssetImageTypeAlias"}} = {{imageType}}.Image
|
31
|
+
{% endif %}
|
32
|
+
|
33
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
34
|
+
|
35
|
+
// MARK: - Asset Catalogs
|
36
|
+
|
37
|
+
{% macro enumBlock assets %}
|
38
|
+
{% call casesBlock assets %}
|
39
|
+
{% if param.allValues %}
|
40
|
+
|
41
|
+
// swiftlint:disable trailing_comma
|
42
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
43
|
+
{{accessModifier}} static let allResourceGroups: [{{arResourceGroupType}}] = [
|
44
|
+
{% filter indent:2 %}{% call allValuesBlock assets "arresourcegroup" "" %}{% endfilter %}
|
45
|
+
]
|
46
|
+
{% endif %}
|
47
|
+
{% if resourceCount.color > 0 %}
|
48
|
+
{{accessModifier}} static let allColors: [{{colorType}}] = [
|
49
|
+
{% filter indent:2 %}{% call allValuesBlock assets "color" "" %}{% endfilter %}
|
50
|
+
]
|
51
|
+
{% endif %}
|
52
|
+
{% if resourceCount.data > 0 %}
|
53
|
+
{{accessModifier}} static let allDataAssets: [{{dataType}}] = [
|
54
|
+
{% filter indent:2 %}{% call allValuesBlock assets "data" "" %}{% endfilter %}
|
55
|
+
]
|
56
|
+
{% endif %}
|
57
|
+
{% if resourceCount.image > 0 %}
|
58
|
+
{{accessModifier}} static let allImages: [{{imageType}}] = [
|
59
|
+
{% filter indent:2 %}{% call allValuesBlock assets "image" "" %}{% endfilter %}
|
60
|
+
]
|
61
|
+
{% endif %}
|
62
|
+
// swiftlint:enable trailing_comma
|
63
|
+
{% endif %}
|
64
|
+
{% endmacro %}
|
65
|
+
{% macro casesBlock assets %}
|
66
|
+
{% for asset in assets %}
|
67
|
+
{% if asset.type == "arresourcegroup" %}
|
68
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{arResourceGroupType}}(name: "{{asset.value}}")
|
69
|
+
{% elif asset.type == "color" %}
|
70
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}")
|
71
|
+
{% elif asset.type == "data" %}
|
72
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{dataType}}(name: "{{asset.value}}")
|
73
|
+
{% elif asset.type == "image" %}
|
74
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}")
|
75
|
+
{% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
|
76
|
+
{{accessModifier}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
77
|
+
{% filter indent:2 %}{% call casesBlock asset.items %}{% endfilter %}
|
78
|
+
}
|
79
|
+
{% elif asset.items %}
|
80
|
+
{% call casesBlock asset.items %}
|
81
|
+
{% endif %}
|
82
|
+
{% endfor %}
|
83
|
+
{% endmacro %}
|
84
|
+
{% macro allValuesBlock assets filter prefix %}
|
85
|
+
{% for asset in assets %}
|
86
|
+
{% if asset.type == filter %}
|
87
|
+
{{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}},
|
88
|
+
{% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
|
89
|
+
{% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %}
|
90
|
+
{% call allValuesBlock asset.items filter prefix2 %}
|
91
|
+
{% elif asset.items %}
|
92
|
+
{% call allValuesBlock asset.items filter prefix %}
|
93
|
+
{% endif %}
|
94
|
+
{% endfor %}
|
95
|
+
{% endmacro %}
|
96
|
+
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
|
97
|
+
{{accessModifier}} enum {{enumName}} {
|
98
|
+
{% if catalogs.count > 1 or param.forceFileNameEnum %}
|
99
|
+
{% for catalog in catalogs %}
|
100
|
+
{{accessModifier}} enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
101
|
+
{% filter indent:2 %}{% call enumBlock catalog.assets %}{% endfilter %}
|
102
|
+
}
|
103
|
+
{% endfor %}
|
104
|
+
{% else %}
|
105
|
+
{% call enumBlock catalogs.first.assets %}
|
106
|
+
{% endif %}
|
107
|
+
}
|
108
|
+
// swiftlint:enable identifier_name line_length nesting type_body_length type_name
|
109
|
+
|
110
|
+
// MARK: - Implementation Details
|
111
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
112
|
+
|
113
|
+
{{accessModifier}} struct {{arResourceGroupType}} {
|
114
|
+
{{accessModifier}} fileprivate(set) var name: String
|
115
|
+
|
116
|
+
#if os(iOS)
|
117
|
+
@available(iOS 11.3, *)
|
118
|
+
{{accessModifier}} var referenceImages: Set<ARReferenceImage> {
|
119
|
+
return ARReferenceImage.referenceImages(in: self)
|
120
|
+
}
|
121
|
+
|
122
|
+
@available(iOS 12.0, *)
|
123
|
+
{{accessModifier}} var referenceObjects: Set<ARReferenceObject> {
|
124
|
+
return ARReferenceObject.referenceObjects(in: self)
|
125
|
+
}
|
126
|
+
#endif
|
127
|
+
}
|
128
|
+
|
129
|
+
#if os(iOS)
|
130
|
+
@available(iOS 11.3, *)
|
131
|
+
{{accessModifier}} extension ARReferenceImage {
|
132
|
+
static func referenceImages(in asset: {{arResourceGroupType}}) -> Set<ARReferenceImage> {
|
133
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
134
|
+
return referenceImages(inGroupNamed: asset.name, bundle: bundle) ?? Set()
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
@available(iOS 12.0, *)
|
139
|
+
{{accessModifier}} extension ARReferenceObject {
|
140
|
+
static func referenceObjects(in asset: {{arResourceGroupType}}) -> Set<ARReferenceObject> {
|
141
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
142
|
+
return referenceObjects(inGroupNamed: asset.name, bundle: bundle) ?? Set()
|
143
|
+
}
|
144
|
+
}
|
145
|
+
#endif
|
146
|
+
{% endif %}
|
147
|
+
{% if resourceCount.color > 0 %}
|
148
|
+
|
149
|
+
{{accessModifier}} final class {{colorType}} {
|
150
|
+
{{accessModifier}} fileprivate(set) var name: String
|
151
|
+
|
152
|
+
#if os(macOS)
|
153
|
+
{{accessModifier}} typealias Color = NSColor
|
154
|
+
#elseif os(iOS) || os(tvOS) || os(watchOS)
|
155
|
+
{{accessModifier}} typealias Color = UIColor
|
156
|
+
#endif
|
157
|
+
|
158
|
+
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
|
159
|
+
{{accessModifier}} private(set) lazy var color: Color = Color(asset: self)
|
160
|
+
|
161
|
+
fileprivate init(name: String) {
|
162
|
+
self.name = name
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
{{accessModifier}} extension {{colorType}}.Color {
|
167
|
+
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
|
168
|
+
convenience init!(asset: {{colorType}}) {
|
169
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
170
|
+
#if os(iOS) || os(tvOS)
|
171
|
+
self.init(named: asset.name, in: bundle, compatibleWith: nil)
|
172
|
+
#elseif os(macOS)
|
173
|
+
self.init(named: NSColor.Name(asset.name), bundle: bundle)
|
174
|
+
#elseif os(watchOS)
|
175
|
+
self.init(named: asset.name)
|
176
|
+
#endif
|
177
|
+
}
|
178
|
+
}
|
179
|
+
{% endif %}
|
180
|
+
{% if resourceCount.data > 0 %}
|
181
|
+
|
182
|
+
{{accessModifier}} struct {{dataType}} {
|
183
|
+
{{accessModifier}} fileprivate(set) var name: String
|
184
|
+
|
185
|
+
#if os(iOS) || os(tvOS) || os(macOS)
|
186
|
+
@available(iOS 9.0, macOS 10.11, *)
|
187
|
+
{{accessModifier}} var data: NSDataAsset {
|
188
|
+
return NSDataAsset(asset: self)
|
189
|
+
}
|
190
|
+
#endif
|
191
|
+
}
|
192
|
+
|
193
|
+
#if os(iOS) || os(tvOS) || os(macOS)
|
194
|
+
@available(iOS 9.0, macOS 10.11, *)
|
195
|
+
{{accessModifier}} extension NSDataAsset {
|
196
|
+
convenience init!(asset: {{dataType}}) {
|
197
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
198
|
+
#if os(iOS) || os(tvOS)
|
199
|
+
self.init(name: asset.name, bundle: bundle)
|
200
|
+
#elseif os(macOS)
|
201
|
+
self.init(name: NSDataAsset.Name(asset.name), bundle: bundle)
|
202
|
+
#endif
|
203
|
+
}
|
204
|
+
}
|
205
|
+
#endif
|
206
|
+
{% endif %}
|
207
|
+
{% if resourceCount.image > 0 %}
|
208
|
+
|
209
|
+
{{accessModifier}} struct {{imageType}} {
|
210
|
+
{{accessModifier}} fileprivate(set) var name: String
|
211
|
+
|
212
|
+
#if os(macOS)
|
213
|
+
{{accessModifier}} typealias Image = NSImage
|
214
|
+
#elseif os(iOS) || os(tvOS) || os(watchOS)
|
215
|
+
{{accessModifier}} typealias Image = UIImage
|
216
|
+
#endif
|
217
|
+
|
218
|
+
{{accessModifier}} var image: Image {
|
219
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
220
|
+
#if os(iOS) || os(tvOS)
|
221
|
+
let image = Image(named: name, in: bundle, compatibleWith: nil)
|
222
|
+
#elseif os(macOS)
|
223
|
+
let name = NSImage.Name(self.name)
|
224
|
+
let image = (bundle == .main) ? NSImage(named: name) : bundle.image(forResource: name)
|
225
|
+
#elseif os(watchOS)
|
226
|
+
let image = Image(named: name)
|
227
|
+
#endif
|
228
|
+
guard let result = image else {
|
229
|
+
fatalError("Unable to load image named \(name).")
|
230
|
+
}
|
231
|
+
return result
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
{{accessModifier}} extension {{imageType}}.Image {
|
236
|
+
@available(macOS, deprecated,
|
237
|
+
message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property")
|
238
|
+
convenience init!(asset: {{imageType}}) {
|
239
|
+
#if os(iOS) || os(tvOS)
|
240
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
241
|
+
self.init(named: asset.name, in: bundle, compatibleWith: nil)
|
242
|
+
#elseif os(macOS)
|
243
|
+
self.init(named: NSImage.Name(asset.name))
|
244
|
+
#elseif os(watchOS)
|
245
|
+
self.init(named: asset.name)
|
246
|
+
#endif
|
247
|
+
}
|
248
|
+
}
|
249
|
+
{% endif %}
|
250
|
+
{% if not param.bundle %}
|
251
|
+
|
252
|
+
// swiftlint:disable convenience_type
|
253
|
+
private final class BundleToken {
|
254
|
+
static let bundle: Bundle = {
|
255
|
+
#if SWIFT_PACKAGE
|
256
|
+
return Bundle.module
|
257
|
+
#else
|
258
|
+
return Bundle(for: BundleToken.self)
|
259
|
+
#endif
|
260
|
+
}()
|
261
|
+
}
|
262
|
+
// swiftlint:enable convenience_type
|
263
|
+
{% endif %}
|
264
|
+
{% else %}
|
265
|
+
// No assets found
|
266
|
+
{% endif %}
|
@@ -0,0 +1,274 @@
|
|
1
|
+
// swiftlint:disable all
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
3
|
+
|
4
|
+
{% if catalogs %}
|
5
|
+
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
|
6
|
+
{% set arResourceGroupType %}{{param.arResourceGroupTypeName|default:"ARResourceGroupAsset"}}{% endset %}
|
7
|
+
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
|
8
|
+
{% set dataType %}{{param.dataTypeName|default:"DataAsset"}}{% endset %}
|
9
|
+
{% set imageType %}{{param.imageTypeName|default:"ImageAsset"}}{% endset %}
|
10
|
+
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
|
11
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
12
|
+
#if os(macOS)
|
13
|
+
import AppKit
|
14
|
+
#elseif os(iOS)
|
15
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
16
|
+
import ARKit
|
17
|
+
{% endif %}
|
18
|
+
import UIKit
|
19
|
+
#elseif os(tvOS) || os(watchOS)
|
20
|
+
import UIKit
|
21
|
+
#endif
|
22
|
+
|
23
|
+
// Deprecated typealiases
|
24
|
+
{% if resourceCount.color > 0 %}
|
25
|
+
@available(*, deprecated, renamed: "{{colorType}}.Color", message: "This typealias will be removed in SwiftGen 7.0")
|
26
|
+
{{accessModifier}} typealias {{param.colorAliasName|default:"AssetColorTypeAlias"}} = {{colorType}}.Color
|
27
|
+
{% endif %}
|
28
|
+
{% if resourceCount.image > 0 %}
|
29
|
+
@available(*, deprecated, renamed: "{{imageType}}.Image", message: "This typealias will be removed in SwiftGen 7.0")
|
30
|
+
{{accessModifier}} typealias {{param.imageAliasName|default:"AssetImageTypeAlias"}} = {{imageType}}.Image
|
31
|
+
{% endif %}
|
32
|
+
|
33
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
34
|
+
|
35
|
+
// MARK: - Asset Catalogs
|
36
|
+
|
37
|
+
{% macro enumBlock assets %}
|
38
|
+
{% call casesBlock assets %}
|
39
|
+
{% if param.allValues %}
|
40
|
+
|
41
|
+
// swiftlint:disable trailing_comma
|
42
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
43
|
+
{{accessModifier}} static let allResourceGroups: [{{arResourceGroupType}}] = [
|
44
|
+
{% filter indent:2 %}{% call allValuesBlock assets "arresourcegroup" "" %}{% endfilter %}
|
45
|
+
]
|
46
|
+
{% endif %}
|
47
|
+
{% if resourceCount.color > 0 %}
|
48
|
+
{{accessModifier}} static let allColors: [{{colorType}}] = [
|
49
|
+
{% filter indent:2 %}{% call allValuesBlock assets "color" "" %}{% endfilter %}
|
50
|
+
]
|
51
|
+
{% endif %}
|
52
|
+
{% if resourceCount.data > 0 %}
|
53
|
+
{{accessModifier}} static let allDataAssets: [{{dataType}}] = [
|
54
|
+
{% filter indent:2 %}{% call allValuesBlock assets "data" "" %}{% endfilter %}
|
55
|
+
]
|
56
|
+
{% endif %}
|
57
|
+
{% if resourceCount.image > 0 %}
|
58
|
+
{{accessModifier}} static let allImages: [{{imageType}}] = [
|
59
|
+
{% filter indent:2 %}{% call allValuesBlock assets "image" "" %}{% endfilter %}
|
60
|
+
]
|
61
|
+
{% endif %}
|
62
|
+
// swiftlint:enable trailing_comma
|
63
|
+
{% endif %}
|
64
|
+
{% endmacro %}
|
65
|
+
{% macro casesBlock assets %}
|
66
|
+
{% for asset in assets %}
|
67
|
+
{% if asset.type == "arresourcegroup" %}
|
68
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{arResourceGroupType}}(name: "{{asset.value}}")
|
69
|
+
{% elif asset.type == "color" %}
|
70
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}")
|
71
|
+
{% elif asset.type == "data" %}
|
72
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{dataType}}(name: "{{asset.value}}")
|
73
|
+
{% elif asset.type == "image" %}
|
74
|
+
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}")
|
75
|
+
{% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
|
76
|
+
{{accessModifier}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
77
|
+
{% filter indent:2 %}{% call casesBlock asset.items %}{% endfilter %}
|
78
|
+
}
|
79
|
+
{% elif asset.items %}
|
80
|
+
{% call casesBlock asset.items %}
|
81
|
+
{% endif %}
|
82
|
+
{% endfor %}
|
83
|
+
{% endmacro %}
|
84
|
+
{% macro allValuesBlock assets filter prefix %}
|
85
|
+
{% for asset in assets %}
|
86
|
+
{% if asset.type == filter %}
|
87
|
+
{{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}},
|
88
|
+
{% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
|
89
|
+
{% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %}
|
90
|
+
{% call allValuesBlock asset.items filter prefix2 %}
|
91
|
+
{% elif asset.items %}
|
92
|
+
{% call allValuesBlock asset.items filter prefix %}
|
93
|
+
{% endif %}
|
94
|
+
{% endfor %}
|
95
|
+
{% endmacro %}
|
96
|
+
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
|
97
|
+
{{accessModifier}} enum {{enumName}} {
|
98
|
+
{% if catalogs.count > 1 or param.forceFileNameEnum %}
|
99
|
+
{% for catalog in catalogs %}
|
100
|
+
{{accessModifier}} enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
101
|
+
{% filter indent:2 %}{% call enumBlock catalog.assets %}{% endfilter %}
|
102
|
+
}
|
103
|
+
{% endfor %}
|
104
|
+
{% else %}
|
105
|
+
{% call enumBlock catalogs.first.assets %}
|
106
|
+
{% endif %}
|
107
|
+
}
|
108
|
+
// swiftlint:enable identifier_name line_length nesting type_body_length type_name
|
109
|
+
|
110
|
+
// MARK: - Implementation Details
|
111
|
+
{% if resourceCount.arresourcegroup > 0 %}
|
112
|
+
|
113
|
+
{{accessModifier}} struct {{arResourceGroupType}} {
|
114
|
+
{{accessModifier}} fileprivate(set) var name: String
|
115
|
+
|
116
|
+
#if os(iOS)
|
117
|
+
@available(iOS 11.3, *)
|
118
|
+
{{accessModifier}} var referenceImages: Set<ARReferenceImage> {
|
119
|
+
return ARReferenceImage.referenceImages(in: self)
|
120
|
+
}
|
121
|
+
|
122
|
+
@available(iOS 12.0, *)
|
123
|
+
{{accessModifier}} var referenceObjects: Set<ARReferenceObject> {
|
124
|
+
return ARReferenceObject.referenceObjects(in: self)
|
125
|
+
}
|
126
|
+
#endif
|
127
|
+
}
|
128
|
+
|
129
|
+
#if os(iOS)
|
130
|
+
@available(iOS 11.3, *)
|
131
|
+
{{accessModifier}} extension ARReferenceImage {
|
132
|
+
static func referenceImages(in asset: {{arResourceGroupType}}) -> Set<ARReferenceImage> {
|
133
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
134
|
+
return referenceImages(inGroupNamed: asset.name, bundle: bundle) ?? Set()
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
@available(iOS 12.0, *)
|
139
|
+
{{accessModifier}} extension ARReferenceObject {
|
140
|
+
static func referenceObjects(in asset: {{arResourceGroupType}}) -> Set<ARReferenceObject> {
|
141
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
142
|
+
return referenceObjects(inGroupNamed: asset.name, bundle: bundle) ?? Set()
|
143
|
+
}
|
144
|
+
}
|
145
|
+
#endif
|
146
|
+
{% endif %}
|
147
|
+
{% if resourceCount.color > 0 %}
|
148
|
+
|
149
|
+
{{accessModifier}} final class {{colorType}} {
|
150
|
+
{{accessModifier}} fileprivate(set) var name: String
|
151
|
+
|
152
|
+
#if os(macOS)
|
153
|
+
{{accessModifier}} typealias Color = NSColor
|
154
|
+
#elseif os(iOS) || os(tvOS) || os(watchOS)
|
155
|
+
{{accessModifier}} typealias Color = UIColor
|
156
|
+
#endif
|
157
|
+
|
158
|
+
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
|
159
|
+
{{accessModifier}} private(set) lazy var color: Color = {
|
160
|
+
guard let color = Color(asset: self) else {
|
161
|
+
fatalError("Unable to load color asset named \(name).")
|
162
|
+
}
|
163
|
+
return color
|
164
|
+
}()
|
165
|
+
|
166
|
+
fileprivate init(name: String) {
|
167
|
+
self.name = name
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
{{accessModifier}} extension {{colorType}}.Color {
|
172
|
+
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
|
173
|
+
convenience init?(asset: {{colorType}}) {
|
174
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
175
|
+
#if os(iOS) || os(tvOS)
|
176
|
+
self.init(named: asset.name, in: bundle, compatibleWith: nil)
|
177
|
+
#elseif os(macOS)
|
178
|
+
self.init(named: NSColor.Name(asset.name), bundle: bundle)
|
179
|
+
#elseif os(watchOS)
|
180
|
+
self.init(named: asset.name)
|
181
|
+
#endif
|
182
|
+
}
|
183
|
+
}
|
184
|
+
{% endif %}
|
185
|
+
{% if resourceCount.data > 0 %}
|
186
|
+
|
187
|
+
{{accessModifier}} struct {{dataType}} {
|
188
|
+
{{accessModifier}} fileprivate(set) var name: String
|
189
|
+
|
190
|
+
#if os(iOS) || os(tvOS) || os(macOS)
|
191
|
+
@available(iOS 9.0, macOS 10.11, *)
|
192
|
+
{{accessModifier}} var data: NSDataAsset {
|
193
|
+
guard let data = NSDataAsset(asset: self) else {
|
194
|
+
fatalError("Unable to load data asset named \(name).")
|
195
|
+
}
|
196
|
+
return data
|
197
|
+
}
|
198
|
+
#endif
|
199
|
+
}
|
200
|
+
|
201
|
+
#if os(iOS) || os(tvOS) || os(macOS)
|
202
|
+
@available(iOS 9.0, macOS 10.11, *)
|
203
|
+
{{accessModifier}} extension NSDataAsset {
|
204
|
+
convenience init?(asset: {{dataType}}) {
|
205
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
206
|
+
#if os(iOS) || os(tvOS)
|
207
|
+
self.init(name: asset.name, bundle: bundle)
|
208
|
+
#elseif os(macOS)
|
209
|
+
self.init(name: NSDataAsset.Name(asset.name), bundle: bundle)
|
210
|
+
#endif
|
211
|
+
}
|
212
|
+
}
|
213
|
+
#endif
|
214
|
+
{% endif %}
|
215
|
+
{% if resourceCount.image > 0 %}
|
216
|
+
|
217
|
+
{{accessModifier}} struct {{imageType}} {
|
218
|
+
{{accessModifier}} fileprivate(set) var name: String
|
219
|
+
|
220
|
+
#if os(macOS)
|
221
|
+
{{accessModifier}} typealias Image = NSImage
|
222
|
+
#elseif os(iOS) || os(tvOS) || os(watchOS)
|
223
|
+
{{accessModifier}} typealias Image = UIImage
|
224
|
+
#endif
|
225
|
+
|
226
|
+
{{accessModifier}} var image: Image {
|
227
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
228
|
+
#if os(iOS) || os(tvOS)
|
229
|
+
let image = Image(named: name, in: bundle, compatibleWith: nil)
|
230
|
+
#elseif os(macOS)
|
231
|
+
let name = NSImage.Name(self.name)
|
232
|
+
let image = (bundle == .main) ? NSImage(named: name) : bundle.image(forResource: name)
|
233
|
+
#elseif os(watchOS)
|
234
|
+
let image = Image(named: name)
|
235
|
+
#endif
|
236
|
+
guard let result = image else {
|
237
|
+
fatalError("Unable to load image asset named \(name).")
|
238
|
+
}
|
239
|
+
return result
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
{{accessModifier}} extension {{imageType}}.Image {
|
244
|
+
@available(macOS, deprecated,
|
245
|
+
message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property")
|
246
|
+
convenience init?(asset: {{imageType}}) {
|
247
|
+
#if os(iOS) || os(tvOS)
|
248
|
+
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
|
249
|
+
self.init(named: asset.name, in: bundle, compatibleWith: nil)
|
250
|
+
#elseif os(macOS)
|
251
|
+
self.init(named: NSImage.Name(asset.name))
|
252
|
+
#elseif os(watchOS)
|
253
|
+
self.init(named: asset.name)
|
254
|
+
#endif
|
255
|
+
}
|
256
|
+
}
|
257
|
+
{% endif %}
|
258
|
+
{% if not param.bundle %}
|
259
|
+
|
260
|
+
// swiftlint:disable convenience_type
|
261
|
+
private final class BundleToken {
|
262
|
+
static let bundle: Bundle = {
|
263
|
+
#if SWIFT_PACKAGE
|
264
|
+
return Bundle.module
|
265
|
+
#else
|
266
|
+
return Bundle(for: BundleToken.self)
|
267
|
+
#endif
|
268
|
+
}()
|
269
|
+
}
|
270
|
+
// swiftlint:enable convenience_type
|
271
|
+
{% endif %}
|
272
|
+
{% else %}
|
273
|
+
// No assets found
|
274
|
+
{% endif %}
|