Permalink
Browse files

adding ability to import in slimmed down app

  • Loading branch information...
1 parent 45fba41 commit 5537346ecf09ce9449281dc90970c4f83731a6e0 @jacobrogers jacobrogers committed Mar 10, 2011
Showing with 25 additions and 13 deletions.
  1. +1 −1 build.gradle
  2. +15 −5 ratpack
  3. +4 −2 sample/sample.groovy
  4. +5 −5 src/main/groovy/com/bleedingwolf/ratpack/RatpackApp.groovy
View
@@ -8,7 +8,7 @@ repositories {
}
dependencies {
- groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.6'
+ groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.9'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'org.json', name: 'json', version: '20090211'
View
20 ratpack
@@ -1,11 +1,21 @@
#!/usr/bin/env groovy
-import com.bleedingwolf.ratpack.Ratpack
+import groovy.lang.Binding
+import groovy.util.GroovyScriptEngine
import com.bleedingwolf.ratpack.RatpackServlet
+import com.bleedingwolf.ratpack.RatpackApp
-def appScript = new File(args[0]).text
-def appClosure = new GroovyShell().evaluate("def webapp = { ${appScript} }; return webapp ")
+def scriptFile = new File(args[0])
-def app = Ratpack.app(appClosure)
+GroovyScriptEngine gse = new GroovyScriptEngine(scriptFile.parentFile.canonicalPath)
+Binding binding = new Binding()
-RatpackServlet.serve(app)
+RatpackApp ratpack = new RatpackApp()
+binding.setVariable('get', ratpack.get)
+binding.setVariable('post', ratpack.post)
+binding.setVariable('put', ratpack.put)
+binding.setVariable('delete', ratpack.delete)
+binding.setVariable('set', ratpack.set)
+gse.run scriptFile.name, binding
+
+RatpackServlet.serve(ratpack)
View
@@ -1,4 +1,6 @@
-setPort 4999
+import java.text.SimpleDateFormat
+
+set 'port', 4999
get("/") {
def ua = headers['user-agent']
@@ -11,4 +13,4 @@ get("/foo/:name") {
get("/person/:id") {
"Person #${urlparams.id}"
-}
+}
@@ -13,7 +13,7 @@ class RatpackApp {
def config = [:]
- void set(setting, value) {
+ def set = { setting, value ->
config[setting] = value
}
@@ -42,19 +42,19 @@ class RatpackApp {
return handlers[method.toUpperCase()].route(subject)
}
- void get(path, handler) {
+ def get = { path, handler ->
register('GET', path, handler)
}
- void post(path, handler) {
+ def post = { path, handler ->
register('POST', path, handler)
}
- void put(path, handler) {
+ def put = { path, handler ->
register('PUT', path, handler)
}
- void delete(path, handler) {
+ def delete = { path, handler ->
register('DELETE', path, handler)
}

0 comments on commit 5537346

Please sign in to comment.