ngocdaothanh/xitrum-scalate — pull request #2 by caiiiycuk (2013-10-13 12:11:33+00:00)
Title: xitrum helper with concret class (get rid out of xitrum.Action)

Related to: https://github.com/ngocdaothanh/xitrum/issues/76
Discussion: http://groups.google.com/group/xitrum-framework/browse_thread/thread/912f4f81f88ba858

Changes in this pull request affects development mode of xitrum. In development mode all helpers of scalate templates will be concrete Action class not xitrum.Action. Also i look into xsbt-scalate-generate project to fit it into xitrum convention, and i found that it is extremely easy. I prepare the patch for it, i think xitrum team should fork this project patch and then publish it into sonatype repo (as xitrum-sbt-generate). After this we can get awesome templates where actions fields will be accessible directly, like in ruby and in my tests:

```scala
class MyAction extends Action {
def some() = "some"
}

Scalate.renderSspString("<%=some()%>")
```

Patch for xsbt-scalate-generate:

```patch
From 2b834dd9159168b136d3b65d4904303471d5b464 Mon Sep 17 00:00:00 2001
From: Aleksander Guryanov
Date: Sun, 13 Oct 2013 18:58:46 +0700
Subject: [PATCH] Make helper concrete class (get rid out of xitrum.Action)

---
generator/src/main/scala/Generator.scala | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/generator/src/main/scala/Generator.scala b/generator/src/main/scala/Generator.scala
index 7dcda57..0372393 100644
--- a/generator/src/main/scala/Generator.scala
+++ b/generator/src/main/scala/Generator.scala
@@ -61,14 +61,27 @@ class Generator {
paths collect {
case Updated(uri, templateFile, scalaFile) =>
val template = TemplateSource.fromFile(templateFile, uri)
-
- val code = engine.generateScala(template).source
+ val code = engine.generateScala(template, extraBindings(uri)).source
scalaFile.getParentFile.mkdirs
IOUtil.writeBinaryFile(scalaFile, code.getBytes("UTF-8"))
scalaFile
} toArray
}

+ def extraBindings(uri: String) = {
+ List(Binding("helper", uri2Class(uri), true))
+ }
+
+ def uri2Class(uri: String) = {
+ val aClass = uri.split('.')(0).replaceAll("/", ".")
+
+ if (aClass.startsWith(".")) {
+ aClass.substring(1)
+ } else {
+ aClass
+ }
+ }
+
object Updated {
def unapply(uri: String) = {
val templateFile = new File(sources, uri)
--
1.8.1.2
```