-
Notifications
You must be signed in to change notification settings - Fork 12
/
Gridicons.stencil
60 lines (51 loc) · 1.69 KB
/
Gridicons.stencil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
import UIKit
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"GridiconType"}}{% endset %}
{% macro enumBlock assets sp %}
{{sp}} {% call casesBlock assets sp %}
{% endmacro %}
{% macro casesBlock assets sp %}
{{sp}} {% for asset in assets %}
{{sp}} {% if asset.type == "image" %}
{{sp}} case {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|replace:"Ios","iOS"|escapeReservedKeywords}}
{{sp}} {% endif %}
{{sp}} {% endfor %}
{% endmacro %}
{% macro assetNamesBlock assets sp %}
{{sp}} {% for asset in assets %}
{{sp}} {% if asset.type == "image" %}
{{sp}} case .{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|replace:"Ios","iOS"|escapeReservedKeywords}}: return "{{asset.name}}"
{{sp}} {% endif %}
{{sp}} {% endfor %}
{% endmacro %}
@objc
public enum {{enumName}}: Int {
{% call enumBlock catalogs.first.assets " " %}
}
extension {{enumName}} {
var name: String {
switch self {
{% call assetNamesBlock catalogs.first.assets " " %}
}
}
var icon: UIImage {
#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
var bundle = Bundle(for: BundleToken.self)
if let url = bundle.url(forResource: "GridiconsAssets", withExtension: "bundle"),
let assetBundle = Bundle(url: url) {
// When loaded through CocoaPods, assets reside in a separate resource bundle
bundle = assetBundle
}
#endif
let image = UIImage(named: name, in: bundle, compatibleWith: nil)
guard let result = image else { fatalError("Unable to load image named \(name).") }
return result
}
}
private final class BundleToken {}
{% else %}
// No assets found
{% endif %}