Last active
May 2, 2022 04:00
-
-
Save fxm90/d1eb5439ad0f45d727bdb98132e933a6 to your computer and use it in GitHub Desktop.
A stencil template for generating SwiftUI assets with SwiftGen. Currently only `Image` and `Color` are supported.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Do not edit! File generated using SwiftGen — https://github.com/SwiftGen/SwiftGen | |
// | |
// SwiftUI Template by Felix Mau – https://felix.hamburg | |
// | |
// Latest version available at https://gist.github.com/fxm90/d1eb5439ad0f45d727bdb98132e933a6 | |
// | |
import SwiftUI | |
// swiftlint:disable all | |
// swiftformat:disable all | |
{# Documentation for Stencil Template #} | |
{# - https://github.com/SwiftGen/SwiftGenKit/blob/master/Documentation/Assets.md #} | |
{# - https://github.com/SwiftGen/StencilSwiftKit #} | |
{# -- #} | |
{# This template is based on `swift5.stencil` #} | |
{# https://github.com/SwiftGen/SwiftGen/blob/stable/templates/xcassets/swift5.stencil #} | |
{% macro imageBlock assets %} | |
{% for asset in assets %} | |
{% if asset.type == "image" %} | |
static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = Image("{{asset.value}}") | |
{% elif asset.items %} | |
{% call imageBlock asset.items %} | |
{% endif %} | |
{% endfor %} | |
{% endmacro %} | |
{% macro colorBlock assets %} | |
{% for asset in assets %} | |
{% if asset.type == "color" %} | |
static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = Color("{{asset.value}}") | |
{% elif asset.items %} | |
{% call colorBlock asset.items %} | |
{% endif %} | |
{% endfor %} | |
{% endmacro %} | |
enum ImageAsset { | |
{% for catalog in catalogs %} | |
{% call imageBlock catalog.assets %} | |
{% endfor %} | |
} | |
enum ColorAsset { | |
{% for catalog in catalogs %} | |
{% call colorBlock catalog.assets %} | |
{% endfor %} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment