incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r590035 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/scripting/engines/freemarker/ main/webapp/ test/java/org/apache/sling/microsling/integration/ test/resources/integration-test/
Date Tue, 30 Oct 2007 11:14:38 GMT
Author: bdelacretaz
Date: Tue Oct 30 04:14:37 2007
New Revision: 590035

URL: http://svn.apache.org/viewvc?rev=590035&view=rev
Log:
SLING-87 - Freemarker Scripting Support, example and integration tests added

Added:
    incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html   (with
props)
    incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.ftl
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
    incubator/sling/whiteboard/microsling/src/main/webapp/index.html
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java?rev=590035&r1=590034&r2=590035&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
Tue Oct 30 04:14:37 2007
@@ -30,7 +30,7 @@
 import java.util.Map;
 
 /**
- * A ScriptEngine that uses {@link http://freemarker.org/ Freemarker}
+ * A ScriptEngine that uses {@link http://freemarker.org/ FreeMarker}
  * templates to render a Resource in HTML.
  */
 public class FreemarkerScriptEngine implements ScriptEngine {
@@ -54,7 +54,7 @@
         if (!"GET".equals(request.getMethod())) {
             throw new HttpStatusCodeException(
                 HttpServletResponse.SC_METHOD_NOT_ALLOWED,
-                "Freemarker templates only support GET requests");
+                "FreeMarker templates only support GET requests");
         }
 
         Template tmpl = new Template(scriptName, script, configuration);
@@ -65,7 +65,7 @@
         } catch (IOException ioe) {
             throw ioe;
         } catch (Throwable t) {
-            throw new SlingException("Failure running Freemarker script " + scriptName, t);
+            throw new SlingException("Failure running FreeMarker script " + scriptName, t);
         }
     }
 }

Added: incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html?rev=590035&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html (added)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html Tue Oct
30 04:14:37 2007
@@ -0,0 +1,38 @@
+<html>
+<head>
+  <title>microsling FreeMarker templates</title>
+  <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+  <h1>microsling FreeMarker templates</h1>
+  
+  <div class="note">
+    <a href="../">back to homepage</a>
+  </div>
+  <p> 
+  	Scripts found by the <code>SlingScriptResolver</code> using the <code>.ftl</code>
extension are executed by
+    the <code>FreemarkerScriptEngine</code>.
+  </p>
+  <p>
+    This works exactly like the <a href="velocity-scripts.html">Velocity templates</a>,
except that
+    templates use the FreeMarker syntax.
+  </p>
+  <p>
+    Here's an example HTML template. See the <a href="http://freemarker.org">FreeMarker</a>
website 
+    more info about the syntax.
+    <pre>&lt;html>
+&lt;body>
+&lt;h1>This is generated from a FreeMarker template&lt;/h1>
+&lt;p>
+  The current resource URI is &lt;b>${resource.URI}&lt;/b>
+&lt;/p>
+
+&lt;h2>${resource.getItem().getProperty("title").getString()}&lt;/h2>
+&lt;p>
+  ${resource.getItem().getProperty("text").getString()}
+&lt;/p>
+
+&lt;/body></pre>  
+  </p>
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/index.html?rev=590035&r1=590034&r2=590035&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/index.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/index.html Tue Oct 30 04:14:37 2007
@@ -35,6 +35,11 @@
         Server-side javascript and ESP templates
       </a>: explains how to use server-side javascript and javascript-based ESP templates
to process requests.
     </li>
+    <li>
+      <a href="freemarker-scripts.html">
+        FreeMarker templates
+      </a>: explains how to use FreeMarker templates to render content.
+    </li>
   </ul>
   
   <h2>Show me the code</h2>

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=590035&r1=590034&r2=590035&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
Tue Oct 30 04:14:37 2007
@@ -103,4 +103,15 @@
             testClient.delete(toDelete);
         }
     }
+    
+    public void testFtlHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker
template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><span>"
+ testText + "</span></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
 }

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=590035&r1=590034&r2=590035&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
Tue Oct 30 04:14:37 2007
@@ -107,4 +107,15 @@
             testClient.delete(toDelete);
         }
     }
+    
+    public void testFtlHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker
template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><span>"
+ testText + "</span></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
 }

Added: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.ftl
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.ftl?rev=590035&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.ftl
(added)
+++ incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.ftl
Tue Oct 30 04:14:37 2007
@@ -0,0 +1,7 @@
+<%-- used by ScriptedRenderingTest --%>
+<html>
+	<body>
+		FreeMarker template
+		<p><span>${resource.getItem().getProperty("text").getString()}</span></p>
+	</body>
+</html>



Mime
View raw message