Slide 1

Slide 1 text

#jkug 01 Kotlin Repositories @hotchemi

Slide 2

Slide 2 text

Shintaro Katafuchi - Programmer at TIS - ID: hotchemi - BLOG: hotchemi.hateblo.jp

Slide 3

Slide 3 text

- Kotlinྺ1िؒ͘Β͍ͷϑϨογϡϚϯͰ͢!!! - ॳ৺ऀ࿮ͰͷൃදͱͳΓ·͢ - ීஈ͸Nodeͱ͔Pythonͱ͔δϟόॻ͍ͯ·͢

Slide 4

Slide 4 text

࠷ߴͷ#jkugʹ͠Α͏΍

Slide 5

Slide 5 text

ຊ౰͸ࠓ೔࿩͔ͨͬͨ͠ࣄ - Kara Web Frameworkʹ͍ͭͯ - RailsϥΠΫͳMVCϑϨʔϜϫʔΫ - DSL(kotlin)Ͱhtml͕ॻ͚Δ!!! - DSL(kotlin)Ͱcss͕ॻ͚Δ!!! - https://github.com/TinyMission/kara

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

ԿͷϏϧυ΋!! ௨ͤ·ͤΜͰͨ͠!! Build ServerݟͨΒίϯύΠϧΤϥʔు͍ͯΔ…

Slide 8

Slide 8 text

ֶΜͩࣄ - GitHubͷKotlinϓϩδΣΫτ͸େମಈ͔ͳ͍ - ࠷ऴίϛοτ͕൒೥લͩͱେମಈ͔ͳ͍ - ։ൃऀ͕KotlinͷਐԽʹ͍͍͚ͭͯͯͳ͍ - ಈ͔͵΋·ͨҰڵŊ ༏խͳؾ࣋ͪΛ

Slide 9

Slide 9 text

࢓ํͳ͍ͷͰGitHubͷϥΠϒϥϦΛړͬͯŊΤίγεςϜͷ঺հͳͲ͠·͢… ※Android͸ੌ͍ਓ͕஻ͬͯ͘ΕΔͷͰল͖·ͨ͠

Slide 10

Slide 10 text

Editor

Slide 11

Slide 11 text

- kotlin-vim https://github.com/ignatov/kotlin-vim - Sublime Text https://github.com/vkostyukov/kotlin-sublime-package - TextMate https://github.com/k33g/kotlin-textmate-bundle IntelliJҎ֎ʹ΋͋ΔΑ

Slide 12

Slide 12 text

CLI

Slide 13

Slide 13 text

- kotlin-script - εΫϦϓτݴޠϥΠΫʹkotlinΛ࣮ߦ͢Δ - https://github.com/andrewoma/kotlin-script $ kotlin mykotlinfile.kt - aztec - kotlin-scriptΑΓߴػೳͬΆ͍ŊPython੡ - ಈ͖·ͤΜͰͨ͠!! - https://github.com/kondratovich/aztec $ azs mykotlinfile.kt

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Web Application Framework

Slide 16

Slide 16 text

- RailsϥΠΫͳMVCϑϨʔϜϫʔΫ - DSL(kotlin)Ͱhtml͕ॻ͚Δ!!! - DSL(kotlin)Ͱcss͕ॻ͚Δ!!! - https://github.com/TinyMission/kara Kara Web Framework

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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)

Slide 19

Slide 19 text

- NodeʹΠϯεύΠΞ͞ΕͨWAF - ߏจ͸expressϥΠΫ - https://github.com/jonninja/node.kt node.kt

Slide 20

Slide 20 text

package node.kt.examples.Render import node.express.Express /** * Example app showing rendering of pages using different template engines */ fun main(args: Array) { 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

Slide 21

Slide 21 text

Testing Framework

Slide 22

Slide 22 text

- assertionϥΠϒϥϦͷΈΛఏڙ - expect.jsͷΠϯεύΠΞ - expect.jsαΠίʔο! - expectͱshouldͷ2௨ΓͷγϯλοΫε - υΩϡϝϯτ΋ॆ࣮͓ͯ͠Γ͓નΊ - https://github.com/kouphax/expect.kt expect.kt

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

- DSLͰॻ͚ΔΞαʔγϣϯϥΠϒϥϦ - should/mustͷ2௨Γͷߏจ - https://github.com/danseid/katchers katchers

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

- BDDελΠϧ - JUnit 4.xͷςετϥϯφʔͰಈ͔ͤΔ - https://github.com/hhariri/spek spek

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Others

Slide 29

Slide 29 text

ŋKlaxon - KotlinͷJSONύʔα - https://github.com/cbeust/klaxon ŋExposed - Kotlin SQL Framework - ͪΐͬͱORMʹͳΓ͖Εͯͳ͍ײ͡ - https://github.com/cheptsov/Exposed

Slide 30

Slide 30 text

fun main(args: Array) { 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

Slide 31

Slide 31 text

·ͱΊ - KotlinϓϩδΣΫτେମಈ͔ͳ͍ʂ - vimͱ͔Sublime TextͰ΋Kotlinॻ͚Δʂ - Testig Framework͸expect.kt(js)͕͓નΊʂ - ಈ͔͵΋·ͨҰڵŊ༏խͳؾ࣋ͪΛ