Commits

Stephen McKamey committed c737602

lowercasing client-side paths

Comments (0)

Files changed (4)

duel-compiler/src/main/java/org/duelengine/duel/codegen/ClientCodeGen.java

 			this.writeln(output, 0);
 
 			// prepend the client-side prefix
-			String viewName = this.settings.getFullClientName(view.getName());
+			String viewName = this.settings.getClientName(view.getName());
 			try {
 				if (this.encoder.writeNamespace(output, namespaces, viewName)) {
 					this.writeln(output, 0);
 					if (addPrefix && "view".equalsIgnoreCase(attr) && attrVal instanceof ExpressionNode) {
 						// prepend the client-side prefix
 						ExpressionNode nameAttr = (ExpressionNode)attrVal; 
-						attrVal = new ExpressionNode(this.settings.getFullClientName(nameAttr.getValue()), nameAttr.getIndex(), nameAttr.getLine(), nameAttr.getColumn());
+						attrVal = new ExpressionNode(this.settings.getClientName(nameAttr.getValue()), nameAttr.getIndex(), nameAttr.getLine(), nameAttr.getColumn());
 					}
 					this.writeNode(output, attrVal, depth, preMode);
 				}

duel-compiler/src/main/java/org/duelengine/duel/codegen/CodeDOMBuilder.java

 
 import java.io.IOException;
 import java.util.*;
+
 import org.duelengine.duel.*;
 import org.duelengine.duel.ast.*;
 import org.duelengine.duel.codedom.*;
 	public CodeTypeDeclaration buildView(VIEWCommandNode viewNode) throws IOException {
 		try {
 			// prepend the server-side prefix
-			String fullName = this.settings.getFullServerName(viewNode.getName());
+			String fullName = this.settings.getServerName(viewNode.getName());
 			int lastDot = fullName.lastIndexOf('.');
 			String name = fullName.substring(lastDot+1);
 			String ns = (lastDot > 0) ? fullName.substring(0, lastDot) : null;
 		}
 
 		// prepend the server-side prefix
-		viewName = this.settings.getFullServerName(viewName);
+		viewName = this.settings.getServerName(viewName);
 
 		CodeExpression[] ctorArgs = new CodeExpression[node.getChildren().size()];
 
 
 		if (viewName != null) {
 			// prepend the server-side prefix
-			viewName = this.settings.getFullClientName(viewName);
+			viewName = this.settings.getClientName(viewName);
 			this.buffer.append(viewName);
 
 		} else {

duel-compiler/src/main/java/org/duelengine/duel/codegen/CodeGenSettings.java

 package org.duelengine.duel.codegen;
 
+import java.util.Locale;
+
 /**
  * Settings which affect generated code
  */
 public class CodeGenSettings {
+	private static final char NAMESPACE_DELIM = '.';
+	private static final char DIR_DELIM = '/';
 
 	private String clientPrefix;
 	private String serverPrefix;
 	private boolean convertLineEndings;
 	private boolean normalizeWhitespace;
 	private boolean encodeNonASCII = true;
+	private boolean lowercaseClientPaths = true;
 
 	public void setClientNamePrefix(String value) {
-		this.clientPrefix = (value == null) ? null : value.trim();
+		clientPrefix = (value == null) ? null : value.trim();
 	}
 
 	public String getClientNamePrefix() {
-		return this.clientPrefix;
+		return clientPrefix;
 	}
 
 	public boolean hasClientNamePrefix() {
-		return (this.clientPrefix != null) && (this.clientPrefix.length() > 0);
-	}
-
-	public String getFullClientName(String name) {
-		if ((this.clientPrefix == null) || (this.clientPrefix.length() < 1)) {
-			return name;
-		}
-
-		if (name != null) {
-			name = name.trim();
-		}
-
-		return this.clientPrefix+'.'+name;
+		return (clientPrefix != null) && (clientPrefix.length() > 0);
 	}
 
 	public void setServerNamePrefix(String value) {
-		this.serverPrefix = value;
+		serverPrefix = value;
 	}
 
 	public String getServerNamePrefix() {
-		return this.serverPrefix;
+		return serverPrefix;
 	}
 
 	public boolean hasServerNamePrefix() {
-		return (this.serverPrefix != null) && (this.serverPrefix.length() > 0);
-	}
-
-	public String getFullServerName(String name) {
-		if ((this.serverPrefix == null) || (this.serverPrefix.length() < 1)) {
-			return name;
-		}
-
-		if (name != null) {
-			name = name.trim();
-		}
-
-		return this.serverPrefix+'.'+name;
+		return (serverPrefix != null) && (serverPrefix.length() > 0);
 	}
 
 	/**
 	 * @return
 	 */
 	public String getIndent() {
-		return this.indent;
+		return indent;
 	}
 
 	/**
 	 * @param value
 	 */
 	public void setIndent(String value) {
-		this.indent = (value != null) ? value : "";
+		indent = (value != null) ? value : "";
 	}
 
 	/**
 	 * @return
 	 */
 	public String getNewline() {
-		return this.newline;
+		return newline;
 	}
 
 	/**
 	 * @param value
 	 */
 	public void setNewline(String value) {
-		this.newline = (value != null) ? value : "";
+		newline = (value != null) ? value : "";
 	}
 
 	/**
 	 * @return
 	 */
 	public boolean getConvertLineEndings() {
-		return this.convertLineEndings;
+		return convertLineEndings;
 	}
 
 	/**
 	 * @param value
 	 */
 	public void setConvertLineEndings(boolean value) {
-		this.convertLineEndings = value;
+		convertLineEndings = value;
 	}
 
 	/**
 	 * @return
 	 */
 	public boolean getEncodeNonASCII() {
-		return this.encodeNonASCII;
+		return encodeNonASCII;
 	}
 
 	/**
 	 * @param value
 	 */
 	public void setEncodeNonASCII(boolean value) {
-		this.encodeNonASCII = value;
+		encodeNonASCII = value;
 	}
 
 	/**
 	 * @return
 	 */
 	public boolean getNormalizeWhitespace() {
-		return this.normalizeWhitespace;
+		return normalizeWhitespace;
 	}
 
 	/**
 	 * @param value
 	 */
 	public void setNormalizeWhitespace(boolean value) {
-		this.normalizeWhitespace = value;
+		normalizeWhitespace = value;
+	}
+
+	/**
+	 * Gets if client paths and filenames are forced to lowercase
+	 * @return
+	 */
+	public boolean getLowercaseClientPaths() {
+		return lowercaseClientPaths;
+	}
+
+	/**
+	 * Sets if client paths and filenames are forced to lowercase
+	 * @param value
+	 */
+	public void setLowercaseClientPaths(boolean value) {
+		lowercaseClientPaths = value;
+	}
+
+	String getServerName(String viewName) {
+		if (viewName != null) {
+			viewName = viewName.trim();
+		}
+
+		if ((serverPrefix == null) || (serverPrefix.length() < 1)) {
+			return viewName;
+		}
+		return serverPrefix+NAMESPACE_DELIM+viewName;
+	}
+
+	public String getServerPath(String viewName, CodeGenerator codegen) {
+		if (viewName == null) {
+			throw new NullPointerException("viewName");
+		}
+		if (codegen == null) {
+			throw new NullPointerException("codegen");
+		}
+		return getServerName(viewName).replace(NAMESPACE_DELIM, DIR_DELIM) + codegen.getFileExtension();
+	}
+
+	String getClientName(String viewName) {
+		if (viewName != null) {
+			viewName = viewName.trim();
+		}
+
+		if ((clientPrefix == null) || (clientPrefix.length() < 1)) {
+			return viewName;
+		}
+		return clientPrefix+NAMESPACE_DELIM+viewName;
+	}
+
+	public String getClientPath(String viewName) {
+		if (viewName == null) {
+			throw new NullPointerException("viewName");
+		}
+
+		String clientPath = getClientName(viewName);
+		if (lowercaseClientPaths) {
+			// important for case-sensitive web servers & file systems
+			clientPath = clientPath.toLowerCase(Locale.ROOT);
+		}
+		return clientPath.replace(NAMESPACE_DELIM, DIR_DELIM);
 	}
 }

duel-compiler/src/main/java/org/duelengine/duel/compiler/DuelCompiler.java

 
 import java.io.*;
 import java.util.*;
-import org.duelengine.duel.ast.*;
+
+import org.duelengine.duel.ast.VIEWCommandNode;
 import org.duelengine.duel.codegen.*;
 import org.duelengine.duel.parsing.*;
 import org.slf4j.Logger;
 			String outputName = inputFile.getName();
 			for (VIEWCommandNode view : views) {
 				// use the first view
-				outputName = settings.getFullClientName(view.getName()).replace('.', '/');
+				outputName = settings.getClientPath(view.getName());
 				break;
 			}
 
 			codegen = new JavaCodeGen(settings);
 			for (VIEWCommandNode view : views) {
 				try {
-					File outputFile = new File(this.outputServerDir, settings.getFullServerName(view.getName()).replace('.', '/')+codegen.getFileExtension());
+					File outputFile = new File(this.outputServerDir, settings.getServerPath(view.getName(), codegen));
 					outputFile.getParentFile().mkdirs();
 
 					FileWriter writer = new FileWriter(outputFile, false);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.