Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more refactoring / cleanup

  • Loading branch information...
commit c35e725f1e9f12713d284da00b15efbbd636e36f 1 parent b5e43e9
Henrik Hofmeister authored February 02, 2013
20  src/main/java/com/vonhof/webi/file/JavascriptHandler.java
@@ -89,20 +89,28 @@ private void compiled(WebiContext req, List<File> files) throws IOException {
89 89
         //Atleast 1 source file required in root module
90 90
         rootModule.add(SourceFile.fromCode("root.js", ""));
91 91
         
  92
+        //Get absolute dir path to current url
92 93
         final String baseDir = this.getDocumentRoot()+req.getPath();
93 94
         
94 95
         //Run through all files that should be compiled
95 96
         for(File file:files) {
96 97
             
  98
+            //Calculate relative path to HTTP root path
97 99
             String relativePath = req.getBase()+file.getAbsolutePath().substring(this.getDocumentRoot().length()+1);
98  
-            String fileName = file.getAbsolutePath().substring(baseDir.length());
99  
-            if (fileName.isEmpty()) {
100  
-                fileName = file.getName();
  100
+            
  101
+            //Get relative path to file from the current path. This is that path that the browsers will use for 
  102
+            //finding non-minified js
  103
+            String sourcePath = file.getAbsolutePath().substring(baseDir.length());
  104
+            if (sourcePath.isEmpty()) {
  105
+                //If the current path is same as the file path, just use the filename
  106
+                sourcePath = file.getName();
101 107
             }
102  
-            fileName += "?source";
  108
+            
  109
+            //Add parm to have actual non-minified source code show up
  110
+            sourcePath += "?source";
103 111
             
104 112
             //Build source file using paths that the browsers will recognize in source maps
105  
-            SourceFile sFile = SourceFile.fromCode(fileName,relativePath,Files.toString(file, charset));
  113
+            SourceFile sFile = SourceFile.fromCode(sourcePath,relativePath,Files.toString(file, charset));
106 114
             
107 115
             //Check for special comment //@module <name> @prio - low-tech dependency management
108 116
             String firstLine = Files.readFirstLine(file, charset);
@@ -116,9 +124,11 @@ private void compiled(WebiContext req, List<File> files) throws IOException {
116 124
                 }
117 125
             }
118 126
             
  127
+            //Default module name
119 128
             if (moduleName == null || moduleName.isEmpty()) {
120 129
                 moduleName = "__global";
121 130
             }
  131
+            //Create module if not exists
122 132
             if (!modules.containsKey(moduleName)) {
123 133
                 modules.put(moduleName, new JSModule(moduleName));
124 134
             }

0 notes on commit c35e725

Please sign in to comment.
Something went wrong with that request. Please try again.