Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Würthner committed Nov 14, 2024
1 parent dd8ec32 commit 648a4ed
Show file tree
Hide file tree
Showing 6 changed files with 1,338 additions and 307 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ This templating is used in the `filter` and `fileNames` configurations.
- `full_name`: The full name of the component. If part of a component set, comprised of the name of
the component set and the component name. The component name otherwise.
- `name`: The name of the component
- `normalized_name`: A name object for the `full_name`
- `key`: The key of the component
- `id`: The id of the component
- `set_name`: The name of the set of which this component is a part of, empty if not part of a set
Expand All @@ -181,6 +182,7 @@ This templating is used in the file at the `templatePath` configuration.
- `colors`: A list of `Color` objects
- `floats`: A list of `Float` objects
- `strings`: A list of `String` objects
- `icons`: A list of `Icon` objects as for the icon export. Useful to generate code accessors to the icons.
- `booleans`: A list of `Boolean` objects
- `text_styles`: A list of `TextStyle` objects
- `figma`: A `Figma` object
Expand Down Expand Up @@ -243,6 +245,7 @@ Hint: You can also use Jinja filters to modify the name, e.g. `{{ color.name|low
- `snake`: The name in snake case
- `kebab`: The name in kebab case
- `pascal`: The name in pascal case
- `camel`: The name in camel case

#### Figma
- `file`: The Figma file name
Expand Down
12 changes: 12 additions & 0 deletions figex-core/src/main/kotlin/com/iodigital/figex/ExportHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.iodigital.figex

import com.hubspot.jinjava.Jinjava
import com.hubspot.jinjava.JinjavaConfig
import com.iodigital.figex.ext.camel
import com.iodigital.figex.ext.kebab
import com.iodigital.figex.ext.pascal
import com.iodigital.figex.ext.snake
import com.iodigital.figex.jinjava.LowercaseFilter
import com.iodigital.figex.jinjava.ReplaceSpecialChars
import com.iodigital.figex.jinjava.StartsWithFilter
Expand Down Expand Up @@ -52,6 +56,14 @@ internal fun createTemplateContext(
"icons" to components.map { it.toContext() }
) + createTemplateContext(file)

internal fun String.toNameObject() = mapOf(
"original" to this,
"snake" to this.snake(),
"camel" to this.camel(),
"kebab" to this.kebab(),
"pascal" to this.pascal(),
)

internal fun createTemplateContext(
file: FigmaFile,
scale: FigExConfig.Export.Icons.Scale,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iodigital.figex.models.figex

import com.iodigital.figex.models.Contextable
import com.iodigital.figex.toNameObject

data class FigExComponent(
val setKey: String?,
Expand All @@ -21,5 +22,8 @@ data class FigExComponent(
"key" to key,
"id" to id,
"set_id" to (setId ?: ""),
"normalized_name" to fullName.map { if (it.isLetterOrDigit()) it else "_" }
.joinToString("")
.toNameObject(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.iodigital.figex.ext.kebab
import com.iodigital.figex.ext.pascal
import com.iodigital.figex.ext.snake
import com.iodigital.figex.models.Contextable
import com.iodigital.figex.toNameObject
import kotlin.reflect.KClass

data class FigExValue<T : Any>(
Expand Down Expand Up @@ -40,14 +41,6 @@ data class FigExValue<T : Any>(
}
}

private fun String.toNameObject() = mapOf(
"original" to this,
"snake" to this.snake(),
"camel" to this.camel(),
"kebab" to this.kebab(),
"pascal" to this.pascal(),
)

private fun Any.toContext(): Map<String, Any> = if (this is Contextable) {
toContext()
} else {
Expand Down
Loading

0 comments on commit 648a4ed

Please sign in to comment.