Skip to content

Commit

Permalink
Merge pull request #1 from AlexeyKorshun/add_color_fields
Browse files Browse the repository at this point in the history
add snackName and FullHex fields in Color model
  • Loading branch information
movch authored May 19, 2021
2 parents fecedc4 + 90f32a3 commit a02e5bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions FigmaAssetsFetch/Helpers/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ extension String {
.joined()
.lowercasedFirstLetter
}

var snakeCased: String {
return self
.stripped
.components(separatedBy: .whitespaces)
.map { $0.lowercased() }
.joined(separator: "_")
.lowercasedFirstLetter
}
}
8 changes: 7 additions & 1 deletion FigmaAssetsFetch/Models/ColorObjectModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ struct ColorObjectModel {

/// `name` converted to camel case
let camelCaseName: String


/// `name` converted to snake case
let snakeCaseName: String

/// Hex value of color
let hexColor: String

/// Hex value with alpha of color
let fullHexColor: String

/// RGBA value of color
var figmaColor: FigmaColor
Expand Down
4 changes: 4 additions & 0 deletions FigmaAssetsFetch/Models/FigmaTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public struct FigmaColor: Codable {
public func toHex() -> String {
return String(format: "%02lX%02lX%02lX", lround(r * 255), lround(g * 255), lround(b * 255))
}

public func toFullHex() -> String {
return String(format: "%02lX%02lX%02lX%02lX", lround(a * 255), lround(r * 255), lround(g * 255), lround(b * 255))
}
}

/// How this node blends with nodes behind it in the scene
Expand Down
2 changes: 2 additions & 0 deletions FigmaAssetsFetch/Services/PaletteExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class PaletteExtractor {
var paletteColor = ColorObjectModel(
name: styleName,
camelCaseName: styleName.camelCased,
snakeCaseName: styleName.snakeCased,
hexColor: color.toHex(),
fullHexColor: color.toFullHex(),
figmaColor: color
)

Expand Down

0 comments on commit a02e5bd

Please sign in to comment.