Permalink
Browse files

Implemented final leg of pluggable templates, there were a few spots …

…where things were still hardcoded or difficult to configure outside Sitebricks. Also rewrote the logic for TemplateLoader to be easier to follow, more intuitive, quicker to return when templates are explicitly set, and more deterministic (will no longer attempt to load the default template if Show is explicitly set and the expected template could not be found).
  • Loading branch information...
1 parent f454f0d commit 9b8345be239dde4e235cd8a0fbb3cc8b36ab2abc @impressiver impressiver committed May 2, 2012
View
@@ -9,6 +9,7 @@ out/
*.ipr
*.iws
*.iml
+atlassian-ide-plugin.xml
# Eclipse
.classpath
View
@@ -1,7 +1,7 @@
repositories << "http://scala-tools.org/repo-releases/"
project "Sitebricks :: Parent" @ "https://github.com/dhanji/sitebricks"
- id: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT
+ id: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT
inherit: org.sonatype.oss:oss-parent:6
packaging: pom
@@ -1,8 +1,8 @@
repositories << "http://nexus.openqa.org/content/repositories/releases,http://repository.codehaus.org"
project "Sitebricks :: Acceptance Tests" @ "null"
- id: com.google.sitebricks:sitebricks-acceptance-tests:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-acceptance-tests:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
overrides: [ org.slf4j:slf4j-api:1.6.1 ]
@@ -1,6 +1,6 @@
project "Sitebricks :: Client" @ "null"
- id: com.google.sitebricks:sitebricks-client:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-client:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ org.testng:testng:${org.testng.version}(jdk15)
@@ -1,6 +1,6 @@
project "Sitebricks :: Type Conversion" @ "null"
- id: com.google.sitebricks:sitebricks-converter:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-converter:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ org.testng:testng:${org.testng.version}(jdk15)
@@ -1,10 +1,10 @@
Manifest-Version: 1.0
-Export-Package: org.sitebricks.client.easy;version="0.8.6.SNAPSHOT";
+Export-Package: org.sitebricks.client.easy;version="0.8.7.SNAPSHOT";
uses:="com.google.inject.binder,
com.google.inject.util,
org.sonatype.sisu.sitebricks.client.internal,
com.google.inject",
- org.sitebricks.client.easy.internal;version="0.8.6.SNAPSHOT";
+ org.sitebricks.client.easy.internal;version="0.8.7.SNAPSHOT";
uses:="com.google.sitebricks.client,
com.google.sitebricks.http,
com.google.sitebricks.client.transport,
@@ -17,7 +17,7 @@ Export-Package: org.sitebricks.client.easy;version="0.8.6.SNAPSHOT";
org.sonatype.sisu.sitebricks.client,
com.google.inject.spi,
com.google.inject"
-Bundle-Version: 0.8.6.SNAPSHOT
+Bundle-Version: 0.8.7.SNAPSHOT
Tool: Bnd-0.0.357
Bundle-Name: sitebricks-easy-client
Bnd-LastModified: 1327256671731
@@ -41,4 +41,3 @@ Import-Package: com.google.inject;version="1.3",
org.codehaus.jackson.type;version="1.9",
org.sitebricks.client.easy;version="0.8",
org.sitebricks.client.easy.internal;version="0.8"
-
@@ -28,7 +28,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -1,6 +1,6 @@
project "Sitebricks :: Jetty Archetype" @ "null"
- id: com.google.sitebricks:sitebricks-jetty-archetype:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-jetty-archetype:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ com.google.sitebricks:sitebricks
@@ -13,6 +13,7 @@
* @author Dhanji R. Prasanna (dhanji@gmail.com)
*/
public class Main {
+
private static final int PORT = 8080;
public static void main(String... args) throws Exception {
@@ -22,4 +23,4 @@ public static void main(String... args) throws Exception {
server.start();
server.join();
}
-}
+}
View
@@ -1,10 +1,10 @@
project "Sitebricks :: Mail Client" @ "null"
- id: com.google.sitebricks:sitebricks-mail:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-mail:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ org.apache.james:apache-mime4j:0.6
- com.google.sitebricks:sitebricks:0.8.6-SNAPSHOT
+ com.google.sitebricks:sitebricks:0.8.7-SNAPSHOT
org.jboss.netty:netty:3.2.4.Final
org.slf4j:slf4j-api:1.5.5
ch.qos.logback:logback-classic:${ch.qos.logback.version}
@@ -1,8 +1,8 @@
repositories << "http://repository.jboss.org/nexus/content/groups/public-jboss/"
project "Sitebricks :: Options Module" @ "null"
- id: com.google.sitebricks:sitebricks-options:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks-options:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ com.google.sitebricks:sitebricks-converter
View
@@ -1,6 +1,6 @@
project "Sitebricks :: Core" @ "null"
- id: com.google.sitebricks:sitebricks:0.8.6-SNAPSHOT
- inherit: com.google.sitebricks:sitebricks-parent:0.8.6-SNAPSHOT:../pom.atom
+ id: com.google.sitebricks:sitebricks:0.8.7-SNAPSHOT
+ inherit: com.google.sitebricks:sitebricks-parent:0.8.7-SNAPSHOT:../pom.atom
packaging: jar
deps: [ org.testng:testng:${org.testng.version}(jdk15)
@@ -1,11 +1,12 @@
package com.google.sitebricks;
-import java.util.Map;
-
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.sitebricks.compiler.TemplateCompiler;
+import java.util.Map;
+import java.util.Set;
+
@Singleton
public class DefaultTemplateSystem implements TemplateSystem {
@@ -16,14 +17,27 @@ public DefaultTemplateSystem(Map<String, TemplateCompiler> templateCompilers) {
this.templateCompilers = templateCompilers;
}
+ @Override
public TemplateCompiler compilerFor(String templateName) {
String extension = templateName.substring(templateName.lastIndexOf(".") + 1);
- TemplateCompiler templateCompiler = templateCompilers.get(extension);
- return templateCompiler;
+ return templateCompilers.get(extension);
}
@Override
public String[] getTemplateExtensions() {
- return new String[] { "%s.html", "%s.xhtml", "%s.xml", "%s.txt", "%s.fml", "%s.dml", "%s.mvel" };
- }
+ Set<String> keys = templateCompilers.keySet();
+
+ if (keys.isEmpty()) {
+ return new String[0];
+ }
+
+ String[] extensions = new String[keys.size()];
+
+ int i = 0;
+ for (String ext : keys) {
+ extensions[i++] = "%s." + ext;
+ }
+
+ return extensions;
+ }
}
@@ -62,9 +62,9 @@ public SitebricksModule() {
methods.put("delete", Delete.class);
methods.put("head", Head.class);
methods.put("trace", Trace.class);
-
+
}
-
+
@Override
protected final void configure() {
@@ -117,19 +117,29 @@ protected final void configure() {
configureTemplateSystem();
}
-
- protected void configureTemplateSystem() {
+
+ protected void configureTemplateSystem() {
//
// Map of all the implementations keyed by type they can handle
//
MapBinder<String,TemplateCompiler> templateCompilers = MapBinder.newMapBinder(binder(), String.class, TemplateCompiler.class);
templateCompilers.addBinding("html").to(HtmlTemplateCompiler.class);
+ templateCompilers.addBinding("xhtml").to(HtmlTemplateCompiler.class);
templateCompilers.addBinding("xml").to(XmlTemplateCompiler.class);
templateCompilers.addBinding("flat").to(FlatTemplateCompiler.class);
templateCompilers.addBinding("mvel").to(MvelTemplateCompiler.class);
- templateCompilers.addBinding("fml").to(FreemarkerTemplateCompiler.class);
+ templateCompilers.addBinding("fml").to(FreemarkerTemplateCompiler.class);
+
+ configureTemplateCompilers(templateCompilers);
}
-
+
+ protected void configureTemplateCompilers(MapBinder<String, TemplateCompiler> compilers) {
+ // Override to include custom template compilers. You can also simply add to the existing MapBinder
+ // mapping anywhere in your modules (see: http://code.google.com/p/google-guice/wiki/Multibindings):
+ // MapBinder<String,TemplateCompiler> templateCompilers = MapBinder.newMapBinder(binder(), String.class, TemplateCompiler.class);
+ // templateCompilers.addBinding("mustache").to(MustacheTemplateCompiler.class);
+ }
+
/**
* Optionally supply {@link javax.servlet.Servlet} and/or {@link javax.servlet.Filter} implementations to
* Guice Servlet. See {@link com.google.sitebricks.SitebricksServletModule} for usage examples.
@@ -194,7 +204,7 @@ public void using(Locale locale, Map<String, String> messages) {
public void using(Locale locale, Properties properties) {
Preconditions.checkArgument(null != properties, "Must provide a non-null resource bundle");
// A Properties object is always of type string/string
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({ "unchecked", "rawtypes" })
Map<String, String> messages = (Map) properties;
localizations.add(new Localizer.Localization(iface, locale, messages));
}
@@ -221,7 +231,7 @@ protected final void scan(Package pack) {
Preconditions.checkArgument(null != pack, "Package parameter to scan() cannot be null");
packages.add(pack);
}
-
+
static enum BindingKind {
EMBEDDED, PAGE, SERVICE, STATIC_RESOURCE, ACTION
}
@@ -331,20 +341,20 @@ public void asEagerSingleton() {
this.asEagerSingleton = true;
}
}
-
+
//
// Converters
//
-
+
@SuppressWarnings("rawtypes")
private Multibinder<Converter> converters;
-
+
public final void converter(Converter<?, ?> converter) {
Preconditions.checkArgument(null != converter, "Type converters cannot be null");
converters.addBinding().toInstance(converter);
}
-
+
public final void converter(Class<? extends Converter<?, ?>> clazz) {
converters.addBinding().to(clazz);
- }
+ }
}
Oops, something went wrong.

0 comments on commit 9b8345b

Please sign in to comment.