Skip to content

Instantly share code, notes, and snippets.

@fxm90
Last active May 2, 2022 04:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxm90/d1eb5439ad0f45d727bdb98132e933a6 to your computer and use it in GitHub Desktop.
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.
//
// 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