Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
remove kdoc samples until they can be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Jul 24, 2021
1 parent 0263425 commit af652eb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 60 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ shadowJar {
}
mergeServiceFiles()
}

dokkaHtml {
dokkaSourceSets {
configureEach {
samples.from(files("src/main/kotlin/samples.kt"))
}
}
}
6 changes: 3 additions & 3 deletions src/main/kotlin/kweb/Element.kt
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ open class Element(
* Return a KVar that is tied to a property related to an element, which will update when an specified
* event fires on this element. This is a convenience wrapper around [bind].
*
* @sample kweb.InputElement.checked
* // @sample kweb.InputElement.checked
*
* @param accessor Function that takes an element id and returns a JavaScript expression to access that element
* @param updateOnEvent The event to listen for that signifies this element has been updated
Expand All @@ -497,7 +497,7 @@ open class Element(
* Return a KVar that is tied to a property related to an element, which will update when an specified
* event fires on this element.
*
* @sample kweb.InputElement.checked
* // @sample kweb.InputElement.checked
*
* @param reader Function that takes an element id and returns a JavaScript expression to read that element
* @param writer Function that takes an element id and a new value, and returns a JavaScript expression to
Expand Down Expand Up @@ -573,7 +573,7 @@ open class Element(
* @param preventDefault Whether [preventDefault()](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
* will be called on the event object.
*
* @sample kweb.ValueElement.getValue
* // @sample kweb.ValueElement.getValue
*/
fun on(retrieveJs: String? = null, preventDefault: Boolean = false) = OnReceiver(this, retrieveJs, preventDefault)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kweb/WebBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class WebBrowser(private val sessionId: String, val httpRequestInfo: HttpRequest
* If your JavaScript needs to use an empty JavaScript map, just insert a space
* between the {}s, eg. `{ }`
*
* @sample kweb.callJsFunction_sample
* // @sample kweb.callJsFunction_sample
*/
fun callJsFunction(jsBody: String, vararg args: JsonElement) {
val functionCall = if (cachedFunctions[jsBody] != null) {
Expand Down Expand Up @@ -185,7 +185,7 @@ class WebBrowser(private val sessionId: String, val httpRequestInfo: HttpRequest
}
}

fun callJsFunction_sample() {
private fun callJsFunction_sample() {
callJsFunction("alert({});", JsonPrimitive("Hello, I'm an alert box!"))
}

Expand Down
50 changes: 4 additions & 46 deletions src/main/kotlin/kweb/config/KwebConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,65 +48,23 @@ abstract class KwebConfiguration {
* Override the default robots.txt behavior, which is to return with a 404. Passed a Ktor [ApplicationCall]
* which may be used to return whatever you wish.
*
* @sample kweb.config.KwebConfiguration.robots_txt_sample
* // @sample robots_txt_sample
*/
open suspend fun robotsTxt(call: ApplicationCall) {
call.response.status(HttpStatusCode.NotFound)
call.respondText("robots.txt has not been specified)")
}

fun robots_txt_sample() {
val config = object : KwebDefaultConfiguration() {
override suspend fun robotsTxt(call: ApplicationCall) {
call.respondText(
ContentType("text", "plain"),
HttpStatusCode.OK
) {
"""
User-agent: Googlebot
Disallow: /nogooglebot/
User-agent: *
Allow: /
""".trimIndent()
}
}
}
Kweb(port = 1245, kwebConfig = config) {
// ...
}
}

/**
* Override the default favicon.ico behavior, which is to return with a 404. Passed a Ktor [ApplicationCall]
* Override the default robots.txt behavior, which is to return with a 404. Passed a Ktor [ApplicationCall]
* which may be used to return whatever you wish.
*
* @sample kweb.config.KwebConfiguration.favicon_sample
**/
* // @sample favicon_sample
*/
open suspend fun faviconIco(call: ApplicationCall) {
call.respondText("favicons not currently supported by kweb", status = HttpStatusCode.NotFound)
}

fun favicon_sample() {
// We should cache faviconBytes rather than re-loading for every function call
val faviconBytes = this::class.java.getResourceAsStream("favicon.ico")!!.readAllBytes()
val config = object : KwebDefaultConfiguration() {
override suspend fun faviconIco(call: ApplicationCall) {
call.respondBytes(
// Here the favicon.ico file is read from a resource
faviconBytes,
ContentType("image", "x-icon"),
status = HttpStatusCode.OK
)
}
}

Kweb(port = 1245, kwebConfig = config) {
// ...
}
}

protected object Accessor {
private val env = System.getenv()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ val jqueryCore = JQueryCorePlugin()
/**
* Selects the element based on id, then executes the provided js
*
* @sample table().executeOnSelf(".tablesort()")
* // @sample table().executeOnSelf(".tablesort()")
*/
fun Element.executeOnSelf(js: String) {
callJsFunction("$('#' + {})$js", id.json)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/kweb/prelude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class SelectElement(parent: Element) : ValueElement(parent, kvarUpdateEvent = "c
/**
* [<SELECT>](https://www.w3schools.com/tags/tag_select.asp)
*
* @sample select_sample
* // @sample select_sample
*/
fun ElementCreator<Element>.select(
attributes: Map<String, JsonPrimitive> = emptyMap(),
Expand Down Expand Up @@ -508,7 +508,7 @@ abstract class ValueElement(open val element: Element, val kvarUpdateEvent: Stri
* This [KVar] will update if the select element is changed (depending on [kvarUpdateEvent]), and will modify the element value
* if the KVar is changed.
*
* @sample select_sample
* // @sample select_sample
*/
var value: KVar<String>
get() {
Expand Down Expand Up @@ -745,7 +745,7 @@ fun <T : Any> ElementCreator<*>.renderEach(list: KVar<List<T>>, block: ElementCr
/**
* Create a [FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader)
*
* @sample fileReaderSample
* // @sample fileReaderSample
*/
fun ElementCreator<*>.fileInput(name: String? = null, initialValue: String? = null, size: Int? = null, placeholder: String? = null, attributes: Map<String, JsonPrimitive> = attr): FileFormInput {
val inputElement = input(attributes, InputType.file, name, initialValue, size, placeholder)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/kweb/routing/routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kweb.route
import kweb.state.KVar

/**
* @sample testSampleForRouting
* // @sample testSampleForRouting
*/

// TODO: Handle back button https://www.webdesignerdepot.com/2013/03/how-to-manage-the-back-button-with-javascript/
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kweb/state/render.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data class IndexedItem<I>(val index: Int, val total: Int, val item: I)
/**
*
*
* @sample ordered_view_set_sample
* // @sample ordered_view_set_sample
*/
fun <ITEM : Any, EL : Element> ElementCreator<EL>.renderEach(orderedViewSet: OrderedViewSet<ITEM>, renderer: ElementCreator<EL>.(KVar<ITEM>) -> Unit) {
val items = CopyOnWriteArrayList<ItemInfo<ITEM>>()
Expand Down Expand Up @@ -200,7 +200,7 @@ private enum class RenderState {
NOT_RENDERING, RENDERING_NO_PENDING_CHANGE, RENDERING_WITH_PENDING_CHANGE
}

fun ordered_view_set_sample() {
private fun ordered_view_set_sample() {
data class Cat(val name: String, val color: String)

val cats = Shoebox<Cat>()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kweb/table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.serialization.json.JsonPrimitive
/**
* Create tables
*
* @sample table_example
* // @sample table_example
*/
fun ElementCreator<Element>.table(attributes: Map<String, JsonPrimitive> = attr) = TableElement(element("table", attributes))
open class TableElement(parent: Element) : Element(parent)
Expand All @@ -26,7 +26,7 @@ open class TrElement(parent: Element) : Element(parent)
fun ElementCreator<Element>.td(attributes: Map<String, JsonPrimitive> = attr) = TdElement(element("td", attributes))
class TdElement(parent: Element) : Element(parent)

fun table_example() {
private fun table_example() {
Kweb(port = 2314, buildPage = {
doc.body.new {
table().new {
Expand Down

0 comments on commit af652eb

Please sign in to comment.