Skip to content

Commit

Permalink
Исправление SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
timbaev committed Sep 4, 2023
1 parent 933b248 commit e9e9958
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,30 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes
private func makeAsset(
for node: ImageRenderedNode,
setNode: ImageComponentSetRenderedNode,
format: ImageFormat,
preserveVectorData: Bool,
groupByFrame: Bool,
namingStyle: ImageNamingStyle,
parameters: ImagesParameters,
folderPath: Path
) -> ImageAsset {
let name = resolveName(for: node, setNode: setNode, namingStyle: namingStyle)
let folderPath = resolveFolderPath(groupByFrame: groupByFrame, setNode: setNode, folderPath: folderPath)
let name = resolveName(for: node, setNode: setNode, namingStyle: parameters.namingStyle)

let folderPath = resolveFolderPath(
groupByFrame: parameters.groupByFrame,
setNode: setNode,
folderPath: folderPath
)

let filePaths = node.urls.keys.reduce(into: [:]) { result, scale in
result[scale] = folderPath
.appending(fileName: name, extension: AssetImageSet.pathExtension)
.appending(fileName: name.appending(scale.fileNameSuffix), extension: format.fileExtension)
.appending(fileName: name.appending(scale.fileNameSuffix), extension: parameters.format.fileExtension)
.string
}

return ImageAsset(name: name, filePaths: filePaths, preserveVectorData: preserveVectorData)
return ImageAsset(name: name, filePaths: filePaths, preserveVectorData: parameters.preserveVectorData)
}

private func makeAssets(
for nodes: [ImageComponentSetRenderedNode],
format: ImageFormat,
preserveVectorData: Bool,
groupByFrame: Bool,
namingStyle: ImageNamingStyle,
parameters: ImagesParameters,
folderPath: Path
) -> [ImageComponentSetAsset] {
nodes.map { setNode in
Expand All @@ -72,10 +71,7 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes
assets[node] = makeAsset(
for: node,
setNode: setNode,
format: format,
preserveVectorData: preserveVectorData,
groupByFrame: groupByFrame,
namingStyle: namingStyle,
parameters: parameters,
folderPath: folderPath
)
}
Expand Down Expand Up @@ -149,19 +145,13 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes

func saveImages(
nodes: [ImageComponentSetRenderedNode],
format: ImageFormat,
preserveVectorData: Bool,
groupByFrame: Bool,
namingStyle: ImageNamingStyle,
parameters: ImagesParameters,
in folderPath: String
) -> Promise<[ImageComponentSetAsset]> {
perform(on: DispatchQueue.global(qos: .userInitiated)) {
self.makeAssets(
for: nodes,
format: format,
preserveVectorData: preserveVectorData,
groupByFrame: groupByFrame,
namingStyle: namingStyle,
parameters: parameters,
folderPath: Path(folderPath)
)
}.nest { assets in
Expand All @@ -173,7 +163,7 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes
)
}
}.then { assets in
try self.saveAssetFolders(assets: assets, groupByFrame: groupByFrame, in: folderPath)
try self.saveAssetFolders(assets: assets, groupByFrame: parameters.groupByFrame, in: folderPath)
}.then {
self.saveImageFiles(assets: assets)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ protocol ImageAssetsProvider {

func saveImages(
nodes: [ImageComponentSetRenderedNode],
format: ImageFormat,
preserveVectorData: Bool,
groupByFrame: Bool,
namingStyle: ImageNamingStyle,
parameters: ImagesParameters,
in folderPath: String
) -> Promise<[ImageComponentSetAsset]>
}
15 changes: 3 additions & 12 deletions Sources/FigmaGen/Providers/Images/DefaultImagesProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,13 @@ final class DefaultImagesProvider: ImagesProvider {

private func saveAssetImagesIfNeeded(
nodes: [ImageComponentSetRenderedNode],
format: ImageFormat,
preserveVectorData: Bool,
groupByFrame: Bool,
namingStyle: ImageNamingStyle,
parameters: ImagesParameters,
in assets: String?
) -> Promise<[ImageComponentSetAsset]> {
assets.map { folderPath in
imageAssetsProvider.saveImages(
nodes: nodes,
format: format,
preserveVectorData: preserveVectorData,
groupByFrame: groupByFrame,
namingStyle: namingStyle,
parameters: parameters,
in: folderPath
)
} ?? .value([])
Expand Down Expand Up @@ -194,10 +188,7 @@ final class DefaultImagesProvider: ImagesProvider {
when(
fulfilled: self.saveAssetImagesIfNeeded(
nodes: nodes,
format: parameters.format,
preserveVectorData: parameters.preserveVectorData,
groupByFrame: parameters.groupByFrame,
namingStyle: parameters.namingStyle,
parameters: parameters,
in: parameters.assets
),
self.saveResourceImagesIfNeeded(
Expand Down

0 comments on commit e9e9958

Please sign in to comment.