Skip to content

Commit

Permalink
updating example for video
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jan 10, 2025
1 parent ac13b3a commit ced28f1
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 44 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ having the comments modified in a `javadoc.jar` or a Dokka HTML website).

## Example

You can find a little video demo [right here](https://drive.google.com/file/d/1ddcU9bTLlj9IQ52fTei1ajeg0YfzEwkJ/view?usp=sharing).

### What you write:

<div style="width: 100%;">
Expand Down
41 changes: 37 additions & 4 deletions kodex-example-gradle-project-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nl.jolanrensen.kodex.defaultProcessors.ARG_DOC_PROCESSOR_LOG_NOT_FOUND
import nl.jolanrensen.kodex.gradle.creatingRunKodexTask

plugins {
kotlin("jvm") version "2.0.20"
Expand Down Expand Up @@ -27,14 +28,46 @@ dependencies {
implementation("androidx.compose.ui:ui:1.7.6")
}

// new experimental gradle extension
kodex {
preprocess(kotlin.sourceSets.main) {
// optional setup
arguments(
ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false,
)
arguments(ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false)
}
}

// old KoDEx notation
val kotlinMainSources: FileCollection = kotlin.sourceSets.main.get().kotlin.sourceDirectories

val preprocessMainKodexOld by creatingRunKodexTask(sources = kotlinMainSources) {
arguments(ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false)
}

// Modify all Jar tasks such that before running the Kotlin sources are set to
// the target of processKdocMain and they are returned back to normal afterwards.
tasks.withType<Jar> {
dependsOn(preprocessMainKodexOld)
outputs.upToDateWhen { false }

doFirst {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(preprocessMainKodexOld.targets)
}
}
}
}

doLast {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(kotlinMainSources)
}
}
}
}
preprocess(kotlin.sourceSets.test)
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,9 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.util.fastRoundToInt
import nl.jolanrensen.example.BiasAlignmentDocs.*

/**
* An interface to calculate the position of box of a certain $DIMENSION inside an available $DIMENSION.
* $REFERENCE is often used to define the $DIRECTION alignment of a layout inside a
* parent layout.
*/
@ExcludeFromSources
private interface CommonAlignmentDocs

/**
* Calculates the $DIRECTION position of a box of $DIMENSION [size] relative to the $SIDE side of
* an area of $DIMENSION [space]. {@include [OffsetNote]}
*/
@ExcludeFromSources
private interface AlignDocs

/**
* The returned offset can be negative or larger than `space - size`, meaning that
* the box will be positioned partially or completely outside the area.
*/
@ExcludeFromSources
private interface OffsetNote
import nl.jolanrensen.example.BiasAlignmentDocs.ALIGNMENT_REF
import nl.jolanrensen.example.BiasAlignmentDocs.END
import nl.jolanrensen.example.BiasAlignmentDocs.START

/**
* An interface to calculate the position of a sized box inside an available space. [Alignment] is
Expand All @@ -57,20 +37,31 @@ private interface OffsetNote
@Stable
fun interface Alignment {

/**
* The returned offset can be negative or larger than `space - size`, meaning that
* the box will be positioned partially or completely outside the area.
*/
@ExcludeFromSources
private interface OffsetNote

/**
* Calculates the position of a box of size [size] relative to the top left corner of an area of
* size [space]. {@include [OffsetNote]}
*/
fun align(size: IntSize, space: IntSize, layoutDirection: LayoutDirection): IntOffset

/**
* @include [CommonAlignmentDocs]
* {@set DIMENSION width} {@set DIRECTION horizontal} {@set REFERENCE [Alignment.Horizontal]}
* An interface to calculate the position of box of a certain width inside an available width.
* [Alignment.Horizontal] is often used to define the horizontal alignment of a layout inside a
* parent layout.
*/
@Stable
fun interface Horizontal {

/** @include [AlignDocs] {@set DIMENSION width} {@set DIRECTION horizontal} {@set SIDE left} */
/**
* Calculates the horizontal position of a box of width [size] relative to the left side of
* an area of width [space]. {@include [OffsetNote]}
*/
fun align(size: Int, space: Int, layoutDirection: LayoutDirection): Int

/**
Expand All @@ -81,13 +72,17 @@ fun interface Alignment {
}

/**
* @include [CommonAlignmentDocs]
* {@set DIMENSION height} {@set DIRECTION vertical}{@set REFERENCE [Alignment.Vertical]}
* An interface to calculate the position of a box of a certain height inside an available
* height. [Alignment.Vertical] is often used to define the vertical alignment of a layout
* inside a parent layout.
*/
@Stable
fun interface Vertical {

/** @include [AlignDocs] {@set DIMENSION height} {@set DIRECTION vertical} {@set SIDE top} */
/**
* Calculates the vertical position of a box of height [size] relative to the top edge of an
* area of height [space]. {@include [OffsetNote]}
*/
fun align(size: Int, space: Int): Int

/**
Expand Down Expand Up @@ -196,13 +191,9 @@ object AbsoluteAlignment {
* alignment will position the aligned size fully inside the available space, while outside the
* range it will the aligned size will be positioned partially or completely outside.
*/
@ExcludeFromSources
interface BiasAlignmentDocs {
interface ALIGNMENT_REF

interface START

interface END
@Suppress("ClassName", "ktlint:standard:blank-line-before-declaration", "ktlint:standard:statement-wrapping")
private interface BiasAlignmentDocs {
interface ALIGNMENT_REF; interface START; interface END
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nl.jolanrensen.example
interface MathH1 {

/**
* Computes the cosine of the angle [x] given in degrees.
* Computes the cosine of the anglle [x] given in degrees.
*
* Special cases:
* - `cos(NaN|+Inf|-Inf)` is `NaN`
Expand All @@ -14,7 +14,7 @@ interface MathH1 {
fun cos(x: Double): Double

/**
* ...
* Computes ...
*/
fun cos(x: Float): Double

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface MathH2 {
fun cos(x: Int): Double

/**
* Computes the sine of the angle [x] given in degrees {@comment Oh no! I mean radians!}.
* Computes the sine of the angle [x] given in degrees.
*
* Special cases:
* - `sin(NaN|+Inf|-Inf)` is `NaN`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nl.jolanrensen.example
interface MathH3 {

/**
* Computes the {@get OP} of the angle [x] given in degrees.
* Computes the {@get OP} of the angle [x] given in degrees. {@comment Oh no! I mean radians!}
*
* Special cases:
* - `{@get FUN}(NaN|+Inf|-Inf)` is `NaN`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package nl.jolanrensen.example

/**
* Our data looks something like this:
*
* ```json
* {@includeFile (../../../../resources/test.json)}
* ```
*/
interface IncludeFileDemo

/**
* Hello {@get name World}, today is {@get day unknown day}!
*
* @set day Friday
*/
interface GetSetDemo1

/**
* Hello $name=World, today is ${day=unknown day}!
*
* @set day Friday
*/
interface GetSetDemo2

/**
* Fibonacci in Kotlin:
* @sample [fibonacciUsingIteration]
*/
interface SampleDemo

fun fibonacciUsingIteration(num: Int): Int {
// SampleStart
var a = 0
var b = 1
var tmp: Int
for (i in 2..num) {
tmp = a + b
a = b
b = tmp
}
return b
// SampleEnd
}

/**
* That will be \$5.00
*
* To filter a list in Kotlin, you can call $example.
*
* {@set example `list.filter { it > 1 \}`}
*/
interface EscapeCharDemo
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kotlin {
}
}

// TODO make example for how to build Jars here too
kodex {
preprocess(kotlin.sourceSets.commonMain) {
generateJar = false
Expand Down

0 comments on commit ced28f1

Please sign in to comment.