Skip to content

Instantly share code, notes, and snippets.

@julienrf
julienrf / Application.java
Last active August 29, 2015 14:00
Content negotiation in Java with Play framework
package controllers;
import play.mvc.Controller;
import play.libs.Json;
import static controllers.Render.*;
import static play.mvc.Http.MimeTypes;
public class Application extends Controller {
@julienrf
julienrf / ws.scala
Last active August 29, 2015 14:04
Using the Play HTTP client without the hassle of starting a Play application
val client = new NingWSClient(new NingAsyncHttpClientConfigBuilder(DefaultWSClientConfig()).build())
client.url("…").get().foreach { response =>
client.close()
}
@julienrf
julienrf / bar.js
Created August 7, 2014 07:02
Dependency injection in JavaScript
/* A basic implementation of bar */
define(function () {
return {
plop: function () { alert('bar implementation'); }
}
});
@julienrf
julienrf / Controller.scala
Created July 5, 2015 08:08
Handling Etags with Play
def taggedResult(request: RequestHeader, tag: String)(result: => Result): Result =
request.headers.get(IF_NONE_MATCH) match {
case Some(t) if t == tag => NotModified
case _ => result.withHeaders(ETAG -> tag)
}
// Example of use:
val javascriptRoutes = {
val router =
JavaScriptReverseRouter("routes", None, hostname,
@julienrf
julienrf / glitter-sample.scala
Created April 11, 2011 21:06
Template sample using Glitter
// Import the Glitter DSL
import glitter._
object Templates {
// Define a reusable layout
def layout(body: Xml) =
html5dtd | 'html (
'head :: 'title :: "Glitter is amazing!"
| 'body :: body
@julienrf
julienrf / bigtable.scala
Created April 12, 2011 08:30
Bigtable template in Glitter
import glitter._
object Bigtable {
def template(table: Array[Array[Int]]) =
'table (
forM (table) (row =>
'tr :: forM (row) ('td :: _.toString)
)
)
}
@julienrf
julienrf / tyco_sample.scala
Created April 20, 2011 12:11
Is it possible to write more expressive things?
import tyco.compiler._
object MyWebsite extends tyco.Site {
for (page <- Content.allPages)
page.uri ==> Template.show(page)
for (file <- Path("stylesheets/*.scss"))
"/css/"+file.name ==> new TextFile(file) with Sass with CssMinifier
}
@julienrf
julienrf / 1_Max.scala
Created April 29, 2011 10:28
Scala typeclass pattern
/** Say we have a `max` function, computing the maximum of two numbers */
def max(a: Int, b: Int): Int = {
if (a < b) b
else a
}
/** It can be used like that: */
max(3, 4)

What do we want to do?

Find a way to easily allow industrial web applications developers to write consistent user interfaces without having to repeat themselves, and to efficiently handle variability.

The user interface is displayed by the web browser from the HTML of the page. Developers write the HTML markup using a template engine. This template engine allows to include parametrized fragments, giving the ability to define some UI traits (capturing one UI concept) and to reuse them across the application.

*{ Liste éditable d’éléments }*
*{ @param _arg: Iterable[A] Liste des éléments constitutifs de la liste }*
*{ @param as: String Name of the iterator }*
*{ @param (optional) addAction: ActionDefinition URL permettant d’ajouter un élément }*
*{ @param (optional) pager: Pager }*
#{ui.list users, as: 'user', addAction: @Users.add(), pager: pager}
#{useritem user /}
#{/ui.list}
*{ Formulaire }*