From 03b8fd600d0229130850cdec2ff335f002998b59 Mon Sep 17 00:00:00 2001 From: Jitin Sharma Date: Sat, 7 Sep 2019 18:21:07 +0530 Subject: [PATCH] Split up docs to multiple files --- Drawable.kt => DrawableExtensions.kt | 0 README.md | 373 ++------------------------- doc/ActivityExtensions.md | 45 ++++ doc/ContextExtensions.md | 93 +++++++ doc/DateExtensions.md | 32 +++ doc/DrawableExtensions.md | 14 + doc/GeneralExtensions.md | 26 ++ doc/ImageExtensions.md | 20 ++ doc/MetricExtensions.md | 22 ++ doc/StringExtensions.md | 39 +++ doc/ThreadingBlocks.md | 44 ++++ doc/ViewExtensions.md | 37 +++ kotlin-doc/src/main/kotlin/Doc.kt | 5 +- 13 files changed, 390 insertions(+), 360 deletions(-) rename Drawable.kt => DrawableExtensions.kt (100%) create mode 100644 doc/ActivityExtensions.md create mode 100644 doc/ContextExtensions.md create mode 100644 doc/DateExtensions.md create mode 100644 doc/DrawableExtensions.md create mode 100644 doc/GeneralExtensions.md create mode 100644 doc/ImageExtensions.md create mode 100644 doc/MetricExtensions.md create mode 100644 doc/StringExtensions.md create mode 100644 doc/ThreadingBlocks.md create mode 100644 doc/ViewExtensions.md diff --git a/Drawable.kt b/DrawableExtensions.kt similarity index 100% rename from Drawable.kt rename to DrawableExtensions.kt diff --git a/README.md b/README.md index 590d4f2..3d625cc 100644 --- a/README.md +++ b/README.md @@ -1,365 +1,22 @@ # Kotlin.someExtensions Few extensions functions for Kotlin and Android -# ImageExtensions.kt - ```kotlin - /** - * Convert byte array to bitmap - */ -fun ByteArray.convertBytesToBitmap(): Bitmap = - BitmapFactory.decodeByteArray(this, 0, size) - -/** - * Convert bitmap to a byte array - */ -fun Bitmap.convertBitmapToBytes(): ByteArray { - val bytes: ByteArray - val stream = ByteArrayOutputStream() - this.compress(Bitmap.CompressFormat.PNG, 0, stream) - bytes = stream.toByteArray() - return bytes -} - ``` -# ContextExtensions.kt - ```kotlin - /** - * Checks network connectivity - */ -@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) -fun Context.isNetworkStatusAvailable(): Boolean { - val connectivityManager = this - .getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager - connectivityManager?.let { - val netInfo = it.activeNetworkInfo - netInfo?.let { - if (netInfo.isConnected) return true - } - } - return false -} - -/** - * Execute block of code if network is available - */ -@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) -inline fun Context.withNetwork(block: () -> Unit) { - if (isNetworkStatusAvailable()) { - block() - } -} - -/** - * Loads content of file from assets as String using UTF-8 charset - */ -fun Context.loadFromAsset(jsonName: String): String? { - var stream: String? = null - try { - val inputStream = this.assets.open(jsonName) - val size = inputStream.available() - val buffer = ByteArray(size) - inputStream.read(buffer) - inputStream.close() - stream = String(buffer, Charset.forName("UTF-8")) - } catch (e: IOException) { - } - return stream -} - -/** - * Computes status bar height - */ -fun Context.getStatusBarHeight(): Int { - var result = 0 - val resourceId = this.resources.getIdentifier("status_bar_height", "dimen", - "android") - if (resourceId > 0) { - result = this.resources.getDimensionPixelSize(resourceId) - } - return result -} - -/** - * Computes screen height - */ -fun Context.getScreenHeight(): Int { - var screenHeight = 0 - val wm = this.getSystemService(Context.WINDOW_SERVICE) as? WindowManager - wm?.let { - val metrics = DisplayMetrics() - wm.defaultDisplay.getMetrics(metrics) - screenHeight = metrics.heightPixels - } - return screenHeight -} - -/** - * Convert dp integer to pixel - */ -fun Context.dpToPx(dp : Int): Float { - val displayMetrics = this.resources.displayMetrics - return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)).toFloat() -} - -/** - * Get color from resources - */ -fun Context.getCompatColor(@ColorRes colorInt: Int) : Int = - ContextCompat.getColor(this, colorInt) - -/** - * Get drawable from resources - */ -fun Context.getCompatDrawable(@DrawableRes drawableRes: Int) : Drawable = - ContextCompat.getDrawable(this, drawableRes) - ``` -# ActivityExtensions.kt - ```kotlin - /** - * AppCompatActivity's toolbar visibility modifiers - */ +[ImageExtensions](/doc/ImageExtensions.md) -fun AppCompatActivity.hideToolbar() { - supportActionBar?.hide() -} - -/** - * Returns display density as ...DPI - */ -fun AppCompatActivity.getDisplayDensity(): String { - val metrics = DisplayMetrics() - this.windowManager.defaultDisplay.getMetrics(metrics) - return when (metrics.densityDpi) { - DisplayMetrics.DENSITY_LOW -> "LDPI" - DisplayMetrics.DENSITY_MEDIUM -> "MDPI" - DisplayMetrics.DENSITY_HIGH -> "HDPI" - DisplayMetrics.DENSITY_XHIGH -> "XHDPI" - DisplayMetrics.DENSITY_XXHIGH -> "XXHDPI" - DisplayMetrics.DENSITY_XXXHIGH -> "XXXHDPI" - else -> "XXHDPI" - } -} - -/** - * Sets color to toolbar in AppCompatActivity - */ -fun AppCompatActivity.setToolbarColor(@ColorRes color: Int) { - this.supportActionBar?.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, - color))) -} - -/** - * Perform replace for a support fragment - */ -inline fun AppCompatActivity.transact(action: FragmentTransaction.() -> Unit) { - supportFragmentManager.beginTransaction().apply { - action() - }.commit() -} - ``` -# ThreadingBlocks.kt - ```kotlin - /** - * Executes block of code on Android's main thread. Can be called from background thread. - */ -inline fun uiThreadExecutor(crossinline block: () -> Unit) { - val mainHandler = Handler(Looper.getMainLooper()) - mainHandler.post{ - block() - } -} - -/** - * Executes a function using RxJava observable on a separate thread and - * exposes it's response as lambda on main thread - * REQUIRED: RxJava, RxKotlin, RxAndroid - */ -fun asyncRxExecutor(heavyFunction: () -> T, response : (response : T?) -> Unit) { - val observable = Single.create({e -> - e.onSuccess(heavyFunction()) - }) - observable.subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { t: T? -> - response(t) - } -} - -/** - * Executes a function using Kotlin coroutines on a separate thread pool and - * exposes it's response as lambda on main thread. - * Thread pool is maintained by Anko Coroutines lib - * REQUIRED: Anko Coroutines - */ -fun asyncCoroutinesExecutor(heavyFunction: () -> T, response : (response : T?) -> Unit) { - async(UI) { - val data : Deferred = bg { - heavyFunction() - } - response(data.await()) - } -} - ``` -# GeneralExtensions.kt - ```kotlin - /** - * Wrapping try/catch to ignore catch block - */ -inline fun justTry(block: () -> T) = try { block() } catch (e: Throwable) {} - -/** - * App's debug mode - */ -inline fun debugMode(block : () -> Unit) { - if (BuildConfig.DEBUG) { - block() - } -} - -/** - * For functionality supported above API 21 (Eg. Material design stuff) - */ -inline fun lollipopAndAbove(block : () -> Unit) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - block() - } -} - ``` -# ViewExtensions.kt - ```kotlin - /** - * Visibility modifiers and check functions - */ +[ContextExtensions](/doc/ContextExtensions.md) -fun View.isVisibile(): Boolean = this.visibility == View.VISIBLE - -/** - * Sets text and content description using same string - */ -fun TextView.setTextWithContentDescription(value : String?) { - text = value - contentDescription = value -} - -/** - * Button enabling/disabling modifiers - */ +[ActivityExtensions](/doc/ActivityExtensions.md) -fun Button.disableButton() { - isEnabled = false - alpha = 0.3f -} - -/** - * Sets color to status bar - */ -fun Window.addStatusBarColor(@ColorRes color: Int) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - this.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) - this.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) - this.statusBarColor = ContextCompat.getColor(this.context, color) - } -} - ``` -# StringExtensions.kt - ```kotlin - /** - * Converts string to integer safely otherwise returns zero - */ -fun String.toIntOrZero() : Int { - var value = 0 - justTry { - value = this.toInt() - } - return value -} - -/** - * Converts a string to boolean such as 'Y', 'yes', 'TRUE' - */ +[ThreadingBlocks](/doc/ThreadingBlocks.md) -fun String.toBoolean(): Boolean { - return this != "" && - (this.equals("TRUE", ignoreCase = true) - || this.equals("Y", ignoreCase = true) - || this.equals("YES", ignoreCase = true)) -} - -/** - * Converts string to camel case. Handles multiple strings and empty strings - */ -fun String.convertToCamelCase(): String { - var titleText = "" - if (!this.isEmpty()) { - val words = this.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - words.filterNot { it.isEmpty() } - .map { it.substring(0, 1).toUpperCase() + it.substring(1).toLowerCase() } - .forEach { titleText += it + " " } - } - return titleText.trim { it <= ' ' } -} - ``` -# MetricExtensions.kt - ```kotlin - /** - * Convert Celsius temperature to Fahrenheit - */ -fun Double.celsiusToFahrenheit() : Double = (this * 1.8) + 32 - -/** - * Convert Fahrenheit temperature to Celsius - */ -fun Double.fahrenheitToCelsius() : Double = (this - 32) * 5/9 - -/** - * Convert meters to miles - */ -fun Double.convertMetersToMiles(): Double { - return if (this != 0.0) { - this / 1609.34 - } else -1.0 -} - ``` -# Drawable.kt - ```kotlin - /** - * Returns a compat drawable with tint added - */ -fun Drawable.withTint(colorInt: Int): Drawable { - return with(this) { - DrawableCompat.wrap(this).apply { - DrawableCompat.setTint(this, colorInt) - } - } -} - ``` -# DateExtensions.kt - ```kotlin - /** - * Convert a given date to milliseconds - */ -fun Date.toMillis() : Long { - val calendar = Calendar.getInstance() - calendar.time = this - return calendar.timeInMillis -} - -/** - * Checks if dates are same - */ -fun Date.isSame(to : Date) : Boolean { - val sdf = SimpleDateFormat("yyyMMdd", Locale.getDefault()) - return sdf.format(this) == sdf.format(to) -} - -/** - * Converts raw string to date object using [SimpleDateFormat] - */ -fun String.convertStringToDate(simpleDateFormatPattern: String): Date? { - val simpleDateFormat = SimpleDateFormat(simpleDateFormatPattern, Locale.getDefault()) - var value: Date? = null - justTry { - value = simpleDateFormat.parse(this) - } - return value -} - ``` \ No newline at end of file +[GeneralExtensions](/doc/GeneralExtensions.md) + +[ViewExtensions](/doc/ViewExtensions.md) + +[StringExtensions](/doc/StringExtensions.md) + +[MetricExtensions](/doc/MetricExtensions.md) + +[DrawableExtensions](/doc/DrawableExtensions.md) + +[DateExtensions](/doc/DateExtensions.md) \ No newline at end of file diff --git a/doc/ActivityExtensions.md b/doc/ActivityExtensions.md new file mode 100644 index 0000000..b9612da --- /dev/null +++ b/doc/ActivityExtensions.md @@ -0,0 +1,45 @@ + +# ActivityExtensions.kt + ```kotlin + /** + * AppCompatActivity's toolbar visibility modifiers + */ + +fun AppCompatActivity.hideToolbar() { + supportActionBar?.hide() +} + +/** + * Returns display density as ...DPI + */ +fun AppCompatActivity.getDisplayDensity(): String { + val metrics = DisplayMetrics() + this.windowManager.defaultDisplay.getMetrics(metrics) + return when (metrics.densityDpi) { + DisplayMetrics.DENSITY_LOW -> "LDPI" + DisplayMetrics.DENSITY_MEDIUM -> "MDPI" + DisplayMetrics.DENSITY_HIGH -> "HDPI" + DisplayMetrics.DENSITY_XHIGH -> "XHDPI" + DisplayMetrics.DENSITY_XXHIGH -> "XXHDPI" + DisplayMetrics.DENSITY_XXXHIGH -> "XXXHDPI" + else -> "XXHDPI" + } +} + +/** + * Sets color to toolbar in AppCompatActivity + */ +fun AppCompatActivity.setToolbarColor(@ColorRes color: Int) { + this.supportActionBar?.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, + color))) +} + +/** + * Perform replace for a support fragment + */ +inline fun AppCompatActivity.transact(action: FragmentTransaction.() -> Unit) { + supportFragmentManager.beginTransaction().apply { + action() + }.commit() +} + ``` \ No newline at end of file diff --git a/doc/ContextExtensions.md b/doc/ContextExtensions.md new file mode 100644 index 0000000..2c43f96 --- /dev/null +++ b/doc/ContextExtensions.md @@ -0,0 +1,93 @@ + +# ContextExtensions.kt + ```kotlin + /** + * Checks network connectivity + */ +@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) +fun Context.isNetworkStatusAvailable(): Boolean { + val connectivityManager = this + .getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager + connectivityManager?.let { + val netInfo = it.activeNetworkInfo + netInfo?.let { + if (netInfo.isConnected) return true + } + } + return false +} + +/** + * Execute block of code if network is available + */ +@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) +inline fun Context.withNetwork(block: () -> Unit) { + if (isNetworkStatusAvailable()) { + block() + } +} + +/** + * Loads content of file from assets as String using UTF-8 charset + */ +fun Context.loadFromAsset(jsonName: String): String? { + var stream: String? = null + try { + val inputStream = this.assets.open(jsonName) + val size = inputStream.available() + val buffer = ByteArray(size) + inputStream.read(buffer) + inputStream.close() + stream = String(buffer, Charset.forName("UTF-8")) + } catch (e: IOException) { + } + return stream +} + +/** + * Computes status bar height + */ +fun Context.getStatusBarHeight(): Int { + var result = 0 + val resourceId = this.resources.getIdentifier("status_bar_height", "dimen", + "android") + if (resourceId > 0) { + result = this.resources.getDimensionPixelSize(resourceId) + } + return result +} + +/** + * Computes screen height + */ +fun Context.getScreenHeight(): Int { + var screenHeight = 0 + val wm = this.getSystemService(Context.WINDOW_SERVICE) as? WindowManager + wm?.let { + val metrics = DisplayMetrics() + wm.defaultDisplay.getMetrics(metrics) + screenHeight = metrics.heightPixels + } + return screenHeight +} + +/** + * Convert dp integer to pixel + */ +fun Context.dpToPx(dp : Int): Float { + val displayMetrics = this.resources.displayMetrics + return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)).toFloat() +} + +/** + * Get color from resources + */ +fun Context.getCompatColor(@ColorRes colorInt: Int) : Int = + ContextCompat.getColor(this, colorInt) + +/** + * Get drawable from resources + */ +fun Context.getCompatDrawable(@DrawableRes drawableRes: Int) : Drawable = + ContextCompat.getDrawable(this, drawableRes) + ``` \ No newline at end of file diff --git a/doc/DateExtensions.md b/doc/DateExtensions.md new file mode 100644 index 0000000..1a6a1b7 --- /dev/null +++ b/doc/DateExtensions.md @@ -0,0 +1,32 @@ + +# DateExtensions.kt + ```kotlin + /** + * Convert a given date to milliseconds + */ +fun Date.toMillis() : Long { + val calendar = Calendar.getInstance() + calendar.time = this + return calendar.timeInMillis +} + +/** + * Checks if dates are same + */ +fun Date.isSame(to : Date) : Boolean { + val sdf = SimpleDateFormat("yyyMMdd", Locale.getDefault()) + return sdf.format(this) == sdf.format(to) +} + +/** + * Converts raw string to date object using [SimpleDateFormat] + */ +fun String.convertStringToDate(simpleDateFormatPattern: String): Date? { + val simpleDateFormat = SimpleDateFormat(simpleDateFormatPattern, Locale.getDefault()) + var value: Date? = null + justTry { + value = simpleDateFormat.parse(this) + } + return value +} + ``` \ No newline at end of file diff --git a/doc/DrawableExtensions.md b/doc/DrawableExtensions.md new file mode 100644 index 0000000..4326b31 --- /dev/null +++ b/doc/DrawableExtensions.md @@ -0,0 +1,14 @@ + +# DrawableExtensions.kt + ```kotlin + /** + * Returns a compat drawable with tint added + */ +fun Drawable.withTint(colorInt: Int): Drawable { + return with(this) { + DrawableCompat.wrap(this).apply { + DrawableCompat.setTint(this, colorInt) + } + } +} + ``` \ No newline at end of file diff --git a/doc/GeneralExtensions.md b/doc/GeneralExtensions.md new file mode 100644 index 0000000..29e62cd --- /dev/null +++ b/doc/GeneralExtensions.md @@ -0,0 +1,26 @@ + +# GeneralExtensions.kt + ```kotlin + /** + * Wrapping try/catch to ignore catch block + */ +inline fun justTry(block: () -> T) = try { block() } catch (e: Throwable) {} + +/** + * App's debug mode + */ +inline fun debugMode(block : () -> Unit) { + if (BuildConfig.DEBUG) { + block() + } +} + +/** + * For functionality supported above API 21 (Eg. Material design stuff) + */ +inline fun lollipopAndAbove(block : () -> Unit) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + block() + } +} + ``` \ No newline at end of file diff --git a/doc/ImageExtensions.md b/doc/ImageExtensions.md new file mode 100644 index 0000000..6f83393 --- /dev/null +++ b/doc/ImageExtensions.md @@ -0,0 +1,20 @@ + +# ImageExtensions.kt + ```kotlin + /** + * Convert byte array to bitmap + */ +fun ByteArray.convertBytesToBitmap(): Bitmap = + BitmapFactory.decodeByteArray(this, 0, size) + +/** + * Convert bitmap to a byte array + */ +fun Bitmap.convertBitmapToBytes(): ByteArray { + val bytes: ByteArray + val stream = ByteArrayOutputStream() + this.compress(Bitmap.CompressFormat.PNG, 0, stream) + bytes = stream.toByteArray() + return bytes +} + ``` \ No newline at end of file diff --git a/doc/MetricExtensions.md b/doc/MetricExtensions.md new file mode 100644 index 0000000..7665c47 --- /dev/null +++ b/doc/MetricExtensions.md @@ -0,0 +1,22 @@ + +# MetricExtensions.kt + ```kotlin + /** + * Convert Celsius temperature to Fahrenheit + */ +fun Double.celsiusToFahrenheit() : Double = (this * 1.8) + 32 + +/** + * Convert Fahrenheit temperature to Celsius + */ +fun Double.fahrenheitToCelsius() : Double = (this - 32) * 5/9 + +/** + * Convert meters to miles + */ +fun Double.convertMetersToMiles(): Double { + return if (this != 0.0) { + this / 1609.34 + } else -1.0 +} + ``` \ No newline at end of file diff --git a/doc/StringExtensions.md b/doc/StringExtensions.md new file mode 100644 index 0000000..1ccfdee --- /dev/null +++ b/doc/StringExtensions.md @@ -0,0 +1,39 @@ + +# StringExtensions.kt + ```kotlin + /** + * Converts string to integer safely otherwise returns zero + */ +fun String.toIntOrZero() : Int { + var value = 0 + justTry { + value = this.toInt() + } + return value +} + +/** + * Converts a string to boolean such as 'Y', 'yes', 'TRUE' + */ + +fun String.toBoolean(): Boolean { + return this != "" && + (this.equals("TRUE", ignoreCase = true) + || this.equals("Y", ignoreCase = true) + || this.equals("YES", ignoreCase = true)) +} + +/** + * Converts string to camel case. Handles multiple strings and empty strings + */ +fun String.convertToCamelCase(): String { + var titleText = "" + if (!this.isEmpty()) { + val words = this.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + words.filterNot { it.isEmpty() } + .map { it.substring(0, 1).toUpperCase() + it.substring(1).toLowerCase() } + .forEach { titleText += it + " " } + } + return titleText.trim { it <= ' ' } +} + ``` \ No newline at end of file diff --git a/doc/ThreadingBlocks.md b/doc/ThreadingBlocks.md new file mode 100644 index 0000000..190acfa --- /dev/null +++ b/doc/ThreadingBlocks.md @@ -0,0 +1,44 @@ + +# ThreadingBlocks.kt + ```kotlin + /** + * Executes block of code on Android's main thread. Can be called from background thread. + */ +inline fun uiThreadExecutor(crossinline block: () -> Unit) { + val mainHandler = Handler(Looper.getMainLooper()) + mainHandler.post{ + block() + } +} + +/** + * Executes a function using RxJava observable on a separate thread and + * exposes it's response as lambda on main thread + * REQUIRED: RxJava, RxKotlin, RxAndroid + */ +fun asyncRxExecutor(heavyFunction: () -> T, response : (response : T?) -> Unit) { + val observable = Single.create({e -> + e.onSuccess(heavyFunction()) + }) + observable.subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { t: T? -> + response(t) + } +} + +/** + * Executes a function using Kotlin coroutines on a separate thread pool and + * exposes it's response as lambda on main thread. + * Thread pool is maintained by Anko Coroutines lib + * REQUIRED: Anko Coroutines + */ +fun asyncCoroutinesExecutor(heavyFunction: () -> T, response : (response : T?) -> Unit) { + async(UI) { + val data : Deferred = bg { + heavyFunction() + } + response(data.await()) + } +} + ``` \ No newline at end of file diff --git a/doc/ViewExtensions.md b/doc/ViewExtensions.md new file mode 100644 index 0000000..9128361 --- /dev/null +++ b/doc/ViewExtensions.md @@ -0,0 +1,37 @@ + +# ViewExtensions.kt + ```kotlin + /** + * Visibility modifiers and check functions + */ + +fun View.isVisibile(): Boolean = this.visibility == View.VISIBLE + +/** + * Sets text and content description using same string + */ +fun TextView.setTextWithContentDescription(value : String?) { + text = value + contentDescription = value +} + +/** + * Button enabling/disabling modifiers + */ + +fun Button.disableButton() { + isEnabled = false + alpha = 0.3f +} + +/** + * Sets color to status bar + */ +fun Window.addStatusBarColor(@ColorRes color: Int) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + this.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + this.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + this.statusBarColor = ContextCompat.getColor(this.context, color) + } +} + ``` \ No newline at end of file diff --git a/kotlin-doc/src/main/kotlin/Doc.kt b/kotlin-doc/src/main/kotlin/Doc.kt index 014fc84..6d498ab 100644 --- a/kotlin-doc/src/main/kotlin/Doc.kt +++ b/kotlin-doc/src/main/kotlin/Doc.kt @@ -40,8 +40,9 @@ fun main() { } if (functionDocTexts.isNotEmpty()) { val doc = "\n# ${file.name} \n ```kotlin \n ${functionDocTexts.trimEnd()} \n ```" - val readMePath = currentPath.replace("kotlin-doc", "README.md") - Files.write(Paths.get(readMePath), doc.toByteArray(), StandardOpenOption.APPEND) + println(file.name.replace(".kt", "")) + val readMePath = currentPath.replace("kotlin-doc", "doc/${file.name.replace(".kt", "")}.md") + Files.write(Paths.get(readMePath), doc.toByteArray(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING) } } }