Skip to content

Commit

Permalink
Adds theme_resource_path config param to ThemeConfig "builder"
Browse files Browse the repository at this point in the history
 * Bumps version to 3.2.0
  • Loading branch information
Tom McClure committed Jan 30, 2016
1 parent 7514184 commit e23629e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Available from Maven Central:
<dependency>
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<version>3.1.3</version>
<version>3.2.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<packaging>jar</packaging>
<version>3.1.3</version>
<version>3.2.0</version>
<name>Chunk Templates</name>
<description>Chunk Template Engine for Java</description>
<url>http://www.x5software.com/chunk/</url>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/x5/template/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@
* Updates: <A href="http://www.x5software.com/chunk/">Chunk Documentation</A><BR>
*
* @author Tom McClure
* @version 3.1.3
* @version 3.2.0
*/

public class Chunk implements Map<String,Object>
{
public static final int HASH_THRESH = 8;
public static final int DEPTH_LIMIT = 17;

public static final String VERSION = "3.1.3";
public static final String VERSION = "3.2.0";

private static final String TRUE = "TRUE";

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/x5/template/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public Theme(ThemeConfig config)
if (encoding != null) {
this.setEncoding(encoding);
}

String themeResourcePath = config.getThemeResourcePath();
if (themeResourcePath != null) {
this.setClasspathThemesFolder(themeResourcePath);
}
}

public Theme(ContentSource templates)
Expand All @@ -74,14 +79,19 @@ public Theme(String themesFolder, String themeLayerNames, String ext)
this.fileExtension = ext;
}

public void setClasspathThemesFolder(String classpathThemesFolder) {
this.classpathThemesFolder = classpathThemesFolder;
public void setClasspathThemesFolder(String classpathThemesFolder)
{
if (this.themeLayers.size() > 0) {
throw new java.lang.IllegalStateException("Must specify paths before lazy init.");
} else {
this.classpathThemesFolder = classpathThemesFolder;
}
}

public void setTemplateFolder(String pathToTemplates)
{
if (this.themeLayers.size() > 0) {
throw new java.lang.IllegalStateException("Must specify extension before lazy init.");
throw new java.lang.IllegalStateException("Must specify paths before lazy init.");
} else {
this.themesFolder = pathToTemplates;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/x5/template/ThemeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class ThemeConfig
{
public static final String THEME_PATH = "theme_path";
public static final String THEME_RESOURCE_PATH = "theme_resource_path";
public static final String LAYER_NAMES = "layers";
public static final String DEFAULT_EXT = "default_extension";
public static final String CACHE_MINUTES = "cache_minutes";
Expand All @@ -26,6 +27,7 @@ public class ThemeConfig
public static final String STANDARD_DEFAULT_EXT = "chtml";

private String themePath = null;
private String themeResourcePath = null;
private String layerNames = null;
private String defaultExtension = STANDARD_DEFAULT_EXT;
private int cacheMinutes = 0;
Expand All @@ -51,6 +53,8 @@ public void set(String configKey, String value)

if (configKey.equals(THEME_PATH)) {
this.themePath = value;
} else if (configKey.equals(THEME_RESOURCE_PATH)) {
this.themeResourcePath = value;
} else if (configKey.equals(LAYER_NAMES)) {
this.layerNames = value;
} else if (configKey.equals(DEFAULT_EXT)) {
Expand Down Expand Up @@ -169,6 +173,11 @@ public String getThemeFolder()
return this.themePath;
}

public String getThemeResourcePath()
{
return this.themeResourcePath;
}

public String getLayerNames()
{
return this.layerNames;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/x5/util/Path.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.x5.util;

public class Path {
public static String ensureTrailingSeparator(String path) {
public class Path
{
public static String ensureTrailingSeparator(String path)
{
if (path != null) {
char lastChar = path.charAt(path.length()-1);
char fs = System.getProperty("file.separator").charAt(0);
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/x5/template/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public void testUserFilterConfig()
assertEquals("XXXspacey XXX", c.toString());
}

@Test
public void testAlternateResourcePath()
{
Map<String, String> cfg = new HashMap<String,String>();
cfg.put("theme_resource_path", "/alt/themes");

ThemeConfig config = new ThemeConfig(cfg);
Theme theme = new Theme(config);
Chunk c = theme.makeChunk("hello#hello_world");
c.set("what_kind", "bizarro");
assertEquals("Hello bizarro world!", c.toString());
}

@Test
public void testHideErrors()
{
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/alt/themes/hello.chtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#hello_world}Hello {$what_kind:chunky} world!{#}

0 comments on commit e23629e

Please sign in to comment.