Created
September 6, 2010 06:01
-
-
Save takedasoft/566698 to your computer and use it in GitHub Desktop.
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
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Scalatra のすすめ | |
Scala + Sinatra = Scalatra | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
旧STEP -> Scalatra | |
「Scalatraってなんだよ。。」by @kmizu | |
Scala+Sinatra=Scatra? ・・スカトr・・ | |
「Scalatra」でいいんです、きっと。 | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Sinatraとは・・ | |
Rubyistに人気の | |
"超軽量"Webフレームワーク | |
Webフレームワークというより、 | |
ロジックにHTTPしゃべらせるためのライブラリ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Sinatraサンプル | |
require 'rubygems' | |
require 'sinatra' | |
get '/hi' do | |
"Hello World!" | |
end | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Scalatraサンプル | |
import org.scalatra._ | |
class MyServlet extends ScalatraServlet{ | |
get("/hi") { | |
<h1>Hello World!</h1> | |
} | |
} | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
①get( url )( func ) //宣言 | |
↓登録 | |
②Map( url -> func ) //URL->関数バインド | |
↑URL ↓関数 | |
③doGet(...//) //実行 | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Scalatraをおすすめする理由 | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
本体のソースコードが極めて短い | |
全部で550ステップ | |
もともとブログエントリで書ききっていた。 | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Scalaの基本的で素直な使い方がわかる | |
・implicit def | |
・Collection | |
・高階関数 | |
・カリー化 ..など | |
Scala入門の半歩先の | |
コードリーディングの題材として | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
超軽量! | |
GoogleAppEngine Friendly | |
Scalatra+Slim3とかいいのでは? | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Sinatra is Ready ! | |
Ruby会議2010でみたセッション | |
他のツールと組みあわせやすい | |
プラグインが整ってきた | |
Scalatra will be Ready too ! | |
挑戦しやすい(かも) | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
生Servlet書くよりは | |
断然ラクじゃね? | |
・web.xmlに登録するのは1つ | |
・before/after-filter | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
テンプレートエンジンScalate | |
と組み合わせる | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
import org.scalatra._ | |
import scalate.ScalateSupport | |
class MyServlet extends ScalatraServlet | |
with ScalateSupport { | |
before {contentType = "text/html"} | |
get("/hackers") { | |
val data = Seq( | |
Map("name"->"keisuke_n","site"->"http://cappuccino.jp/keisuken/logbook/"), | |
Map("name"->"kmizu","site"->"http://d.hatena.ne.jp/kmizushima/"), | |
Map("name"->"yuroyoro","site"->"http://d.hatena.ne.jp/yuroyoro/") | |
) | |
templateEngine.layout( | |
"/WEB-INF/hackers.mustache", | |
Map( "list" -> data )) | |
} | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
<ul> | |
{{#list}} | |
<li> | |
<font color="blue">{{name}}</font>: | |
<font color="gray"> | |
<a href="{{site}}">{{site}}</a> | |
</font> | |
</li> | |
{{/list}} | |
</ul> | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
めちゃかんたん | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
大規模に向かない???? | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
trait App extends ScalatraServlet | |
with ScalateSupport { | |
before {contentType = "text/html"} | |
} | |
trait ProductApp extends App{ | |
get("/product"){ } | |
} | |
trait UserApp extends App{ | |
get("/user"){ } | |
} | |
class MyServlet | |
extends ProductApp | |
with UserApp | |
Mix-inがあるじゃないかっ | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
simple-build-toolsで動かすサンプル | |
> git clone git://github.com/takedasoft/ScalatraExample.git | |
> cd ScalatraExample | |
> sbt | |
> update | |
> ~jetty-restart | |
※ ~ つけるとソース修正時に自動再起動 | |
■■■■■■■■■■■■■■■■■■■■■■■ | |
Scalatra is nice | |
ご清聴ありがとうございました。 | |
■■■■■■■■■■■■■■■■■■■■■■■ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment