Skip to content

Instantly share code, notes, and snippets.

View guillaumebort's full-sized avatar

Guillaume Bort guillaumebort

View GitHub Profile
@guillaumebort
guillaumebort / gist:1894297
Created February 23, 2012 18:48
Play scala templates
{ scopeName = 'text.html.scala';
fileTypes = ( 'scala.html' );
foldingStartMarker = '(?x)
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?>
|<!--(?!.*-->)
|\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
)';
foldingStopMarker = '(?x)
(</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)>
|^\s*-->
public static class ManagedDatasource {
final BoneCPDataSource ds;
final String url;
public ManagedDatasource(BoneCPDataSource ds, String url) {
this.ds = ds;
this.url = url;
}
package models;
import java.util.*;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
@Entity
@guillaumebort
guillaumebort / gist:1207364
Created September 9, 2011 21:18
Compiling Play 2.0 type safe templates
val ScalaTemplates = (sourceDirectory:File, generatedDir:File, templateTypes:Function1[String,(String,String)], additionalImports:String) => {
import play.templates._
(generatedDir ** "*.template.scala").get.map(GeneratedSource(_)).foreach(_.sync())
try {
(sourceDirectory ** "*.scala.html").get.foreach { template =>
ScalaTemplateCompiler.compile(template, sourceDirectory, generatedDir, templateTypes("html")._1, templateTypes("html")._2, additionalImports)
}
} catch {
case TemplateCompilationError(source, message, line, column) => {
@guillaumebort
guillaumebort / gist:1203802
Created September 8, 2011 16:19
Sample Play template used from Java
@(user:models.User, accounts:java.util.List[models.Account])
<h1>User @user.name has @accounts.size @("account".pluralize(accounts))</h1>
@for(account <- accounts) {
<h2>Account @accounts.number</h2>
@if(account.messages.isEmpty) {
<p>No messages for this account.</p>
@guillaumebort
guillaumebort / test.scala
Created August 31, 2011 19:38
Scalate in Play 1.2.3
package controllers {
import play._
import play.mvc._
object Scalate {
import java.io._
import org.fusesource.scalate._
object Orientations {
type Orientation = Char
val N = 'N'
val E = 'E'
val W = 'W'
val S = 'S'
val clockWise = List(N,E,S,W)
def next[A](elements:List[A],e:A):Option[A]= elements.drop(elements.indexOf(e)+1).firstOption
// prime number generator
for (i <- 2 to 1000)
if((2 to i).find( j=> (i % j == 0 && i != j) ) == None)
println(i)
// function currying example
def matcher(haystack: List[Char])(needle: String) = {
haystack contains needle.charAt(0)
}
@guillaumebort
guillaumebort / gist:877428
Created March 19, 2011 11:56
For play.libs.F ?
package scrapbook;
import java.lang.reflect.InvocationTargetException;
public class Test {
public static void main(String[] args) {
// Standard function
Function<String,String> toUpperCase = new Function<String,String>() {{ b = a.toUpperCase(); }};
@guillaumebort
guillaumebort / gist:768364
Created January 6, 2011 19:05
play dependencies
~/Desktop/scrapbook/coco $ play dependencies
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.1-localbuild, http://www.playframework.org
~ framework ID is gbo
~