Skip to content

Commit

Permalink
Rename .filecontent to .read
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jul 23, 2024
1 parent 1db75c6 commit efbac0f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.io.path.Path
*/
val Data: Module =
setOf(
::fileContent,
::read,
::csv,
)

Expand Down Expand Up @@ -59,8 +59,7 @@ internal fun file(
* If not specified or infinite, the whole file is read
* @return a string value of the text extracted from the file
*/
@Name("filecontent")
fun fileContent(
fun read(
@Injected context: Context,
path: String,
@Name("lines") lineRange: Range = Range.INFINITE,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun text(
/**
* Creates a code block. Contrary to its standard Markdown implementation with backtick/tilde fences,
* this function accepts Markdown content as its body, hence it can be used - for example -
* in combination with [fileContent] to load code from file.
* in combination with [read] to load code from file.
* @param language optional language of the code
* @param showLineNumbers whether to show line numbers
* @param body code content
Expand Down
8 changes: 4 additions & 4 deletions stdlib/src/test/kotlin/eu/iamgio/quarkdown/stdlib/DataTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ class DataTest {

assertEquals(
"Line 1${LINE_SEPARATOR}Line 2${LINE_SEPARATOR}${LINE_SEPARATOR}Line 4${LINE_SEPARATOR}Line 5",
fileContent(context, path).unwrappedValue,
read(context, path).unwrappedValue,
)

assertEquals(
"Line 2${LINE_SEPARATOR}${LINE_SEPARATOR}Line 4",
fileContent(context, path, Range(2, 4)).unwrappedValue,
read(context, path, Range(2, 4)).unwrappedValue,
)

assertEquals(
"Line 1${LINE_SEPARATOR}Line 2",
fileContent(context, path, Range(null, 2)).unwrappedValue,
read(context, path, Range(null, 2)).unwrappedValue,
)

assertEquals(
"Line 4${LINE_SEPARATOR}Line 5",
fileContent(context, path, Range(4, null)).unwrappedValue,
read(context, path, Range(4, null)).unwrappedValue,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class FullPipelineTest {
assertEquals("<p><em><strong>result</strong></em>: 11</p>", it)
}

execute(".code\n .filecontent {code.txt}") {
execute(".code\n .read {code.txt}") {
assertEquals(
"<pre><code>Line 1${System.lineSeparator()}Line 2${System.lineSeparator()}${System.lineSeparator()}Line 3</code></pre>",
it,
Expand Down

0 comments on commit efbac0f

Please sign in to comment.