-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,763 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package dev.jmfayard | ||
|
||
|
||
import dev.jmfayard.bootstrap.siteStatics | ||
import io.kotless.dsl.ktor.Kotless | ||
import io.kotless.dsl.ktor.lang.LambdaWarming | ||
import io.kotless.dsl.ktor.lang.event.events | ||
import io.kotless.examples.site.pages.* | ||
import io.ktor.application.Application | ||
import io.ktor.application.call | ||
import io.ktor.http.ContentType | ||
import io.ktor.response.respondText | ||
import io.ktor.routing.get | ||
import io.ktor.routing.route | ||
import io.ktor.routing.routing | ||
|
||
class Server : Kotless() { | ||
override fun prepare(app: Application) { | ||
app.routing { | ||
siteStatics() | ||
|
||
get("/") { | ||
call.respondText(MainPages.root(), ContentType.Text.Html) | ||
} | ||
|
||
//Supports route inner calls | ||
route("pages") { | ||
get("/introduction") { | ||
call.respondText(IntroductionPages.introduction(), ContentType.Text.Html) | ||
} | ||
|
||
get("/faq") { | ||
call.respondText(FAQPages.faq(), ContentType.Text.Html) | ||
} | ||
|
||
|
||
route("/dsl") { | ||
get("/overview") { | ||
call.respondText(DSLPages.overview(), ContentType.Text.Html) | ||
} | ||
get("/lifecycle") { | ||
call.respondText(DSLPages.lifecycle(), ContentType.Text.Html) | ||
} | ||
get("/permissions") { | ||
call.respondText(DSLPages.permissions(), ContentType.Text.Html) | ||
} | ||
get("/http") { | ||
call.respondText(DSLPages.http(), ContentType.Text.Html) | ||
} | ||
get("/events") { | ||
call.respondText(DSLPages.events(), ContentType.Text.Html) | ||
} | ||
} | ||
|
||
route("/plugin") { | ||
get("/overview") { | ||
call.respondText(PluginPages.overview(), ContentType.Text.Html) | ||
} | ||
get("/configuration") { | ||
call.respondText(PluginPages.configuration(), ContentType.Text.Html) | ||
} | ||
get("/tasks") { | ||
call.respondText(PluginPages.tasks(), ContentType.Text.Html) | ||
} | ||
get("/extensions") { | ||
call.respondText(PluginPages.extensions(), ContentType.Text.Html) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
app.events { | ||
subscribe(LambdaWarming) { | ||
println("Lambda warming execution") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.kotless.examples.site.bootstrap | ||
|
||
import kotlinx.html.* | ||
|
||
fun BODY.mainContainer(body: MAIN.() -> Unit) { | ||
main("container") { | ||
role = "main" | ||
body() | ||
} | ||
} | ||
|
||
fun BODY.mainDoc(body: DIV.() -> Unit) { | ||
mainContainer { | ||
div("doc") { | ||
body() | ||
} | ||
} | ||
} | ||
|
||
fun BODY.mainLanding(body: DIV.() -> Unit) { | ||
mainContainer { | ||
div("landing") { | ||
body() | ||
} | ||
} | ||
} | ||
|
||
fun FlowContent.row(body: DIV.() -> Unit) { | ||
div("row") { | ||
body() | ||
} | ||
} | ||
|
||
fun DIV.smCol(size: Int, body: DIV.() -> Unit) { | ||
div("col-sm-$size") { | ||
body() | ||
} | ||
} | ||
|
||
fun FlowContent.simpleCard(classes: String = "", body: DIV.() -> Unit) { | ||
div("card $classes") { | ||
div("card-body") { | ||
body() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package io.kotless.examples.site.bootstrap | ||
|
||
import kotlinx.html.* | ||
|
||
|
||
fun BODY.navbar(body: NAV.() -> Unit) { | ||
nav("navbar navbar-expand-sm navbar-dark bg-dark fixed-top") { | ||
body() | ||
} | ||
} | ||
|
||
fun NAV.brand(labelImg: String, text: String, iconHref: String) { | ||
img(alt = "Kotless label", src = labelImg, classes = "img-label") | ||
a(iconHref, classes = "navbar-brand") { | ||
+text | ||
} | ||
} | ||
|
||
fun UL.dropdown(label: String, labelsToHref: List<Pair<String, String>>) { | ||
li("nav-item dropdown") { | ||
a(href = "#", classes = "nav-link dropdown-toggle") { | ||
attributes["id"] = "dropdown-dsl" | ||
attributes["data-toggle"] = "dropdown" | ||
attributes["aria-haspopup"] = "true" | ||
attributes["aria-expanded"] = "false" | ||
+label | ||
} | ||
div("dropdown-menu") { | ||
attributes["aria-labelledby"] = "dropdown-dsl" | ||
for ((btnLabel, href) in labelsToHref) { | ||
a(href = href, classes = "dropdown-item") { | ||
+btnLabel | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun BODY.siteNavbar() { | ||
navbar { | ||
brand("/favicon.apng", "Kotless", "/") | ||
|
||
button(classes = "navbar-toggler collapsed") { | ||
type = ButtonType.button | ||
attributes["data-toggle"] = "collapse" | ||
attributes["data-target"] = "#navbar-toggler" | ||
attributes["aria-controls"] = "navbar-toggler" | ||
attributes["aria-expanded"] = "false" | ||
attributes["aria-label"] = "Toggle navigation" | ||
span(classes = "navbar-toggler-icon") { } | ||
} | ||
|
||
div(classes = "navbar-collapse collapse") { | ||
style = "" | ||
id = "navbar-toggler" | ||
|
||
ul("navbar-nav") { | ||
li("nav-item") { | ||
a(href = "/pages/introduction", classes = "nav-link") { | ||
+"Getting Started" | ||
} | ||
} | ||
|
||
dropdown("DSL", listOf( | ||
"Overview" to "/pages/dsl/overview", | ||
"Lifecycle" to "/pages/dsl/lifecycle", | ||
"HTTP" to "/pages/dsl/http", | ||
"Events" to "/pages/dsl/events", | ||
"Permissions" to "/pages/dsl/permissions" | ||
)) | ||
|
||
dropdown("Plugin", listOf( | ||
"Overview" to "/pages/plugin/overview", | ||
"Configuration" to "/pages/plugin/configuration", | ||
"Tasks" to "/pages/plugin/tasks", | ||
"Extensions" to "/pages/plugin/extensions" | ||
)) | ||
|
||
li("nav-item") { | ||
a(href = "/pages/faq", classes = "nav-link") { | ||
+"FAQ" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.kotless.examples.site.bootstrap | ||
|
||
import kotlinx.html.* | ||
|
||
private var HTMLTag.integrity: String | ||
get() = attributes["integrity"]!! | ||
set(value) { | ||
attributes["integrity"] = value | ||
} | ||
|
||
private var HTMLTag.crossorigin: String | ||
get() = attributes["crossorigin"]!! | ||
set(value) { | ||
attributes["crossorigin"] = value | ||
} | ||
|
||
|
||
fun TagConsumer<String>.headerSite() { | ||
head { | ||
title { | ||
+"Kotless Serverless Framework" | ||
} | ||
link("/favicon.apng", rel = "icon") | ||
link { | ||
href = "https://use.fontawesome.com/releases/v5.8.1/css/all.css" | ||
rel = "stylesheet" | ||
crossorigin = "anonymous" | ||
integrity = "sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" | ||
} | ||
link { | ||
href = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" | ||
rel = "stylesheet" | ||
crossorigin = "anonymous" | ||
integrity = "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" | ||
} | ||
link("/css/kotless-site.css", rel = "stylesheet") | ||
link("/css/highlight-style.css", rel = "stylesheet") | ||
script { src = "/js/highlight.pack.js" } | ||
script { | ||
src = "https://code.jquery.com/jquery-3.3.1.slim.min.js" | ||
crossorigin = "anonymous" | ||
integrity = "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" | ||
} | ||
script { | ||
src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" | ||
crossorigin = "anonymous" | ||
integrity = "sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" | ||
} | ||
script { | ||
src = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" | ||
crossorigin = "anonymous" | ||
integrity = "sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" | ||
} | ||
|
||
script(type = ScriptType.textJavaScript) { | ||
unsafe { | ||
raw("hljs.initHighlightingOnLoad();") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.jmfayard.bootstrap | ||
|
||
import io.ktor.http.content.file | ||
import io.ktor.http.content.files | ||
import io.ktor.http.content.static | ||
import io.ktor.http.content.staticRootFolder | ||
import io.ktor.routing.Routing | ||
import java.io.File | ||
|
||
|
||
fun Routing.siteStatics() { | ||
//There are used almost all possible definitions of static resources | ||
|
||
static { | ||
staticRootFolder = File("src/main/resources/static") | ||
|
||
static("css") { | ||
files("css") | ||
} | ||
|
||
static("js") { | ||
file("highlight.pack.js", "js/highlight.pack.js") | ||
} | ||
|
||
file("favicon.apng") | ||
} | ||
} |
Oops, something went wrong.