Permalink
Browse files

updated to work with play 2.0.3, with smart importing

  • Loading branch information...
1 parent d3e79e1 commit 3816b97c0aae9066c838b96c91b042cd8415e0c6 @branaway committed Aug 6, 2012
View
@@ -53,7 +53,7 @@ h2. Build the module from source
Note:
-- I'm using sbt 0.11.2 locally. Match the sbt version in the "project/build.properties" file to yours .
+- I'm using sbt 0.11.3 locally. Match the sbt version in the "project/build.properties" file to yours .
- Also check and match the sbt-plugin version in the "project/plugins.sbt" file to your local version.
@@ -136,5 +136,8 @@ h2. History
1. added JapidRenderer.setLogVerbose() to control logging verbosity of Japid activities.
2012.7.28: v0.2.2
1. updated the README and fixed the initialization part.
+2012.7.28: v0.3
+ 1. bug fix: import of empty _tags or _layouts caused compiler error. Now imports those packages only if there are any templates in the folders.
+ 2. enhancement: updated build files to work with play-2.0.3 release.
@@ -519,9 +519,10 @@ static void delAllGeneratedJava(String pathname) {
File rootDir = new File(root);
t.setPackageRoot(rootDir);
t.setInclude(new File(japidviews));
- t.addImport("japidviews ._layouts.*");
- // t.addImport(root + "/" + "._javatags.*");
- t.addImport("japidviews ._tags.*");
+ if (DirUtil.hasLayouts(root))
+ t.addImport("japidviews._layouts.*");
+ if (DirUtil.hasTags(root))
+ t.addImport("japidviews._tags.*");
t.addImport("controllers.*");
t.addImport("models.*");
t.addImport("play.data.validation.Validation");
@@ -227,4 +227,41 @@ public static void writeStringToFile(File file, String content) throws IOExcepti
public static void touch(File newer) throws IOException {
writeStringToFile(newer, "");
}
+
+ public static boolean hasTags(String root) {
+ String dirName = DirUtil.TAGSDIR;
+ return containsTemplateFiles(root, dirName);
+ }
+
+
+ public static boolean hasLayouts(String root) {
+ String dirName = DirUtil.LAYOUTDIR;
+ return containsTemplateFiles(root, dirName);
+ }
+
+
+ public static boolean containsTemplateFiles(String root, String dirName) {
+ String sep = File.separator;
+ String japidViews = root + sep + JAPIDVIEWS_ROOT + sep;
+ String dir = japidViews + dirName;
+ return containsTemplatesInDir(dir);
+ }
+
+ public static boolean containsTemplatesInDir(String dirName) {
+ File dir = new File(dirName);
+
+ if (dir.exists()) {
+ String[] temps = getAllFileNames(dir, new String[]{".html", ".js", ".txt", ".css", ".xml", ".json"});
+ if (temps.length > 0)
+ return true;
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+
+ public static final String LAYOUTDIR = "_layouts";
+ public static final String TAGSDIR = "_tags";
+ public static final String JAPIDVIEWS_ROOT = "japidviews";
}
View
@@ -5,7 +5,7 @@ import PlayProject._
object ApplicationBuild extends Build {
val appName = "japid42"
- val appVersion = "0.2.2"
+ val appVersion = "0.3"
val appDependencies = Seq(
"org.apache.commons" % "commons-email" % "1.2"
View
@@ -1 +1 @@
-sbt.version=0.11.2
+sbt.version=0.11.3
View
@@ -5,4 +5,4 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
-addSbtPlugin("play" % "sbt-plugin" % "2.0-SNAPSHOT")
+addSbtPlugin("play" % "sbt-plugin" % "2.0.3")

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,25 +1,12 @@
-<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>JapidSample42</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.scala-ide.sdt.core.scalabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.scala-ide.sdt.core.scalanature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
- <linkedResources>
- <link>
- <name>japidviews</name>
- <type>2</type>
- <locationURI>PROJECT_LOC/app/japidviews</locationURI>
- </link>
- </linkedResources>
-</projectDescription>
+ <name>JapidSample42</name>
+ <buildSpec>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -1,5 +1,5 @@
#Generated by sbteclipse
-#Sun Mar 25 10:20:12 CST 2012
+#Wed Apr 04 12:49:49 CST 2012
Xcheckinit=true
deprecation=true
encoding=utf8
@@ -14,8 +14,9 @@
@Override
public void onStart(Application app) {
// JapidRenderer.setParentClassLoader(app.classloader());
- JapidRenderer.init(Play.isDev()? OpMode.dev: OpMode.prod, "japidroot", 3, app);
+ JapidRenderer.init(app.isDev() ? OpMode.dev : OpMode.prod, "japidroot", 3, app);
JapidRenderer.addImportStatic(StringUtils.class);
+ JapidRenderer.setLogVerbose(true);
JapidRenderer.gen();
}
@@ -61,8 +61,8 @@
raw expression with ${} and html-safe expression with ~{}
`
</li>
- <li><a href="more.ContentNegotiation/index"> content
- negotiation.</a> Use tools like CURL to test it: <pre>curl -i -H "Accept: application/json" http://127.0.0.1:9000/more.ContentNegotiation/index</pre>
+ <li><a href="more.ContentNegotiation/index">content
+ negotiation. Not quite working yet.</a> Use tools like CURL to test it: <pre>curl -i -H "Accept: application/json" http://127.0.0.1:9000/more.ContentNegotiation/index</pre>
<p>Content negotiation works with renderJapid(), which does
implicit parameter binding and template picking.</p>
<p>For more doc: see <a
@@ -133,8 +133,8 @@ public index(StringBuilder out) {
" raw expression with ${} and html-safe expression with ~{}\n" +
" ");// line 60
p(" </li>\n" +
-" <li><a href=\"more.ContentNegotiation/index\"> content\n" +
-" negotiation.</a> Use tools like CURL to test it: <pre>curl -i -H \"Accept: application/json\" http://127.0.0.1:9000/more.ContentNegotiation/index</pre>\n" +
+" <li><a href=\"more.ContentNegotiation/index\">content\n" +
+" negotiation. Not quite working yet.</a> Use tools like CURL to test it: <pre>curl -i -H \"Accept: application/json\" http://127.0.0.1:9000/more.ContentNegotiation/index</pre>\n" +
" <p>Content negotiation works with renderJapid(), which does\n" +
" implicit parameter binding and template picking.</p>\n" +
" <p>For more doc: see <a\n" +
@@ -6,18 +6,21 @@
*{
}*
+first define something in a Java code block.
+
+` List<String> strings = new ArrayList<String>(){{add("u");add("m");add("everyone");}};
+
+`t aTag(strings)
+
+again: `t aTag(strings)
+
`tag picka("a", "b" + "c") | String r
the tag chosed: $r
<p>and we can call a tag recursively?</p>
`tag SampleTag(r)
<p>yes we can!</p>
`
-first define something in a Java code block.
-
-` List<String> strings = new ArrayList<String>(){{add("u");add("m");add("everyone");}};
-
-`t aTag(strings)
note: the picka tag is defined in the japidviews/_tags directory
</p>
@@ -82,18 +82,29 @@ public callPicka(StringBuilder out) {
"\n" +
"Another simple tag aTag, which locates in the same directory as this template:\n" +
"\n");// line 1
- p("\n");// line 8
- final picka _picka0 = new picka(getOut()); _picka0.setActionRunners(getActionRunners()).setOut(getOut()); _picka0.render(// line 9
-"a", "b" + "c", new picka.DoBody<String>(){ // line 9
-public void render(final String r) { // line 9
-// line 9
- p(" the tag chosed: ");// line 9
- p(r);// line 10
+ p("\n" +
+"first define something in a Java code block. \n" +
+"\n");// line 8
+ List<String> strings = new ArrayList<String>(){{add("u");add("m");add("everyone");}};// line 11
+ p("\n");// line 11
+ final aTag _aTag0 = new aTag(getOut()); _aTag0.setActionRunners(getActionRunners()).setOut(getOut()); _aTag0.render(strings); // line 13// line 13
+ p("\n" +
+"again: ");// line 13
+ final aTag _aTag1 = new aTag(getOut()); _aTag1.setActionRunners(getActionRunners()).setOut(getOut()); _aTag1.render(strings); // line 15// line 15
+ p("\n" +
+"\n" +
+"\n");// line 15
+ final picka _picka2 = new picka(getOut()); _picka2.setActionRunners(getActionRunners()).setOut(getOut()); _picka2.render(// line 19
+"a", "b" + "c", new picka.DoBody<String>(){ // line 19
+public void render(final String r) { // line 19
+// line 19
+ p(" the tag chosed: ");// line 19
+ p(r);// line 20
p("\n" +
" <p>and we can call a tag recursively?</p>\n" +
-" ");// line 10
- final SampleTag _SampleTag1 = new SampleTag(getOut()); _SampleTag1.setActionRunners(getActionRunners()).setOut(getOut()); _SampleTag1.render(r); // line 12// line 12
- p(" <p>yes we can!</p>\n");// line 12
+" ");// line 20
+ final SampleTag _SampleTag3 = new SampleTag(getOut()); _SampleTag3.setActionRunners(getActionRunners()).setOut(getOut()); _SampleTag3.render(r); // line 22// line 22
+ p(" <p>yes we can!</p>\n");// line 22
}
@@ -110,37 +121,32 @@ public void resetBuffer() {
}
}
-);// line 9
- p("\n" +
-"first define something in a Java code block. \n" +
-"\n");// line 14
- List<String> strings = new ArrayList<String>(){{add("u");add("m");add("everyone");}};// line 18
- p("\n");// line 18
- final aTag _aTag2 = new aTag(getOut()); _aTag2.setActionRunners(getActionRunners()).setOut(getOut()); _aTag2.render(strings); // line 20// line 20
+);// line 19
p("\n" +
+"\n" +
"note: the picka tag is defined in the japidviews/_tags directory\n" +
"</p>\n" +
"\n" +
"<p>\n" +
"we can call without the body part:\n" +
-"\n");// line 20
- final picka _picka3 = new picka(getOut()); _picka3.setActionRunners(getActionRunners()).setOut(getOut()); _picka3.render("cc","dd"); // line 28// line 28
+"\n");// line 24
+ final picka _picka4 = new picka(getOut()); _picka4.setActionRunners(getActionRunners()).setOut(getOut()); _picka4.render("cc","dd"); // line 33// line 33
p("\n" +
"or with named args\n" +
-"\n");// line 28
- final picka _picka4 = new picka(getOut()); _picka4.setActionRunners(getActionRunners()).setOut(getOut()); _picka4.render(named("a", "aa"), named("b", "bb")); // line 32// line 32
+"\n");// line 33
+ final picka _picka5 = new picka(getOut()); _picka5.setActionRunners(getActionRunners()).setOut(getOut()); _picka5.render(named("a", "aa"), named("b", "bb")); // line 37// line 37
p("\n" +
"</p>\n" +
"<p>\n" +
"Or using the full path of the tag starting with japidview\n" +
"</p>\n" +
-"\n");// line 32
- final japidviews.templates.aTag _japidviews_templates_aTag5 = new japidviews.templates.aTag(getOut()); _japidviews_templates_aTag5.setActionRunners(getActionRunners()).setOut(getOut()); _japidviews_templates_aTag5.render(strings); // line 39// line 39
+"\n");// line 37
+ final japidviews.templates.aTag _japidviews_templates_aTag6 = new japidviews.templates.aTag(getOut()); _japidviews_templates_aTag6.setActionRunners(getActionRunners()).setOut(getOut()); _japidviews_templates_aTag6.render(strings); // line 44// line 44
p("\n" +
"<p>You can use \".\" instead of \"/\" on the path:</p>\n" +
-"\n");// line 39
- final japidviews.templates.aTag _japidviews_templates_aTag6 = new japidviews.templates.aTag(getOut()); _japidviews_templates_aTag6.setActionRunners(getActionRunners()).setOut(getOut()); _japidviews_templates_aTag6.render(strings); // line 43// line 43
- ;// line 43
+"\n");// line 44
+ final japidviews.templates.aTag _japidviews_templates_aTag7 = new japidviews.templates.aTag(getOut()); _japidviews_templates_aTag7.setActionRunners(getActionRunners()).setOut(getOut()); _japidviews_templates_aTag7.render(strings); // line 48// line 48
+ ;// line 48
endDoLayout(sourceTemplate);
}
@@ -9,7 +9,7 @@ object ApplicationBuild extends Build {
val appDependencies = Seq(
// Add your project dependencies here,
- "japid42" % "japid42_2.9.1" % "0.2"
+ "japid42" % "japid42_2.9.1" % "0.2.1"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(

0 comments on commit 3816b97

Please sign in to comment.