golf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gitignore +10 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +21 -0
  4. data/Rakefile +12 -0
  5. data/bin/golf +8 -0
  6. data/golf-java/README.markdown +41 -0
  7. data/golf-java/THANKS.markdown +14 -0
  8. data/golf-java/build/classes.zip +0 -0
  9. data/golf-java/build/com/thinkminimo/golf/GolfResource$MimeMapping$MimeMappingSingleton.class +0 -0
  10. data/golf-java/build/com/thinkminimo/golf/GolfResource$MimeMapping.class +0 -0
  11. data/golf-java/build/com/thinkminimo/golf/GolfResource.class +0 -0
  12. data/golf-java/build/com/thinkminimo/golf/GolfServlet$1.class +0 -0
  13. data/golf-java/build/com/thinkminimo/golf/GolfServlet$GolfContext.class +0 -0
  14. data/golf-java/build/com/thinkminimo/golf/GolfServlet$GolfParams.class +0 -0
  15. data/golf-java/build/com/thinkminimo/golf/GolfServlet$GolfSession.class +0 -0
  16. data/golf-java/build/com/thinkminimo/golf/GolfServlet$PermanentRedirectException.class +0 -0
  17. data/golf-java/build/com/thinkminimo/golf/GolfServlet$RedirectException.class +0 -0
  18. data/golf-java/build/com/thinkminimo/golf/GolfServlet$StoredJSVM.class +0 -0
  19. data/golf-java/build/com/thinkminimo/golf/GolfServlet.class +0 -0
  20. data/golf-java/build/com/thinkminimo/golf/JsonpTunnel.class +0 -0
  21. data/golf-java/build/com/thinkminimo/golf/Main$1.class +0 -0
  22. data/golf-java/build/com/thinkminimo/golf/Main$RingList.class +0 -0
  23. data/golf-java/build/com/thinkminimo/golf/Main.class +0 -0
  24. data/golf-java/build/com/thinkminimo/golf/ProxyServlet.class +0 -0
  25. data/golf-java/build/com/yahoo/platform/yui/compressor/CssCompressor.class +0 -0
  26. data/golf-java/build/com/yahoo/platform/yui/compressor/JarClassLoader.class +0 -0
  27. data/golf-java/build/com/yahoo/platform/yui/compressor/JavaScriptCompressor.class +0 -0
  28. data/golf-java/build/com/yahoo/platform/yui/compressor/JavaScriptIdentifier.class +0 -0
  29. data/golf-java/build/com/yahoo/platform/yui/compressor/JavaScriptToken.class +0 -0
  30. data/golf-java/build/com/yahoo/platform/yui/compressor/ScriptOrFnScope.class +0 -0
  31. data/golf-java/build/depends.zip +0 -0
  32. data/golf-java/build/golf +2 -0
  33. data/golf-java/build/org/json/JSONArray.class +0 -0
  34. data/golf-java/build/org/json/JSONException.class +0 -0
  35. data/golf-java/build/org/json/JSONObject$1.class +0 -0
  36. data/golf-java/build/org/json/JSONObject$Null.class +0 -0
  37. data/golf-java/build/org/json/JSONObject.class +0 -0
  38. data/golf-java/build/org/json/JSONString.class +0 -0
  39. data/golf-java/build/org/json/JSONStringer.class +0 -0
  40. data/golf-java/build/org/json/JSONTokener.class +0 -0
  41. data/golf-java/build/org/json/JSONWriter.class +0 -0
  42. data/golf-java/build/resources.zip +0 -0
  43. data/golf-java/build.xml +174 -0
  44. data/golf-java/dist/golf.zip +0 -0
  45. data/golf-java/lib/ant-launcher.jar +0 -0
  46. data/golf-java/lib/ant.jar +0 -0
  47. data/golf-java/lib/commons-codec-1.4.jar +0 -0
  48. data/golf-java/lib/commons-collections-3.2.1.jar +0 -0
  49. data/golf-java/lib/commons-fileupload-1.2.1.jar +0 -0
  50. data/golf-java/lib/commons-httpclient-3.1.jar +0 -0
  51. data/golf-java/lib/commons-io-1.4.jar +0 -0
  52. data/golf-java/lib/commons-lang-2.4.jar +0 -0
  53. data/golf-java/lib/commons-logging-1.1.1.jar +0 -0
  54. data/golf-java/lib/cssparser-0.9.5.jar +0 -0
  55. data/golf-java/lib/getopt-0.1-dev.jar +0 -0
  56. data/golf-java/lib/htmlunit-2.6.jar +0 -0
  57. data/golf-java/lib/htmlunit-core-js-2.6.jar +0 -0
  58. data/golf-java/lib/java-xmlbuilder-1.jar +0 -0
  59. data/golf-java/lib/jets3t-0.7.0.jar +0 -0
  60. data/golf-java/lib/jetty-6.1.15.jar +0 -0
  61. data/golf-java/lib/jetty-util-6.1.15.jar +0 -0
  62. data/golf-java/lib/log4j-1.2.15.jar +0 -0
  63. data/golf-java/lib/nekohtml-1.9.13.jar +0 -0
  64. data/golf-java/lib/sac-1.3.jar +0 -0
  65. data/golf-java/lib/serializer-2.7.1.jar +0 -0
  66. data/golf-java/lib/servlet-api-2.5-20081211.jar +0 -0
  67. data/golf-java/lib/xalan-2.7.1.jar +0 -0
  68. data/golf-java/lib/xercesImpl-2.9.1.jar +0 -0
  69. data/golf-java/lib/xml-apis-1.3.04.jar +0 -0
  70. data/golf-java/resources/app_error.html +60 -0
  71. data/golf-java/resources/error.html +29 -0
  72. data/golf-java/resources/forcebot.txt +0 -0
  73. data/golf-java/resources/forceclient.txt +0 -0
  74. data/golf-java/resources/forceproxy.txt +0 -0
  75. data/golf-java/resources/head.html +0 -0
  76. data/golf-java/resources/jquery.address.js +439 -0
  77. data/golf-java/resources/jquery.golf.js +945 -0
  78. data/golf-java/resources/jquery.js +4376 -0
  79. data/golf-java/resources/jsdetect.html +23 -0
  80. data/golf-java/resources/loading.gif +0 -0
  81. data/golf-java/resources/new.html +45 -0
  82. data/golf-java/resources/new.static.html +45 -0
  83. data/golf-java/resources/noscript.forceclient.html +11 -0
  84. data/golf-java/resources/noscript.html +18 -0
  85. data/golf-java/resources/noscript.static.html +15 -0
  86. data/golf-java/resources/project.xml +21 -0
  87. data/golf-java/resources/proxy_project.xml +11 -0
  88. data/golf-java/resources/proxy_web.xml +40 -0
  89. data/golf-java/resources/static_project.xml +37 -0
  90. data/golf-java/resources/version +1 -0
  91. data/golf-java/resources/web.xml +36 -0
  92. data/golf-java/resources/welcome2golf.html +50 -0
  93. data/golf-java/src/com/thinkminimo/golf/GolfResource.java +582 -0
  94. data/golf-java/src/com/thinkminimo/golf/GolfServlet.java +1055 -0
  95. data/golf-java/src/com/thinkminimo/golf/JsonpTunnel.java +86 -0
  96. data/golf-java/src/com/thinkminimo/golf/Main.java +1299 -0
  97. data/golf-java/src/com/thinkminimo/golf/ProxyServlet.java +577 -0
  98. data/golf-java/src/com/yahoo/platform/yui/compressor/CssCompressor.java +188 -0
  99. data/golf-java/src/com/yahoo/platform/yui/compressor/JarClassLoader.java +158 -0
  100. data/golf-java/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java +1281 -0
  101. data/golf-java/src/com/yahoo/platform/yui/compressor/JavaScriptIdentifier.java +55 -0
  102. data/golf-java/src/com/yahoo/platform/yui/compressor/JavaScriptToken.java +28 -0
  103. data/golf-java/src/com/yahoo/platform/yui/compressor/ScriptOrFnScope.java +160 -0
  104. data/golf-java/src/org/json/JSONArray.java +934 -0
  105. data/golf-java/src/org/json/JSONException.java +27 -0
  106. data/golf-java/src/org/json/JSONObject.java +1550 -0
  107. data/golf-java/src/org/json/JSONString.java +18 -0
  108. data/golf-java/src/org/json/JSONStringer.java +78 -0
  109. data/golf-java/src/org/json/JSONTokener.java +422 -0
  110. data/golf-java/src/org/json/JSONWriter.java +323 -0
  111. data/golf-java/test/client/golftest/README.markdown +3 -0
  112. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.css +114 -0
  113. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.html +17 -0
  114. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.js +81 -0
  115. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.res/asc.gif +0 -0
  116. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.res/bg.gif +0 -0
  117. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.res/desc.gif +0 -0
  118. data/golf-java/test/client/golftest/components/com/thinkminimo/golf/test/Harness.res/test/test.html +1 -0
  119. data/golf-java/test/client/golftest/controller.js +131 -0
  120. data/golf-java/test/client/golftest/forceclient.txt +0 -0
  121. data/golf-java/test/client/golftest/forceproxy.txt +0 -0
  122. data/golf-java/test/client/golftest/head.html +1 -0
  123. data/golf-java/test/client/golftest/scripts/jquery.tablesort.js +75 -0
  124. data/golf-java/test/client/golftest/styles/style.css +18 -0
  125. data/golf-java/test/client/golftest/test/test.html +1 -0
  126. data/golf.gemspec +24 -0
  127. data/lib/golf/cli.rb +32 -0
  128. data/lib/golf/compiler.rb +12 -0
  129. data/lib/golf/rack.rb +17 -0
  130. data/lib/golf/version.rb +3 -0
  131. data/lib/golf.rb +6 -0
  132. data/template/Gemfile +5 -0
  133. data/template/config.ru +7 -0
  134. data/template/golfapp/components/Test/Test.html +22 -0
  135. data/template/golfapp/components/Test/Test.res/myfile.txt +1 -0
  136. data/template/golfapp/controller.js +10 -0
  137. data/template/golfapp/plugins/mylib.js +12 -0
  138. data/test/test_compiler.rb +10 -0
  139. data/test/test_helper.rb +6 -0
  140. data/test/test_rack.rb +17 -0
  141. metadata +208 -0
@@ -0,0 +1,188 @@
1
+ /*
2
+ * YUI Compressor
3
+ * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
4
+ * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
5
+ * Code licensed under the BSD License:
6
+ * http://developer.yahoo.net/yui/license.txt
7
+ *
8
+ * This code is a port of Isaac Schlueter's cssmin utility.
9
+ */
10
+
11
+ package com.yahoo.platform.yui.compressor;
12
+
13
+ import java.io.IOException;
14
+ import java.io.Reader;
15
+ import java.io.Writer;
16
+ import java.util.regex.Pattern;
17
+ import java.util.regex.Matcher;
18
+
19
+ public class CssCompressor {
20
+
21
+ private StringBuffer srcsb = new StringBuffer();
22
+
23
+ public CssCompressor(Reader in) throws IOException {
24
+ // Read the stream...
25
+ int c;
26
+ while ((c = in.read()) != -1) {
27
+ srcsb.append((char) c);
28
+ }
29
+ }
30
+
31
+ public void compress(Writer out, int linebreakpos)
32
+ throws IOException {
33
+
34
+ Pattern p;
35
+ Matcher m;
36
+ String css;
37
+ StringBuffer sb;
38
+ int startIndex, endIndex;
39
+
40
+ // Remove all comment blocks...
41
+ startIndex = 0;
42
+ boolean iemac = false;
43
+ boolean preserve = false;
44
+ sb = new StringBuffer(srcsb.toString());
45
+ while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
46
+ preserve = sb.length() > startIndex + 2 && sb.charAt(startIndex + 2) == '!';
47
+ endIndex = sb.indexOf("*/", startIndex + 2);
48
+ if (endIndex < 0) {
49
+ if (!preserve) {
50
+ sb.delete(startIndex, sb.length());
51
+ }
52
+ } else if (endIndex >= startIndex + 2) {
53
+ if (sb.charAt(endIndex-1) == '\\') {
54
+ // Looks like a comment to hide rules from IE Mac.
55
+ // Leave this comment, and the following one, alone...
56
+ startIndex = endIndex + 2;
57
+ iemac = true;
58
+ } else if (iemac) {
59
+ startIndex = endIndex + 2;
60
+ iemac = false;
61
+ } else if (!preserve) {
62
+ sb.delete(startIndex, endIndex + 2);
63
+ } else {
64
+ startIndex = endIndex + 2;
65
+ }
66
+ }
67
+ }
68
+
69
+ css = sb.toString();
70
+
71
+ // Normalize all whitespace strings to single spaces. Easier to work with that way.
72
+ css = css.replaceAll("\\s+", " ");
73
+
74
+ // Make a pseudo class for the Box Model Hack
75
+ css = css.replaceAll("\"\\\\\"}\\\\\"\"", "___PSEUDOCLASSBMH___");
76
+
77
+ // Remove the spaces before the things that should not have spaces before them.
78
+ // But, be careful not to turn "p :link {...}" into "p:link{...}"
79
+ // Swap out any pseudo-class colons with the token, and then swap back.
80
+ sb = new StringBuffer();
81
+ p = Pattern.compile("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
82
+ m = p.matcher(css);
83
+ while (m.find()) {
84
+ String s = m.group();
85
+ s = s.replaceAll(":", "___PSEUDOCLASSCOLON___");
86
+ m.appendReplacement(sb, s);
87
+ }
88
+ m.appendTail(sb);
89
+ css = sb.toString();
90
+ css = css.replaceAll("\\s+([!{};:>+\\(\\)\\],])", "$1");
91
+ css = css.replaceAll("___PSEUDOCLASSCOLON___", ":");
92
+
93
+ // Remove the spaces after the things that should not have spaces after them.
94
+ css = css.replaceAll("([!{}:;>+\\(\\[,])\\s+", "$1");
95
+
96
+ // Add the semicolon where it's missing.
97
+ css = css.replaceAll("([^;\\}])}", "$1;}");
98
+
99
+ // Replace 0(px,em,%) with 0.
100
+ css = css.replaceAll("([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)", "$1$2");
101
+
102
+ // Replace 0 0 0 0; with 0.
103
+ css = css.replaceAll(":0 0 0 0;", ":0;");
104
+ css = css.replaceAll(":0 0 0;", ":0;");
105
+ css = css.replaceAll(":0 0;", ":0;");
106
+ // Replace background-position:0; with background-position:0 0;
107
+ css = css.replaceAll("background-position:0;", "background-position:0 0;");
108
+
109
+ // Replace 0.6 to .6, but only when preceded by : or a white-space
110
+ css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");
111
+
112
+ // Shorten colors from rgb(51,102,153) to #336699
113
+ // This makes it more likely that it'll get further compressed in the next step.
114
+ p = Pattern.compile("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
115
+ m = p.matcher(css);
116
+ sb = new StringBuffer();
117
+ while (m.find()) {
118
+ String[] rgbcolors = m.group(1).split(",");
119
+ StringBuffer hexcolor = new StringBuffer("#");
120
+ for (int i = 0; i < rgbcolors.length; i++) {
121
+ int val = Integer.parseInt(rgbcolors[i]);
122
+ if (val < 16) {
123
+ hexcolor.append("0");
124
+ }
125
+ hexcolor.append(Integer.toHexString(val));
126
+ }
127
+ m.appendReplacement(sb, hexcolor.toString());
128
+ }
129
+ m.appendTail(sb);
130
+ css = sb.toString();
131
+
132
+ // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
133
+ // the color is not preceded by either ", " or =. Indeed, the property
134
+ // filter: chroma(color="#FFFFFF");
135
+ // would become
136
+ // filter: chroma(color="#FFF");
137
+ // which makes the filter break in IE.
138
+ p = Pattern.compile("([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
139
+ m = p.matcher(css);
140
+ sb = new StringBuffer();
141
+ while (m.find()) {
142
+ // Test for AABBCC pattern
143
+ if (m.group(3).equalsIgnoreCase(m.group(4)) &&
144
+ m.group(5).equalsIgnoreCase(m.group(6)) &&
145
+ m.group(7).equalsIgnoreCase(m.group(8))) {
146
+ m.appendReplacement(sb, m.group(1) + m.group(2) + "#" + m.group(3) + m.group(5) + m.group(7));
147
+ } else {
148
+ m.appendReplacement(sb, m.group());
149
+ }
150
+ }
151
+ m.appendTail(sb);
152
+ css = sb.toString();
153
+
154
+ // Remove empty rules.
155
+ css = css.replaceAll("[^\\}]+\\{;\\}", "");
156
+
157
+ if (linebreakpos >= 0) {
158
+ // Some source control tools don't like it when files containing lines longer
159
+ // than, say 8000 characters, are checked in. The linebreak option is used in
160
+ // that case to split long lines after a specific column.
161
+ int i = 0;
162
+ int linestartpos = 0;
163
+ sb = new StringBuffer(css);
164
+ while (i < sb.length()) {
165
+ char c = sb.charAt(i++);
166
+ if (c == '}' && i - linestartpos > linebreakpos) {
167
+ sb.insert(i, '\n');
168
+ linestartpos = i;
169
+ }
170
+ }
171
+
172
+ css = sb.toString();
173
+ }
174
+
175
+ // Replace the pseudo class for the Box Model Hack
176
+ css = css.replaceAll("___PSEUDOCLASSBMH___", "\"\\\\\"}\\\\\"\"");
177
+
178
+ // Replace multiple semi-colons in a row by a single one
179
+ // See SF bug #1980989
180
+ css = css.replaceAll(";;+", ";");
181
+
182
+ // Trim the final string (for any leading or trailing white spaces)
183
+ css = css.trim();
184
+
185
+ // Write the output...
186
+ out.write(css);
187
+ }
188
+ }
@@ -0,0 +1,158 @@
1
+ /*
2
+ * YUI Compressor
3
+ * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
4
+ * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
5
+ * Code licensed under the BSD License:
6
+ * http://developer.yahoo.net/yui/license.txt
7
+ */
8
+
9
+ package com.yahoo.platform.yui.compressor;
10
+
11
+ import java.io.ByteArrayOutputStream;
12
+ import java.io.IOException;
13
+ import java.io.InputStream;
14
+ import java.io.OutputStream;
15
+ import java.util.Enumeration;
16
+ import java.util.jar.JarEntry;
17
+ import java.util.jar.JarFile;
18
+
19
+ public class JarClassLoader extends ClassLoader {
20
+
21
+ private static String jarPath;
22
+
23
+ public Class loadClass(String name) throws ClassNotFoundException {
24
+
25
+ // First check if the class is already loaded
26
+ Class c = findLoadedClass(name);
27
+ if (c == null) {
28
+ c = findClass(name);
29
+ }
30
+
31
+ if (c == null) {
32
+ c = ClassLoader.getSystemClassLoader().loadClass(name);
33
+ }
34
+
35
+ return c;
36
+ }
37
+
38
+ private static String getJarPath() {
39
+
40
+ if (jarPath != null) {
41
+ return jarPath;
42
+ }
43
+
44
+ String classname = JarClassLoader.class.getName().replace('.', '/') + ".class";
45
+ String classpath = System.getProperty("java.class.path");
46
+ String classpaths[] = classpath.split(System.getProperty("path.separator"));
47
+
48
+ for (int i = 0; i < classpaths.length; i++) {
49
+
50
+ String path = classpaths[i];
51
+ JarFile jarFile = null;
52
+ JarEntry jarEntry = null;
53
+
54
+ try {
55
+ jarFile = new JarFile(path);
56
+ jarEntry = findJarEntry(jarFile, classname);
57
+ } catch (IOException ioe) {
58
+ /* ignore */
59
+ } finally {
60
+ if (jarFile != null) {
61
+ try {
62
+ jarFile.close();
63
+ } catch (IOException ioe) {
64
+ /* ignore */
65
+ }
66
+ }
67
+ }
68
+
69
+ if (jarEntry != null) {
70
+ jarPath = path;
71
+ break;
72
+ }
73
+ }
74
+
75
+ return jarPath;
76
+ }
77
+
78
+ private static JarEntry findJarEntry(JarFile jarFile, String entryName) {
79
+
80
+ Enumeration entries = jarFile.entries();
81
+
82
+ while (entries.hasMoreElements()) {
83
+ JarEntry entry = (JarEntry) entries.nextElement();
84
+ if (entry.getName().equals(entryName)) {
85
+ return entry;
86
+ }
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+ protected Class findClass(String name) {
93
+
94
+ Class c = null;
95
+ String jarPath = getJarPath();
96
+
97
+ if (jarPath != null) {
98
+ JarFile jarFile = null;
99
+ try {
100
+ jarFile = new JarFile(jarPath);
101
+ c = loadClassData(jarFile, name);
102
+ } catch (IOException ioe) {
103
+ /* ignore */
104
+ } finally {
105
+ if (jarFile != null) {
106
+ try {
107
+ jarFile.close();
108
+ } catch (IOException ioe) {
109
+ /* ignore */
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ return c;
116
+ }
117
+
118
+ private Class loadClassData(JarFile jarFile, String className) {
119
+
120
+ String entryName = className.replace('.', '/') + ".class";
121
+ JarEntry jarEntry = findJarEntry(jarFile, entryName);
122
+ if (jarEntry == null) {
123
+ return null;
124
+ }
125
+
126
+ // Create the necessary package if needed...
127
+ int index = className.lastIndexOf('.');
128
+ if (index >= 0) {
129
+ String packageName = className.substring(0, index);
130
+ if (getPackage(packageName) == null) {
131
+ definePackage(packageName, "", "", "", "", "", "", null);
132
+ }
133
+ }
134
+
135
+ // Read the Jar File entry and define the class...
136
+ Class c = null;
137
+ try {
138
+ InputStream is = jarFile.getInputStream(jarEntry);
139
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
140
+ copy(is, os);
141
+ byte[] bytes = os.toByteArray();
142
+ c = defineClass(className, bytes, 0, bytes.length);
143
+ } catch (IOException ioe) {
144
+ /* ignore */
145
+ }
146
+
147
+ return c;
148
+ }
149
+
150
+ private void copy(InputStream in, OutputStream out) throws IOException {
151
+ byte[] buf = new byte[1024];
152
+ while (true) {
153
+ int len = in.read(buf);
154
+ if (len < 0) break;
155
+ out.write(buf, 0, len);
156
+ }
157
+ }
158
+ }