Browse Source
Example: ```kotlin compose.resources { publicResClass = true packageOfResClass = "me.sample.library.resources" generateResClass = auto } ```pull/4526/head
Konstantin
9 months ago
committed by
GitHub
13 changed files with 431 additions and 40 deletions
@ -0,0 +1,33 @@
|
||||
package org.jetbrains.compose.resources |
||||
|
||||
abstract class ResourcesExtension { |
||||
/** |
||||
* Whether the generated resources accessors class should be public or not. |
||||
* |
||||
* Default is false. |
||||
*/ |
||||
var publicResClass: Boolean = false |
||||
|
||||
/** |
||||
* The unique identifier of the resources in the current project. |
||||
* Uses as package for the generated Res class and for isolation resources in a final artefact. |
||||
* |
||||
* If it is empty then `{group name}.{module name}.generated.resources` will be used. |
||||
* |
||||
*/ |
||||
var packageOfResClass: String = "" |
||||
|
||||
enum class ResourceClassGeneration { Auto, Always } |
||||
|
||||
//to support groovy DSL |
||||
val auto = ResourceClassGeneration.Auto |
||||
val always = ResourceClassGeneration.Always |
||||
|
||||
/** |
||||
* The mode of resource class generation. |
||||
* |
||||
* - `auto`: The Res class will be generated if the current project has an explicit "implementation" or "api" dependency on the resource's library. |
||||
* - `always`: Unconditionally generate the Res class. This may be useful when the resources library is available transitively. |
||||
*/ |
||||
var generateResClass: ResourceClassGeneration = auto |
||||
} |
@ -0,0 +1,84 @@
|
||||
@file:OptIn(org.jetbrains.compose.resources.InternalResourceApi::class) |
||||
|
||||
package my.lib.res |
||||
|
||||
import kotlin.OptIn |
||||
import org.jetbrains.compose.resources.DrawableResource |
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi |
||||
|
||||
@ExperimentalResourceApi |
||||
private object Drawable0 { |
||||
public val _3_strange_name: DrawableResource by |
||||
lazy { init__3_strange_name() } |
||||
|
||||
public val camelCaseName: DrawableResource by |
||||
lazy { init_camelCaseName() } |
||||
|
||||
public val vector: DrawableResource by |
||||
lazy { init_vector() } |
||||
|
||||
public val vector_2: DrawableResource by |
||||
lazy { init_vector_2() } |
||||
} |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.drawable._3_strange_name: DrawableResource |
||||
get() = Drawable0._3_strange_name |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init__3_strange_name(): DrawableResource = |
||||
org.jetbrains.compose.resources.DrawableResource( |
||||
"drawable:_3_strange_name", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "drawable/3-strange-name.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.drawable.camelCaseName: DrawableResource |
||||
get() = Drawable0.camelCaseName |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_camelCaseName(): DrawableResource = |
||||
org.jetbrains.compose.resources.DrawableResource( |
||||
"drawable:camelCaseName", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "drawable/camelCaseName.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.drawable.vector: DrawableResource |
||||
get() = Drawable0.vector |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_vector(): DrawableResource = org.jetbrains.compose.resources.DrawableResource( |
||||
"drawable:vector", |
||||
setOf( |
||||
|
||||
org.jetbrains.compose.resources.ResourceItem(setOf(org.jetbrains.compose.resources.LanguageQualifier("ast"), |
||||
), "drawable-ast/vector.xml"), |
||||
|
||||
org.jetbrains.compose.resources.ResourceItem(setOf(org.jetbrains.compose.resources.LanguageQualifier("au"), |
||||
org.jetbrains.compose.resources.RegionQualifier("US"), ), "drawable-au-rUS/vector.xml"), |
||||
|
||||
org.jetbrains.compose.resources.ResourceItem(setOf(org.jetbrains.compose.resources.ThemeQualifier.DARK, |
||||
org.jetbrains.compose.resources.LanguageQualifier("ge"), ), "drawable-dark-ge/vector.xml"), |
||||
|
||||
org.jetbrains.compose.resources.ResourceItem(setOf(org.jetbrains.compose.resources.LanguageQualifier("en"), |
||||
), "drawable-en/vector.xml"), |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "drawable/vector.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.drawable.vector_2: DrawableResource |
||||
get() = Drawable0.vector_2 |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_vector_2(): DrawableResource = org.jetbrains.compose.resources.DrawableResource( |
||||
"drawable:vector_2", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "drawable/vector_2.xml"), |
||||
) |
||||
) |
@ -0,0 +1,28 @@
|
||||
@file:OptIn(org.jetbrains.compose.resources.InternalResourceApi::class) |
||||
|
||||
package my.lib.res |
||||
|
||||
import kotlin.OptIn |
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi |
||||
import org.jetbrains.compose.resources.FontResource |
||||
|
||||
@ExperimentalResourceApi |
||||
private object Font0 { |
||||
public val emptyFont: FontResource by |
||||
lazy { init_emptyFont() } |
||||
} |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.font.emptyFont: FontResource |
||||
get() = Font0.emptyFont |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_emptyFont(): FontResource = org.jetbrains.compose.resources.FontResource( |
||||
"font:emptyFont", |
||||
setOf( |
||||
|
||||
org.jetbrains.compose.resources.ResourceItem(setOf(org.jetbrains.compose.resources.LanguageQualifier("en"), |
||||
), "font-en/emptyFont.otf"), |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "font/emptyFont.otf"), |
||||
) |
||||
) |
@ -0,0 +1,31 @@
|
||||
@file:OptIn( |
||||
org.jetbrains.compose.resources.InternalResourceApi::class, |
||||
org.jetbrains.compose.resources.ExperimentalResourceApi::class, |
||||
) |
||||
|
||||
package my.lib.res |
||||
|
||||
import kotlin.ByteArray |
||||
import kotlin.OptIn |
||||
import kotlin.String |
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi |
||||
import org.jetbrains.compose.resources.readResourceBytes |
||||
|
||||
@ExperimentalResourceApi |
||||
public object Res { |
||||
/** |
||||
* Reads the content of the resource file at the specified path and returns it as a byte array. |
||||
* |
||||
* Example: `val bytes = Res.readBytes("files/key.bin")` |
||||
* |
||||
* @param path The path of the file to read in the compose resource's directory. |
||||
* @return The content of the file as a byte array. |
||||
*/ |
||||
public suspend fun readBytes(path: String): ByteArray = readResourceBytes("" + path) |
||||
|
||||
public object drawable |
||||
|
||||
public object string |
||||
|
||||
public object font |
||||
} |
@ -0,0 +1,130 @@
|
||||
@file:OptIn(org.jetbrains.compose.resources.InternalResourceApi::class) |
||||
|
||||
package my.lib.res |
||||
|
||||
import kotlin.OptIn |
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi |
||||
import org.jetbrains.compose.resources.StringResource |
||||
|
||||
@ExperimentalResourceApi |
||||
private object String0 { |
||||
public val PascalCase: StringResource by |
||||
lazy { init_PascalCase() } |
||||
|
||||
public val _1_kebab_case: StringResource by |
||||
lazy { init__1_kebab_case() } |
||||
|
||||
public val app_name: StringResource by |
||||
lazy { init_app_name() } |
||||
|
||||
public val camelCase: StringResource by |
||||
lazy { init_camelCase() } |
||||
|
||||
public val hello: StringResource by |
||||
lazy { init_hello() } |
||||
|
||||
public val multi_line: StringResource by |
||||
lazy { init_multi_line() } |
||||
|
||||
public val str_arr: StringResource by |
||||
lazy { init_str_arr() } |
||||
|
||||
public val str_template: StringResource by |
||||
lazy { init_str_template() } |
||||
} |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.PascalCase: StringResource |
||||
get() = String0.PascalCase |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_PascalCase(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:PascalCase", "PascalCase", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string._1_kebab_case: StringResource |
||||
get() = String0._1_kebab_case |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init__1_kebab_case(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:_1_kebab_case", "_1_kebab_case", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.app_name: StringResource |
||||
get() = String0.app_name |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_app_name(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:app_name", "app_name", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.camelCase: StringResource |
||||
get() = String0.camelCase |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_camelCase(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:camelCase", "camelCase", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.hello: StringResource |
||||
get() = String0.hello |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_hello(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:hello", "hello", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.multi_line: StringResource |
||||
get() = String0.multi_line |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_multi_line(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:multi_line", "multi_line", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.str_arr: StringResource |
||||
get() = String0.str_arr |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_str_arr(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:str_arr", "str_arr", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
||||
|
||||
@ExperimentalResourceApi |
||||
public val Res.string.str_template: StringResource |
||||
get() = String0.str_template |
||||
|
||||
@ExperimentalResourceApi |
||||
private fun init_str_template(): StringResource = org.jetbrains.compose.resources.StringResource( |
||||
"string:str_template", "str_template", |
||||
setOf( |
||||
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), |
||||
) |
||||
) |
Loading…
Reference in new issue