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

Commit

Permalink
officially Kweb not KWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Mar 11, 2017
1 parent 5e5859d commit 264d221
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 56 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## KWeb
## Kweb

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) [![](https://jitpack.io/v/sanity/kweb.svg)](https://jitpack.io/#sanity/kweb) [![Build Status](https://travis-ci.org/sanity/kweb.svg?branch=master)](https://travis-ci.org/sanity/kweb)


KWeb is an experimental [Kotlin](http://kotlinlang.org/) library for building rich interactive web applications in pure Kotlin in a way
Kweb is an experimental [Kotlin](http://kotlinlang.org/) library for building rich interactive web applications in pure Kotlin in a way
that makes the distinction between web browser and server largely invisible to the programmer.

In particular, it can use the new [coroutines](https://github.com/Kotlin/kotlinx.coroutines) mechanism in
Expand All @@ -17,10 +17,10 @@ Building rich webapps normally requires navigating the
choosing between a vast multitude of tools, transpilers, minifiers, state maintainers, and so on, most of which will
be obsolete in 6 months. Then you're faced with handling interaction between client and server which is a whole other world of pain.

KWeb intends to solve this.
Kweb intends to solve this.

### How does it work?
KWeb treats the web browser as a fairly dumb robot, keeping most of the intelligence server-side,
Kweb treats the web browser as a fairly dumb robot, keeping most of the intelligence server-side,
relaying instructions to the client via a websocket, and receiving responses from the client. Instructions to the server
are simple JavaScript snippets which the browser immediately executes, returning the result to the server if requested.

Expand All @@ -32,17 +32,17 @@ transparently keeping server and client state in sync, motivated largely by the
to HTML in the event that the browser doesn't support JavaScript. This requirement is a lot less relevant today than it
was a decade ago.

Uniquely, KWeb takes advantage of the new coroutines functionality in the upcoming Kotlin 1.1 to handle
asynchronously waiting for responses from the client in a way that's almost transparent to the user of KWeb, without tying up threads (a definite no-no if you plan on having more than a handful of people visiting your website at a delay).
Uniquely, Kweb takes advantage of the new coroutines functionality in the upcoming Kotlin 1.1 to handle
asynchronously waiting for responses from the client in a way that's almost transparent to the user of Kweb, without tying up threads (a definite no-no if you plan on having more than a handful of people visiting your website at a delay).

#### News
##### 2017-01-09: Plugins
KWeb now has a simple but flexible plugin mechanism, allowing the addition of support for 3rd party JavaScript libraries.
Kweb now has a simple but flexible plugin mechanism, allowing the addition of support for 3rd party JavaScript libraries.

As an example, here is a [demo](https://github.com/sanity/kweb/blob/master/src/main/kotlin/com/github/sanity/kweb/demos/jquery/jquery.kt) of a rudimentary JQuery plugin being used, and [here](https://github.com/sanity/kweb/blob/master/src/main/kotlin/com/github/sanity/kweb/plugins/jqueryCore/JQueryCorePlugin.kt) you can see its implementation. Currently it only supports .remove() - but you should get a feel for how easy it will be to flesh out other functionality.

##### 2017-01-08: Initial announcement
KWeb is currently very experimental, at this stage more of a proof-of-concept and playground for ideas than anything
Kweb is currently very experimental, at this stage more of a proof-of-concept and playground for ideas than anything
even close to being useful in production.

The DOM DSL only covers a tiny subset of its eventual functionality, just barely more than is required for the TODO
Expand All @@ -54,7 +54,7 @@ Have questions, ideas, or otherwise want to contribute?
Join our Slack channel [#kweb on kotlinlang](https://kotlinlang.slack.com/messages/kweb/)! You may need to [sign up for kotlinlang](http://kotlinslackin.herokuapp.com/) first.

Take a look at our [open issues](https://github.com/sanity/kweb/issues), some of them should be quite easy to tackle, even
for someone new to KWeb. I will do my best to review and merge any suitable pull requests promptly.
for someone new to Kweb. I will do my best to review and merge any suitable pull requests promptly.

#### Getting started
1. Ensure you are using the "Early Access Preview 1.1" Kotlin plugin in IDEA, see "How to Try It" section at the
Expand All @@ -72,18 +72,18 @@ This is way longer than it needs to be due to the extensive comments, it may als
[here](https://github.com/sanity/kweb/blob/master/src/main/kotlin/com/github/sanity/kweb/demos/todo/todo.kt).

```kotlin
import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.to.Element
import com.github.sanity.kweb.dom.to.Element.InputType.setText
import kotlinx.coroutines.async
import kotlinx.coroutines.await

fun main(args: Array<String>) {
// Starts a web server listening on port 8091
KWeb(8091) {
Kweb(8091) {
doc.body.apply {
// Add a header to to the body, along with some simple instructions.
h1("Simple KWeb demo - a to-do list")
h1("Simple Kweb demo - a to-do list")
p("Edit the setText box below and click the button to add the item. Click an item to remove it.")

// If you're unfamiliar with the `apply` function, read this:
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.sanity'
version '0.0.33'
version '0.0.34'

buildscript {
ext.kotlin_version = '1.1.0'
Expand Down Expand Up @@ -61,7 +61,6 @@ dependencies {
compile('org.wasabifx:wasabi:0.3.120') {
exclude module: "slf4j-simple"
}
//compile 'org.jetbrains.kotlinx:vertx3-lang-kotlin:0.0.+'
compile 'com.github.salomonbrys.kotson:kotson:2.3.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
Expand Down
6 changes: 3 additions & 3 deletions docs/_posts/2017-03-03-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ js:

### What you should know

KWeb is built on [Kotlin 1.1](http://kotlinlang.org/), you should have some familiarity with Kotlin
Kweb is built on [Kotlin 1.1](http://kotlinlang.org/), you should have some familiarity with Kotlin
and the Java ecosystem on which it's built.

### Adding a KWeb dependency
### Adding a Kweb dependency

The KWeb library is distributed via [JitPack](https://jitpack.io/#sanity/kweb), it can be added
The Kweb library is distributed via [JitPack](https://jitpack.io/#sanity/kweb), it can be added
easily to any Kotlin project:

#### Gradle
Expand Down
6 changes: 3 additions & 3 deletions docs/_posts/2017-03-08-your-first-kwebsite.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add a file like the following to your project:

```kotlin
fun main(args: Array<String>) {
KWeb(port = 7823) {
Kweb(port = 7823) {
doc.body.h1().setText("Hello World!")
}
}
Expand All @@ -24,7 +24,7 @@ Let's edit the file to do something more interesting:

```kotlin
fun main(args: Array<String>) {
KWeb(port = 7823) {
Kweb(port = 7823) {
var counter = 0
val h1 = doc.body.h1()
h1.setText("Hello World!")
Expand All @@ -42,7 +42,7 @@ we've assigned the header element to a variable called `h1`, and then we use the
Next we create a click event listener on the header element, once clicked we set the text of the element to the value
of the variable `counter`, and increase the value of `counter`.

Kill KWeb if it is still running, and run this new version. Try clicking on the text.
Kill Kweb if it is still running, and run this new version. Try clicking on the text.

**Troubleshooting**: If you get an error like `Exception in thread "main" java.net.BindException: Address already in use` it means
that the previous version is still running and therefore the new version is unable to listen on port 7823, make
Expand Down
10 changes: 5 additions & 5 deletions docs/_posts/2017-03-09-live-coding.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ error, but this bug in HotSwapAgent has been reported and may be fixed by now.

#### Step 4 : Configure Kweb to refresh webpages automatically

Set the `refreshPageOnHotswap` KWeb constructor parameter to `true`:
Set the `refreshPageOnHotswap` Kweb constructor parameter to `true`:

```kotlin
KWeb(port = 1234, refreshPageOnHotswap = true) {
Kweb(port = 1234, refreshPageOnHotswap = true) {
```

#### Step 5 : Run your code
Expand All @@ -63,13 +63,13 @@ Now run your project in debug mode (the button with the green bug), you should s

```
HOTSWAP AGENT: 19:01:57.851 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {1.1.0-SNAPSHOT} - unlimited runtime class redefinition.
HOTSWAP AGENT: 19:01:58.178 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [KWebHotswapPlugin]
HOTSWAP AGENT: 19:01:58.178 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [KwebHotswapPlugin]
HOTSWAP AGENT: 19:01:59.145 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [Hotswapper, WatchResources, ClassInitPlugin, Hibernate, Hibernate3JPA, Hibernate3, Spring, Jersey1, Jersey2, Jetty, Tomcat, ZK, Logback, Log4j2, MyFaces, Mojarra, Seam, ELResolver, WildFlyELResolver, OsgiEquinox, Owb, Proxy, WebObjects, Weld, JBossModules, ResteasyRegistry, Deltaspike, JavaBeans]
HOTSWAP AGENT: 19:01:59.231 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: []
HOTSWAP AGENT: 19:02:00.009 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.logback.LogbackPlugin' initialized in ClassLoader 'sun.misc.Launcher$AppClassLoader@18b4aac2'.
```

This indicates that HotSwapAgent is working, and in particular look out for `Discovered plugins: [KWebHotswapPlugin]` as this will indicate
This indicates that HotSwapAgent is working, and in particular look out for `Discovered plugins: [KwebHotswapPlugin]` as this will indicate
that Kweb is aware of HotSwapAgent (this is necessary for the automatic refresh).

#### Step 6 : Try it!
Expand All @@ -79,4 +79,4 @@ modified (Shift+Command+F9 on a Mac), in a few seconds the browser window should
the change.
Note that HotSwapAgent doesn't work with every code modification, for example if you make a change to the configuration
of your KWeb object it will not pick this up.
of your Kweb object it will not pick this up.
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "Introduction to Kweb"
1. TOC
{:toc}

#### What is KWeb?
#### What is Kweb?

Kweb is a library for building rich web applications in the [Kotlin](http://kotlinlang.org/)
programming language. You can think of it as a powerful Kotlin DSL that allows you to remote-control
Expand Down Expand Up @@ -69,7 +69,7 @@ supports.
be organized

#### How does it work?
KWeb keeps all of the logic server-side, and uses websockets to communicate with web browsers.
Kweb keeps all of the logic server-side, and uses websockets to communicate with web browsers.
We also take advantage of Kotlin's powerful new coroutines mechanism to efficiently handle
asynchronicity largely invisible to the programmer.

Expand All @@ -79,9 +79,9 @@ Here we create a simple "todo" list app:

```kotlin
fun main(args: Array<String>) {
KWeb(8091, debug = true) {
Kweb(8091, debug = true) {
doc.body.apply {
h1().addText("Simple KWeb demo - a to-do list")
h1().addText("Simple Kweb demo - a to-do list")
p().addText("Edit the text box below and click the button to add the item. Click an item to remove it.")

val ul = ul().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ wont be happy. But I thought for your use case it would enable you to move thing
at your end till its properly configurable
*/

class KWeb(val port: Int,
class Kweb(val port: Int,
val debug: Boolean = true,
val refreshPageOnHotswap : Boolean = false,
val plugins: List<KWebPlugin> = Collections.emptyList(),
Expand Down Expand Up @@ -80,10 +80,10 @@ class KWeb(val port: Int,
val logStatement = logStatementBuilder.toString()
logger.warn { logStatement }
}) {
buildPage(RootReceiver(newClientId, httpRequestInfo, this@KWeb))
buildPage(RootReceiver(newClientId, httpRequestInfo, this@Kweb))
}
} else {
buildPage(RootReceiver(newClientId, httpRequestInfo, this@KWeb))
buildPage(RootReceiver(newClientId, httpRequestInfo, this@Kweb))
}
for (plugin in plugins) {
execute(newClientId, plugin.executeAfterPageCreation())
Expand All @@ -103,7 +103,7 @@ class KWeb(val port: Int,
}
}
server.start(wait = false)
logger.info {"KWeb is listening on port $port"}
logger.info {"Kweb is listening on port $port"}
}

private fun handleInboundMessage(ctx: ChannelHandlerContext, message: C2SWebsocketMessage) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/sanity/kweb/RootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName

class RootReceiver(private val clientId: String, val httpRequestInfo: HttpRequestInfo, internal val cc: KWeb, val response: String? = null) {
class RootReceiver(private val clientId: String, val httpRequestInfo: HttpRequestInfo, internal val cc: Kweb, val response: String? = null) {
private val plugins: Map<KClass<out KWebPlugin>, KWebPlugin> by lazy {
cc.appliedPlugins.map { it::class to it }.toMap()
}
Expand All @@ -22,7 +22,7 @@ class RootReceiver(private val clientId: String, val httpRequestInfo: HttpReques
if (!plugins.contains(requiredPlugin)) missing.add(requiredPlugin.simpleName ?: requiredPlugin.jvmName)
}
if (missing.isNotEmpty()) {
throw RuntimeException("Plugin(s) ${missing.joinToString(separator = ", ")} required but not passed to KWeb constructor")
throw RuntimeException("Plugin(s) ${missing.joinToString(separator = ", ")} required but not passed to Kweb constructor")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/sanity/kweb/demos/async/async.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.async

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.createElement
import com.github.sanity.kweb.dom.element.modification.setAttribute
import com.github.sanity.kweb.dom.element.modification.addText
Expand All @@ -13,7 +13,7 @@ import kotlinx.coroutines.experimental.future.future
*/
fun main(args: Array<String>) {
println("Visit http://127.0.0.1:8091/ in your browser...")
KWeb(8091) {
Kweb(8091) {
doc.body.apply {
val p1 = createElement("p").setAttribute("id", 1).addText("one")
val p2 = createElement("p").setAttribute("id", 2).addText("two")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.github.sanity.kweb.demos.errorDetection.buildPageTime

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb

/**
* Created by ian on 3/10/17.
*/

fun main(args: Array<String>) {
KWeb(port = 1234, debug = true) {
Kweb(port = 1234, debug = true) {
Thread.sleep(1000)
}
Thread.sleep(2000)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/sanity/kweb/demos/event/event.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.event

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.input
import com.github.sanity.kweb.dom.element.events.on

Expand All @@ -9,7 +9,7 @@ import com.github.sanity.kweb.dom.element.events.on
*/

fun main(args: Array<String>) {
KWeb(4682) {
Kweb(4682) {
doc.body.apply {
input().on.keydown { e ->
println("Received: '${e}'")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.materialDesignLite

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.a
import com.github.sanity.kweb.dom.element.creation.span
import com.github.sanity.kweb.dom.element.events.on
Expand All @@ -16,7 +16,7 @@ import com.github.sanity.kweb.plugins.materialdesignlite.table.table

fun main(args: Array<String>) {
println("Visit http://127.0.0.1:8091/ in your browser...")
KWeb(port = 8091, plugins = listOf(materialDesignLite)) {
Kweb(port = 8091, plugins = listOf(materialDesignLite)) {
doc.body.apply {
mdl.layout(fixedHeader = true).apply {
addHeader()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.plugins.bootstrap4

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.*
import com.github.sanity.kweb.dom.element.creation.createElement
import com.github.sanity.kweb.dom.element.creation.div
Expand Down Expand Up @@ -40,11 +40,11 @@ From http://v4-alpha.getbootstrap.com/components/forms/#textual-inputs

fun main(args: Array<String>) {
println("Visit http://127.0.0.1:8091/ in your browser...")
KWeb(port = 8091, plugins = listOf(bootstrap4)) {
Kweb(port = 8091, plugins = listOf(bootstrap4)) {
doc.body.apply {
div().apply {
container().apply {
h1().addText("KWeb Bootstrap4 demo")
h1().addText("Kweb Bootstrap4 demo")

p().addText("The following is a simple setText field which does nothing")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.plugins.jquery

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.attributes.attr
import com.github.sanity.kweb.dom.attributes.classes
import com.github.sanity.kweb.dom.element.creation.h1
Expand All @@ -14,7 +14,7 @@ import com.github.sanity.kweb.plugins.jqueryCore.jqueryCore
*/

fun main(args: Array<String>) {
KWeb(port = 8091, plugins = listOf(jqueryCore)) {
Kweb(port = 8091, plugins = listOf(jqueryCore)) {
doc.body.apply {
h1(attr.classes("test")).addText("Simple Demo of JQuery plugin").apply {
jquery(".test").apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.plugins.select2

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.select
import com.github.sanity.kweb.plugins.select2.Item
import com.github.sanity.kweb.plugins.select2.Suggestions
Expand All @@ -11,7 +11,7 @@ import com.github.sanity.kweb.plugins.select2.select2
*/

fun main(args: Array<String>) {
KWeb(5461, plugins = listOf(select2)) {
Kweb(5461, plugins = listOf(select2)) {
doc.body.apply {
val select = select()
select.select2(suggestions = { Suggestions(results = listOf(Item("1", "One"), Item("2", "Two"))) }).on.select {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/github/sanity/kweb/demos/todo/todo.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.sanity.kweb.demos.todo

import com.github.sanity.kweb.KWeb
import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.*
import com.github.sanity.kweb.dom.element.events.on
import com.github.sanity.kweb.dom.element.modification.addText
Expand All @@ -10,10 +10,10 @@ import kotlinx.coroutines.experimental.future.future

fun main(args: Array<String>) {
// Starts a web server listening on port 8091
KWeb(8091, debug = true) {
Kweb(8091, debug = true) {
doc.body.apply {
// Add a header parent to the body, along with some simple instructions.
h1().addText("Simple KWeb demo - a to-do list")
h1().addText("Simple Kweb demo - a to-do list")
p().addText("Edit the text box below and click the button to add the item. Click an item to remove it.")

// If you're unfamiliar with the `apply` function, read this:
Expand Down
Loading

0 comments on commit 264d221

Please sign in to comment.