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

Commit

Permalink
bump version to 0.3.2 to try to fix a bug possibly related to depende…
Browse files Browse the repository at this point in the history
…ncy problems
  • Loading branch information
sanity committed Jul 4, 2018
1 parent bc3accc commit f171cb1
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 28 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
buildscript {
ext.kotlin_version = '1.2.50'
ext.dokka_version = '0.9.15'
ext.ktor_version = '0.9.3-alpha-3'
ext.ktor_version = '0.9.3'

repositories {
jcenter()
Expand All @@ -32,7 +32,7 @@ buildscript {
}

group 'io.kweb'
version '0.3.1'
version '0.3.2'

apply plugin: 'java'
apply plugin: 'kotlin'
Expand Down Expand Up @@ -119,7 +119,7 @@ dependencies {
compile 'io.github.microutils:kotlin-logging:1.4.9'
compile("org.reflections:reflections:0.9.11")

compile 'com.github.kwebio:shoebox:0.2.16'
compile 'com.github.kwebio:shoebox:0.2.17'

compile 'com.github.yamamotoj:cached-property-kotlin:0.1.0'

Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/io/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Kweb(val port: Int,
val plugins: List<io.kweb.plugins.KWebPlugin> = java.util.Collections.emptyList(),
val appServerConfigurator: (io.ktor.routing.Routing) -> Unit = {},
val onError: ((List<StackTraceElement>, io.kweb.JavaScriptError) -> io.kweb.LogError) = { _, _ -> true },
val maxPageBuildTimeMS: Long = 500,
val maxPageBuildTimeMS: Long = 1000,
val clientStateTimeout : Duration = Duration.ofHours(1),
val buildPage: WebBrowser.() -> Unit
) : Closeable {
Expand Down Expand Up @@ -108,6 +108,12 @@ class Kweb(val port: Int,
.replace("<!-- END HEADER PLACEHOLDER -->", endHeadBuilder.toString())

// Setup default KWeb routing.

get("/robots.txt") {
call.response.status(HttpStatusCode.NotFound)
call.respondText("robots.txt not currently supported by kweb")
}

get("/favicon.ico") {
call.response.status(HttpStatusCode.NotFound)
call.respondText("favicons not currently supported by kweb")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/kweb/WebBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class WebBrowser(private val sessionId: String, val httpRequestInfo: HttpRequest
val url = KVar(httpRequestInfo.requestedUrl)

url.addListener { old, new ->
logger.info("URL updated from $old to $new")
pushState(new)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.kweb.browserConnection

import io.ktor.http.cio.websocket.Frame.Text
import io.ktor.http.cio.websocket.WebSocketSession
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.launch
import mu.KotlinLogging
import java.util.concurrent.ConcurrentLinkedQueue

Expand All @@ -13,10 +13,8 @@ sealed class KwebClientConnection {

class WebSocket(private val channel: WebSocketSession) : KwebClientConnection() {

val socketContext = newSingleThreadContext("outbound-websocket-queue")

override fun send(message: String) {
launch(socketContext) {
launch {
channel.send(Text(message))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/kweb/demos/todo/todoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun main(args: Array<String>) {

pageBorderAndTitle("Todo List") {

val url = url(simpleUrlParser)
val url = doc.receiver.url(simpleUrlParser)

div(s.content).new {
render(url.path[0]) { entityType ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ open class ElementCreator<out PARENT_TYPE : Element>(
plugin.elementCreationHook(newElement)
}
onCleanup(withParent = false) {
logger.debug("Deleting element ${newElement.id}")
logger.debug("Deleting element ${newElement.id}", RuntimeException())
newElement.delete()
}
return newElement
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/io/kweb/dom/element/creation/tags/other.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fun ElementCreator<Element>.textArea(rows : Int? = null, attributes: Map<String,
open class SelectElement(parent: Element) : Element(parent)
fun ElementCreator<Element>.select(attributes: Map<String, Any> = attr) = SelectElement(element("select", attributes))

open class OptionElement(parent: Element) : Element(parent)
fun ElementCreator<Element>.option(attributes: Map<String, Any> = attr) = OptionElement(element("option", attributes))


open class H1Element(parent: Element) : Element(parent)
fun ElementCreator<Element>.h1(attributes: Map<String, Any> = attr) = H1Element(element("h1", attributes))

Expand Down
103 changes: 102 additions & 1 deletion src/main/kotlin/io/kweb/plugins/semanticUI/SemanticUIClasses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ class SemanticUIClasses : AttributeBuilder() {
classes("attached")
return this
}


val balance : SemanticUIClasses get() {
classes("balance")
return this
}

val banner : SemanticUIClasses get() {
classes("banner")
return this
Expand Down Expand Up @@ -156,6 +161,11 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val compact : SemanticUIClasses get() {
classes("compact")
return this
}

val container : SemanticUIClasses get() {
classes("container")
return this
Expand Down Expand Up @@ -196,6 +206,11 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val dropdown : SemanticUIClasses get() {
classes("dropdown")
return this
}

val edit : SemanticUIClasses get() {
classes("edit")
return this
Expand All @@ -212,6 +227,11 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val error : SemanticUIClasses get() {
classes("error")
return this
}

val equal : SemanticUIClasses get() {
classes("equal")
return this
Expand Down Expand Up @@ -324,11 +344,21 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val indeterminate : SemanticUIClasses get() {
classes("indeterminate")
return this
}

val info : SemanticUIClasses get() {
classes("info")
return this
}

val inline : SemanticUIClasses get() {
classes("inline")
return this
}

val input : SemanticUIClasses get() {
classes("input")
return this
Expand Down Expand Up @@ -390,6 +420,12 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val loader : SemanticUIClasses get() {
classes("loader")
return this
}


val loading : SemanticUIClasses get() {
classes("loading")
return this
Expand Down Expand Up @@ -451,6 +487,12 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val notched : SemanticUIClasses get() {
classes("notched")
return this
}


val olive : SemanticUIClasses get() {
classes("olive")
return this
Expand Down Expand Up @@ -513,11 +555,27 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}


val scale : SemanticUIClasses get() {
classes("scale")
return this
}

val secondary : SemanticUIClasses get() {
classes("secondary")
return this
}

val selection : SemanticUIClasses get() {
classes("selection")
return this
}

val sortable : SemanticUIClasses get() {
classes("sortable")
return this
}

val success : SemanticUIClasses get() {
classes("success")
return this
Expand Down Expand Up @@ -613,6 +671,22 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val stackable : SemanticUIClasses get() {
classes("stackable")
return this
}

val statistic : SemanticUIClasses get() {
classes("statistic")
return this
}

val statistics : SemanticUIClasses get() {
classes("statistics")
return this
}


val striped : SemanticUIClasses get() {
classes("striped")
return this
Expand All @@ -628,6 +702,16 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val table: SemanticUIClasses get() {
classes("table")
return this
}

val teal: SemanticUIClasses get() {
classes("teal")
return this
}

val three : SemanticUIClasses get() {
classes("three")
return this
Expand Down Expand Up @@ -687,6 +771,18 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val yellow : SemanticUIClasses get() {
classes("yellow")
return this
}


val value : SemanticUIClasses get() {
classes("value")
return this
}


val very : SemanticUIClasses get() {
classes("very")
return this
Expand All @@ -702,6 +798,11 @@ class SemanticUIClasses : AttributeBuilder() {
return this
}

val warning : SemanticUIClasses get() {
classes("warning")
return this
}

val wide : SemanticUIClasses get() {
classes("wide")
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SemanticUIPlugin : KWebPlugin(dependsOn = setOf(jqueryCore)) {
startHead.append("""
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.js"></script>
<script src="https://semantic-ui.com/javascript/library/tablesort.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
""".trimIndent())
}
Expand Down
54 changes: 44 additions & 10 deletions src/main/kotlin/io/kweb/state/persistent/persistent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,40 @@ import io.kweb.dom.element.creation.ElementCreator
import io.kweb.dom.element.creation.tags.*
import io.kweb.shoebox.*
import io.kweb.state.*
import kotlinx.coroutines.experimental.*
import mu.KotlinLogging
import java.util.*
import kotlin.NoSuchElementException
import java.util.concurrent.CopyOnWriteArrayList

/**
* Created by ian on 6/18/17.
*/

private val logger = KotlinLogging.logger {}
val logger = KotlinLogging.logger {}

fun main(args: Array<String>) {

data class D(val a: Int, val b: Int)

val dv = KVar(D(1, 1))

Kweb(port = 13513) {
doc.body.new {
div().new {
render(dv) {
div().text(it.a.toString())
div().text(it.b.toString())
}
}
}
}

launch {
while(true) {
dv.value = dv.value.copy(a = dv.value.a + 1)
delay(20000)
}
}
}

fun <T : Any> ElementCreator<*>.render(kval : KVal<T>, renderer : ElementCreator<Element>.(T) -> Unit) {
var childEC = ElementCreator(this.addToElement, this)
Expand Down Expand Up @@ -50,7 +75,7 @@ data class IndexedItem<I>(val index : Int, val total : Int, val item : I)
* @sample ordered_view_set_sample
*/
fun <ITEM : Any, EL : Element> ElementCreator<EL>.renderEach(orderedViewSet: OrderedViewSet<ITEM>, renderer : ElementCreator<EL>.(KVar<ITEM>) -> Unit) {
val items = ArrayList<ItemInfo<ITEM>>()
val items = CopyOnWriteArrayList<ItemInfo<ITEM>>()
for (keyValue in orderedViewSet.keyValueEntries) {
items += createItem(orderedViewSet, keyValue, renderer, insertAtPosition = null)
}
Expand All @@ -60,10 +85,14 @@ fun <ITEM : Any, EL : Element> ElementCreator<EL>.renderEach(orderedViewSet: Ord
}
this.onCleanup(true) { orderedViewSet.deleteInsertListener(onInsertHandler) }

val onRemoveHandler = orderedViewSet.onRemove { index, _ ->
val removed = items.removeAt(index)
removed.creator.cleanup()
removed.KVar.close()
val onRemoveHandler = orderedViewSet.onRemove { index, keyValue ->
if (index >= items.size) {
logger.warn("Invalid index $index to retrieve item from items list of size ${items.size} for key ${keyValue.key} and item ${keyValue.value}", RuntimeException())
} else {
val removed = items.removeAt(index)
removed.creator.cleanup()
removed.KVar.close()
}
}

this.onCleanup(true) { orderedViewSet.deleteRemoveListener(onRemoveHandler) }
Expand All @@ -77,8 +106,13 @@ private fun <ITEM : Any, EL : Element> ElementCreator<EL>.createItem(
: ItemInfo<ITEM> {
val itemElementCreator = ElementCreator(this.addToElement, this, insertAtPosition)
val itemVar = itemElementCreator.toVar(orderedViewSet.view.viewOf, keyValue.key)
renderer(itemElementCreator, itemVar)
if (itemElementCreator.elementsCreated != 1) {
try {
renderer(itemElementCreator, itemVar)
} catch (e: Exception) {
logger.error("Error rendering item", e)
}

if (itemElementCreator.elementsCreated > 1) {
/*
* Only one element may be created per-item because otherwise it would be much more complicated to figure
* out where new items should be inserted by the onInsert handler below. onRemove would be easier because
Expand Down
Loading

0 comments on commit f171cb1

Please sign in to comment.