Permalink
Browse files

merged master code into the dev

  • Loading branch information...
florinpatrascu committed Feb 10, 2013
2 parents e1aa808 + de2ee6c commit 7fcf0a1f5ab8b9e51889f52142ea0c6d5677d40a
View
@@ -22,4 +22,5 @@ Using an extension is usually as simple as copying a folder and requiring a an e
### Extensions
- [Cache admin](https://github.com/florinpatrascu/micro-extensions/tree/master/cache_admin) - minimalistic admin interface for the Micro cache.
+ - [ST](https://github.com/florinpatrascu/micro-extensions/tree/master/st) - extend Micro with the [StringTemplate](http://www.stringtemplate.org/) template engine.
Binary file not shown.
View
2 st.yml
@@ -2,3 +2,5 @@ class: ca.simplegames.micro.extensions.STExtension
engine:
name: st
class: ca.simplegames.micro.viewers.st.STViewRenderer
+ # options:
+ # delimiters: "$$"
View
@@ -1,6 +1,6 @@
-## StringTemplate engine
+## The `StringTemplate` engine
-Extending Micro with support for StringTemplate rendering.
+This extension is adding the [StringTemplate](http://www.stringtemplate.org/) rendering support to Micro.
### Build from source
@@ -17,14 +17,27 @@ Copy (or create symbolic links) the `st` folder and `st.yml` file to your applic
├── st/
├── st.yml
└── ...
-
-Edit the `application.bsh` startup controller and required the `st` extension, example:
+
+The `st.yml` may contain various configuration options for the `StringTemplate` engine. Example of a config file switching the `StringTemplate` expression delimiters from the default: `<` and `>`, to: `$` and `$`:
+
+ class: ca.simplegames.micro.extensions.STExtension
+ engine:
+ name: st
+ class: ca.simplegames.micro.viewers.st.STViewRenderer
+ options:
+ delimiters: "$$"
+
+See [this link](http://www.antlr.org/wiki/display/ST/Setting+the+expression+delimiters) for more details.
+
+Edit the `application.bsh` startup controller and require the `st` extension, example:
site.ExtensionsManager
.require("i18N")
.require("st"); // <-- just added
+
+That's all. The `StringTemplate` engine will be automatically configured by this extension and made available to the entire application.
-restart the app and go to: `http://localhost:8080/cache`. The following interface will be shown:
+Restart the app and use your `StringTemplate` views.
### License
**Apache License 2**, see the `LICENSE` file in this folder.
View
Binary file not shown.
@@ -41,6 +41,8 @@
*/
public class STViewRenderer implements ViewRenderer {
public static final String NAME = "st";
+ private char delimiterStartChar = '<';
+ private char delimiterStopChar = '>';
@Override
public long render(String path, Repository repository, MicroContext context, Writer out) throws FileNotFoundException, ViewException {
@@ -49,7 +51,7 @@ public long render(String path, Repository repository, MicroContext context, Wri
try {
String source = repository.read(path);
- ST st = new ST(source);
+ ST st = new ST(source, delimiterStartChar, delimiterStopChar);
//todo: Think! Should I use: st.write( ...)??
if (!CollectionUtils.isEmpty(context.getMap())) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) context.getMap()).entrySet()) {
@@ -70,7 +72,16 @@ public long render(String path, Repository repository, MicroContext context, Wri
}
@Override
+ @SuppressWarnings("unchecked")
public void loadConfiguration(SiteContext site, Map<String, Object> configuration) throws Exception {
+ if (configuration != null) {
+ String delimiters = (String) configuration.get("delimiters");
+
+ if (delimiters != null && delimiters.length() > 0) {
+ delimiterStartChar = delimiters.charAt(0);
+ delimiterStopChar = delimiters.length() > 1 ? delimiters.charAt(1) : delimiterStartChar;
+ }
+ }
}
@Override

0 comments on commit 7fcf0a1

Please sign in to comment.