https://github.com/nikeorever/phrase
[Implementation of Paraphrase]A Gradle plugin which generates compile-safe format string builders.
https://github.com/nikeorever/phrase
paraphrase
Last synced: 10 months ago
JSON representation
[Implementation of Paraphrase]A Gradle plugin which generates compile-safe format string builders.
- Host: GitHub
- URL: https://github.com/nikeorever/phrase
- Owner: nikeorever
- License: apache-2.0
- Created: 2020-10-10T10:34:40.000Z (over 5 years ago)
- Default Branch: trunk
- Last Pushed: 2020-10-15T14:36:09.000Z (over 5 years ago)
- Last Synced: 2023-06-29T14:34:27.661Z (over 2 years ago)
- Topics: paraphrase
- Language: Kotlin
- Homepage:
- Size: 123 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Phrase
===========
[](https://maven-badges.herokuapp.com/maven-central/cn.nikeo.phrase/gradle-plugin)
A Gradle plugin which generates compile-safe format string builders.
The reason why I created this library
=====================================
Since [Paraphrase](https://github.com/JakeWharton/paraphrase) has been in a state of **experimental**,
and the project is too old, it seems difficult to maintain, so I created this library.
The goal of this library is consistent with [Paraphrase](https://github.com/JakeWharton/paraphrase)
Sample
=====
**Do** write your format strings like this (**Support Comment**):
```xml
Hello, {other_name}! My name is {my_name}.
```
Execute gradle task 'generate{**variant**}PhraseClasses'
```shell script
./gradlew :{module}:generate{variant}PhraseClasses
```
After successful execution, Gradle Plugin will generate a Kotlin File named **Phrase.kt** for you
```kotlin
// Automatically generated file. DO NOT MODIFY
package cn.nikeo.reparaturapplication
import android.content.Context
import cn.nikeo.phrase.runtime.AbstractPhrase
import kotlin.CharSequence
import kotlin.Suppress
@Suppress("ClassName")
class Phrase_greeting(
context: Context
) : BasePhrase(context = context, stringResId = R.string.greeting) {
fun my_name(value: CharSequence): Phrase_greeting {
put("my_name", value)
return this
}
fun other_name(value: CharSequence): Phrase_greeting {
put("other_name", value)
return this
}
}
/**
* This is a comment of greeting string
*
* The string resource corresponding to [greeting] is in
* /home/xianxueliang/AndroidStudioProjects/ReparaturApplication/app/src/main/res/values/strings.xml
*/
fun greeting(context: Context): Phrase_greeting = Phrase_greeting(context)
```
**Do** enjoy formatting them like this:
```kotlin
text.text = greeting(this)
.my_name("Jake Wharton")
.other_name("GitHub user")
.format()
```
Or
```kotlin
greeting(this)
.my_name("Jake Wharton")
.other_name("GitHub user")
.into(text)
```
Download
--------
#### Top-level build file
```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "cn.nikeo.phrase:gradle-plugin:1.1.2"
}
}
```
#### App-module build file
```groovy
apply plugin: 'com.android.application'
apply plugin: "cn.nikeo.phrase"
```
#### Library-module build file
```groovy
apply plugin: 'com.android.library'
apply plugin: "cn.nikeo.phrase"
```
License
-------
Apache License, Version 2.0, ([LICENSE](https://github.com/nikeorever/phrase/blob/trunk/LICENSE) or [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0))