Skip to content

Instantly share code, notes, and snippets.

View jstrachan's full-sized avatar

James Strachan jstrachan

View GitHub Profile
-@ import val it: Console
- import scala.collection.JavaConversions._
%h2 Scalate Console
%ul
- for (template <- templates)
%li
- val templateFile = servletContext.getRealPath(template)
%a(href="txmt://open/?url=file:" + templateFile)
The ssp code...
$_scalate_$_context << someLayout {
$_scalate_$_context << ( "\nthis is some body!\n" );
}
$_scalate_$_context << ( "\n" );
scaml code...
$_scalate_$_context << ( $_scalate_$_indent ( "", $_scalate_$_context.value ( someLayout {
scala> def foo(body: => Unit) { println("start"); body; println("end") }
foo: (body: => Unit)Unit
scala> foo { println("hey"); println("bar") }
start
hey
bar
end
scala> def bar(body:() => String) { println("start"); body(); println("end") }
bar: (body: () => String)Unit
scala> implicit def body(body: => Unit): () => String = () => { println("capturing"); body; "answer" }
body: (body: => Unit)() => String
scala> bar { println("hey"); println("bar") }
hey
start
capturing
scala> def tag(body:() => String) { println("start"); println("body = " + body()); println("end") }
tag: (body: () => String)Unit
scala> implicit def blockToStringFunction(body: () => Unit): () => String = () => { println("capturing"); body(); "answer" }
blockToStringFunction: (body: () => Unit)() => String
scala> tag { println("line1"); println("line2") }
<console>:7: error: type mismatch;
found : Unit
required: () => String
scala> def b = {println("foo"); println("bar")}
b: Unit
scala> b
foo
bar
scala> tag(b)
start
capturing
scala> def cheese(body: => Unit) { println("start"); body; println("end") }
cheese: (body: => Unit)Unit
scala> cheese { println("1"); println("2") }
start
1
2
end
def tag(context: RenderContext)(body: => Unit) = {
val text = context.capture(body)
context << ("<h3>Wrapped body</h3><p>" + text + "</p><h3>End of wrapped body</h3>")
}
-@ var body: String
-@ var title : String = "Scalate Sample"
- response.setContentType("text/html")
!!! Basic
%html(lang="en")
%head
%meta(http-equiv="Content-Type" content="text/html; charset=utf-8")
%meta(name="description" content="description goes here")
%meta(name="keywords" content="keywords,goes,here")
%meta(name="author" content="Your Name")
<div class="line error">
<span class="lineNumber">
7
</span>
<pre> - for (i &lt;- <span class="errorCol">u</span>nknown)</pre>
</div>