Commits

Stephen McKamey  committed bf9068f

fixing debug semantics to be blocking as if was a compacted script

  • Participants
  • Parent commits bbdd996
  • Tags v0.2.0

Comments (0)

Files changed (3)

File merge-builder/src/main/java/org/duelengine/merge/CSSPlaceholderGenerator.java

 		FileWriter writer = new FileWriter(target, false);
 
 		try {
+			writer.append("/* simulate semantics of merged stylesheets but allow debugging of original files */\n");
+
 			// concatenate references to children
 			for (String child : children) {
 				// insert child files into outputFile
-				writer.append("@import url(").append(child).append(");\n");
+				writer
+					.append("@import url(")
+					.append(child)
+					.append(");\n");
 			}
 
 		} finally {

File merge-builder/src/main/java/org/duelengine/merge/JSPlaceholderGenerator.java

 		FileWriter writer = new FileWriter(target, false);
 
 		try {
-			writer.append("(function() {\n\tvar s, d=document, f=d.getElementsByTagName('script')[0], p=f.parentNode;\n");
+			writer
+				.append("(function() {\n")
+				.append("\t// simulate semantics of merged scripts but allow debugging the original files\n")
+				.append("\ttry {\n");
 
 			// concatenate references to children
 			for (String child : children) {
 				// insert child files into outputFile
 				writer
-					.append("\ts=d.createElement('script');s.type='text/javascript';s.src='")
+					.append("\t\tdocument.write('\u003cscript type=\"text/javascript\" src=\"")
+					.append(child)
+					.append("\">\u003c/script>');\n");
+			}
+
+			writer
+				.append("\t} catch(ex) {\n")
+				.append("\t\tvar s, d=document, f=d.getElementsByTagName('script')[0], p=f.parentNode;\n");
+
+			// concatenate references to children
+			for (String child : children) {
+				// insert child files into outputFile
+				writer
+					.append("\t\ts=d.createElement('script');s.type='text/javascript';s.src='")
 					.append(child.replace("'", "\\'"))
 					.append("';p.insertBefore(s,f);\n");
 			}
 
-			writer.append("})();");
+			writer
+				.append("\t}\n")
+				.append("})();");
 
 		} finally {
 			writer.flush();

File merge-builder/src/main/java/org/duelengine/merge/MergeBuilder.java

 			List<String> children = dependencyMap.get(path);
 
 			this.buildMerge(hashLookup, path, children);
-			this.buildDevPlaceholders(hashLookup, path, children);
+			this.buildDebugPlaceholders(hashLookup, path, children);
 		}
 
 		saveHashLookup(hashLookup);
 		}
 	}
 
-	private void buildDevPlaceholders(final Map<String, String> hashLookup, String path, List<String> children)
+	private void buildDebugPlaceholders(final Map<String, String> hashLookup, String path, List<String> children)
 		throws FileNotFoundException, IOException {
 
 		String hashPath = hashLookup.get(path);
+		if (children.size() == 1) {
+			// if only one child then the source file is the debugPath
+			hashLookup.put(hashPath, children.get(0));
+			return;
+		}
+
+		// splice in the debug directory
 		int slash = hashPath.lastIndexOf('/');
+		String debugPath = hashPath.substring(0, slash)+"/debug"+hashPath.substring(slash);
+		hashLookup.put(hashPath, debugPath);
 
-		// insert dev dir
-		String devPath = hashPath.substring(0, slash)+"/dev"+hashPath.substring(slash);
-		hashLookup.put(hashPath, devPath);
-
-		File outputFile = new File(this.outputDir, devPath);
+		File outputFile = new File(this.outputDir, debugPath);
 		if (outputFile.exists()) {
 			return;
 		}
 
 		PlaceholderGenerator generator = this.placeholders.get(getExtension(hashPath));
 		if (generator == null) {
-			log.warning("Cannot generate placeholder for "+hashPath);
+			log.warning("Cannot generate debug placeholder for "+debugPath);
 			return;
 		}