-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New imageicon interface #132
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6dc2163
Generate Image Assets Cases
kevinneko f6c0222
Implement new Image init method
kevinneko 455f02c
Refactor stencil template
kevinneko 9fc04ad
Refine indent
kevinneko 072c5de
Rename stencil template assetsName to assetsGroupName
kevinneko 3815a75
Remove unused enumCasesImageBlock
kevinneko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import SwiftUI | ||
|
||
extension Image { | ||
@inlinable init(charocalIcon: CharcoalAsset.Images) { | ||
self.init(asset: charocalIcon.imageAsset) | ||
} | ||
} | ||
|
||
// MARK: Development View | ||
|
||
fileprivate struct ImageView: View { | ||
var body: some View { | ||
VStack { | ||
Image(charocalIcon: .add24) | ||
Image(charocalIcon: .delete32) | ||
Image(charocalIcon: .addInline) | ||
Image(charocalIcon: .codes24) | ||
} | ||
} | ||
} | ||
|
||
struct ImageView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ImageView() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
// swiftlint:disable all | ||
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen | ||
{% import "macros/enum-cases.stencil" %} | ||
{% import "macros/enum-cases-color.stencil" %} | ||
{% import "macros/enum-cases-image.stencil" %} | ||
{% import "macros/enum-cases-flat-images.stencil" %} | ||
{% if catalogs %} | ||
{% macro hasValuesBlock assets filter %} | ||
{%- for asset in assets -%} | ||
|
@@ -11,6 +14,14 @@ | |
{%- endif -%} | ||
{%- endfor -%} | ||
{% endmacro %} | ||
|
||
{% macro hasValuesNoRecursionBlock assets filter %} | ||
{%- for asset in assets -%} | ||
{%- if asset.type == filter -%} | ||
1 | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{% endmacro %} | ||
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %} | ||
{% set arResourceGroupType %}{{param.arResourceGroupTypeName|default:"ARResourceGroupAsset"}}{% endset %} | ||
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %} | ||
|
@@ -53,14 +64,12 @@ | |
// MARK: - Asset Catalogs | ||
|
||
{% macro enumBlock assets %} | ||
{% call casesBlock assets %} | ||
{% call casesBlock assets assets.name %} | ||
|
||
{% call enumCasesBlock assets %} | ||
{% set assetsHasGroup %}{% call hasValuesNoRecursionBlock assets "group" %}{% endset %} | ||
|
||
{% set catalogHasColor %}{% call hasValuesBlock assets "color" %}{% endset %} | ||
{# Generate Charcoral Color Asset Enum #} | ||
{% if catalogHasColor %} | ||
{% call enumCasesColorBlock assets %} | ||
{% if assetsHasGroup %} | ||
{% filter indent:2," ",true %}{% call enumCasesFlatImagesBlock assets %}{% endfilter %} | ||
{% endif %} | ||
|
||
{% if param.allValues %} | ||
|
@@ -104,33 +113,39 @@ | |
// swiftlint:enable trailing_comma | ||
{% endif %} | ||
{% endmacro %} | ||
{% macro casesBlock assets %} | ||
{% macro casesBlock assets assetsGroupName %} | ||
{% for asset in assets %} | ||
{% if asset.type == "arresourcegroup" %} | ||
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{arResourceGroupType}}(name: "{{asset.value}}") | ||
{% elif asset.type == "color" %} | ||
static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}Asset = {{colorType}}(name: "{{asset.value}}") | ||
static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord}}Asset = {{colorType}}(name: "{{asset.value}}") | ||
{% elif asset.type == "data" %} | ||
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{dataType}}(name: "{{asset.value}}") | ||
{% elif asset.type == "image" %} | ||
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") | ||
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord}}Asset = {{imageType}}(name: "{{asset.value}}") | ||
{% elif asset.type == "symbol" %} | ||
{{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{symbolType}}(name: "{{asset.value}}") | ||
{% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %} | ||
{{accessModifier}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { | ||
{% filter indent:2," ",true %}{% call casesBlock asset.items %}{% endfilter %} | ||
{{accessModifier}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} : CaseIterable { | ||
{% filter indent:2," ",true %}{% call casesBlock asset.items asset.name %}{% endfilter %} | ||
} | ||
{% elif asset.items %} | ||
{% call casesBlock asset.items %} | ||
{% endif %} | ||
{% endfor %} | ||
{% endmacro %} | ||
{% macro enumCasesBlock assets %} | ||
{% for asset in assets %} | ||
{% if asset.type == "color" %} | ||
case {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} | ||
|
||
{% set catalogHasColor %}{% call hasValuesNoRecursionBlock assets "color" %}{% endset %} | ||
{# Generate Charcoral Color Asset Enum #} | ||
{% if catalogHasColor %} | ||
{% call enumCasesBlock assets %} | ||
{% call enumCasesColorBlock assets %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{# {% set catalogHasImage %}{% call hasValuesNoRecursionBlock assets "image" %}{% endset %} #} | ||
{# Generate Charcoral Image Asset Enum #} | ||
{# {% if catalogHasImage and assetsGroupName %} #} | ||
{# {% call enumCasesImageBlock assets assetsGroupName %} #} | ||
{# {% endif %} #} | ||
{% endmacro %} | ||
{% macro allValuesBlock assets filter prefix %} | ||
{% for asset in assets %} | ||
|
@@ -148,7 +163,7 @@ | |
{{accessModifier}} enum {{enumName}} { | ||
{% if catalogs.count > 1 or param.forceFileNameEnum %} | ||
{% for catalog in catalogs %} | ||
{{accessModifier}} enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { | ||
{{accessModifier}} enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} : CaseIterable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここもCaseIterable無くて大丈夫です |
||
{% if catalog.assets %} | ||
{% filter indent:2," ",true %}{% call enumBlock catalog.assets %}{% endfilter %} | ||
{% endif %} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% macro enumCasesFlatImagesBlock assets %} | ||
{% for asset in assets %} | ||
{% if asset.items %} | ||
{% for item in asset.items %} | ||
case {{item.name | swiftIdentifier:"pretty"|lowerFirstWord}}{{asset.name}} | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% set groupHasImage %}{% call hasValuesBlock assets "image" %}{% endset %} | ||
{% if groupHasImage %} | ||
{{accessModifier}} var imageAsset: ImageAsset { | ||
switch (self) { | ||
{% for asset in assets %} | ||
{% if asset.items %} | ||
{% for item in asset.items %} | ||
{% if item.type == "image" %} | ||
case .{{item.name|swiftIdentifier:"pretty"|lowerFirstWord}}{{asset.name}}: | ||
return {{enumName}}.{{catalog.name|swiftIdentifier:"pretty"}}.{{asset.name|swiftIdentifier:"pretty"}}.{{item.name|swiftIdentifier:"pretty"|lowerFirstWord}}Asset | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
} | ||
} | ||
{{accessModifier}} var image: ImageAsset.Image { | ||
return imageAsset.image | ||
} | ||
{% endif %} | ||
{% endmacro %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% macro enumCasesImageBlock assets assetsGroupName%} | ||
{{accessModifier}} var imageAsset: ImageAsset { | ||
switch (self) { | ||
{% for asset in assets %} | ||
{% if asset.type == "image" %} | ||
case .{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord}}: | ||
return {{enumName}}.{{catalog.name|swiftIdentifier:"pretty"}}.{{assetsGroupName|swiftIdentifier:"pretty"}}.{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord}}Asset | ||
{% endif %} | ||
{% endfor %} | ||
} | ||
} | ||
{{accessModifier}} var image: ImageAsset.Image { | ||
return imageAsset.image | ||
} | ||
{% endmacro %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% macro enumCasesBlock assets %} | ||
{% for asset in assets %} | ||
{% if not asset.items %} | ||
case {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} | ||
{% endif %} | ||
{% endfor %} | ||
{% endmacro %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ライブラリを使う側の人にとってはCaseIterableは不要だと思うので、ここでは削っていただけると 🙏
CaseIterableを付けたいと思ったのはSample側の話でした
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extensionでCaseIterableを書く場合、allCasesを自分で実装する必要があったため、やはりこの方針でいくのが良いとなった