Share
Embed
Transcript
31 slides
-
Shintaro Katafuchi - Programmer at TIS - ID: hotchemi -
BLOG: hotchemi.hateblo.jp -
ຊࠓ͔ͨͬͨ͠ࣄ - Kara Web Frameworkʹ͍ͭͯ - RailsϥΠΫͳMVCϑϨʔϜϫʔΫ - DSL(kotlin)Ͱhtml͕ॻ͚Δ!!! -
DSL(kotlin)Ͱcss͕ॻ͚Δ!!! - https://github.com/TinyMission/kara -
- kotlin-script - εΫϦϓτݴޠϥΠΫʹkotlinΛ࣮ߦ͢Δ - https://github.com/andrewoma/kotlin-script $ kotlin mykotlinfile.kt -
aztec - kotlin-scriptΑΓߴػೳͬΆ͍ŊPython - ಈ͖·ͤΜͰͨ͠!! - https://github.com/kondratovich/aztec $ azs mykotlinfile.kt -
andrew@andrew-u100 ~/dev/euler $ az Aztec [https://github.com/kondratovich/aztec] Aztec is for compiling
Kotlin sources without setting your hair on fire. You can use `azs` to run Kotlin file like a script. Usage: az [options] available options: clean : clean output directory help : print help information compile : compile sources pack : compile sources and pack them to executable file upgrade : upgrade kotlin libraries upto last version list : print list of installed plugins version : show version jar : compile sources and pack them to jar -
object Home { val layout = DefaultLayout() Get("/") class Index()
: Request({ karademo.views.home.Index() }) Get("/test") class Test() : Request({ TextResult("This is a test action, yo") }) Post("/updatebook") class Update() : Request({ redirect("/forms") }) } Controller -
class DefaultStyles() : Stylesheet() { override fun render() { s("body")
{ backgroundColor = c("#f0f0f0") } s("#main") { width = 85.percent backgroundColor = c("#fff") margin = box(0.px, auto) padding = box(1.em) border = "1px solid #ccc" borderRadius = 5.px } s("input[type=text], textarea") { padding = box(4.px) width = 300.px } s("textarea") { height = 80.px } s("table.fields") { s("td") { padding = box(6.px, 3.px) } s("td.label") { textAlign = TextAlign.right } s("td.label.top") { verticalAlign = VerticalAlign.top } } } } DSL(CSS) -
package node.kt.examples.Render import node.express.Express /** * Example app showing rendering
of pages using different template engines */ fun main(args: Array<String>) { var app = Express() app["title"] = "My Kotlin App" // available in the template as settings.title app["view engine"] = "ftl" // sets the default template engine app.get("/velocity", { req, res, next -> res.render("render.vm", hashMapOf( "name" to "Jon Nichols" )); }) app.get("/freemarker", { req, res, next -> res.render("render", hashMapOf( "name" to "Jon Nichols" )); }) app.listen(4000) } node.kt -
- assertionϥΠϒϥϦͷΈΛఏڙ - expect.jsͷΠϯεύΠΞ - expect.jsαΠίʔο! - expectͱshouldͷ2௨ΓͷγϯλοΫε - υΩϡϝϯτॆ࣮͓ͯ͠Γ͓નΊ
- https://github.com/kouphax/expect.kt expect.kt -
expect("james").toBe("james") "james".should.be("james") expect("james").toStartWith("j").and.toEndWith("s") "james".should.startWith("j").and.endWith("s") expect("james").toNotBe("henry") expect(null).toBeNull() true.should.beTrue() expect("").toBeEmpty() expect(" ").toBeBlank()
expect("JAMES").toContain("AM") expect.kt -
1 should match condition {this > 0 && this <
2} //✔ object book { val title = "Title" val author = "Author" } book should match condition { title == "Title" } //✔ book should match condition { title == "Title" && author == "Author" } //✔ book should !match condition { title == "T" && author == "Author" } //✔ book should !match condition { title == "Title" && author == "Author" //✘ {throw NullPointerException()} should fail with NullPointerException() //✔ {1 should be equal 1} should !fail with AssertionError() //✔ {"string" should be equal "string"} should fail with AssertionError() //✘ mapOf(1 to "1", 2 to "2", 3 to "3") should contain key 1 //✔ mapOf(1 to 2, 2 to 3, 4 to 5) should contain key 2 //✔ mapOf(1 to 2, 2 to 3, 4 to 5) should contain key 3 //✘ katchers -
public class calculatorSpecs : JUnitSpec() {{ given("a calculator") { val
calculator = Calculator() on("calling sum with two numbers") { val sum = calculator.sum(2, 4) it("should return the result of adding the first number to the second number") { shouldEqual(6, sum) } } } }} spek -
ŋKlaxon - KotlinͷJSONύʔα - https://github.com/cbeust/klaxon ŋExposed - Kotlin SQL Framework
- ͪΐͬͱORMʹͳΓ͖Εͯͳ͍ײ͡ - https://github.com/cheptsov/Exposed -
fun main(args: Array<String>) { var db = Database("jdbc:h2:mem:test", driver =
"org.h2.Driver") db.withSession { create (Cities, Users) val saintPetersburgId = insert (Cities.values("St. Petersburg")) get Cities.id val munichId = insert (Cities.values("Munich")) get Cities.id insert (Cities.values("Prague")) insert (Users.values("andrey", "Andrey", saintPetersburgId)) insert (Users.values("sergey", "Sergey", munichId)) insert (Users.values("eugene", "Eugene", munichId)) insert (Users.values("alex", "Alex", null)) insert (Users.values("smth", "Something", null)) update (Users) { set(name("Alexey")) } where Users.id.equals("alex") delete (Users) where Users.name.like("%thing") println("All cities:") select (Cities.all) forEach { val (id, name) = it println("$id: $name") } } Exposed