bixbite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +49 -0
  3. data/VERSION +1 -0
  4. data/bin/bixbite +73 -0
  5. data/lib/bixbite.rb +13 -0
  6. data/lib/bixbite/command.rb +14 -0
  7. data/lib/bixbite/create.rb +76 -0
  8. data/template/Rakefile +25 -0
  9. data/template/assets/bixbite/Rakefile.rb +297 -0
  10. data/template/assets/naturaldocs/NaturalDocs/Config/Languages.txt +286 -0
  11. data/template/assets/naturaldocs/NaturalDocs/Config/Topics.txt +382 -0
  12. data/template/assets/naturaldocs/NaturalDocs/Help/customizinglanguages.html +52 -0
  13. data/template/assets/naturaldocs/NaturalDocs/Help/customizingtopics.html +74 -0
  14. data/template/assets/naturaldocs/NaturalDocs/Help/documenting.html +58 -0
  15. data/template/assets/naturaldocs/NaturalDocs/Help/documenting/reference.html +146 -0
  16. data/template/assets/naturaldocs/NaturalDocs/Help/documenting/walkthrough.html +180 -0
  17. data/template/assets/naturaldocs/NaturalDocs/Help/example/Default.css +528 -0
  18. data/template/assets/naturaldocs/NaturalDocs/Help/example/NaturalDocs.js +204 -0
  19. data/template/assets/naturaldocs/NaturalDocs/Help/examples.css +90 -0
  20. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/background.png +0 -0
  21. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/leftside.png +0 -0
  22. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/logo.png +0 -0
  23. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overbody.png +0 -0
  24. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overbodybg.png +0 -0
  25. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overleftmargin.png +0 -0
  26. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overmenu.png +0 -0
  27. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overmenubg.png +0 -0
  28. data/template/assets/naturaldocs/NaturalDocs/Help/images/header/rightside.png +0 -0
  29. data/template/assets/naturaldocs/NaturalDocs/Help/images/logo.gif +0 -0
  30. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/about.png +0 -0
  31. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/background.png +0 -0
  32. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/bottomleft.png +0 -0
  33. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/bottomright.png +0 -0
  34. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/community.png +0 -0
  35. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/customizing.png +0 -0
  36. data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/using.png +0 -0
  37. data/template/assets/naturaldocs/NaturalDocs/Help/index.html +9 -0
  38. data/template/assets/naturaldocs/NaturalDocs/Help/javascript/BrowserStyles.js +77 -0
  39. data/template/assets/naturaldocs/NaturalDocs/Help/javascript/PNGHandling.js +72 -0
  40. data/template/assets/naturaldocs/NaturalDocs/Help/keywords.html +38 -0
  41. data/template/assets/naturaldocs/NaturalDocs/Help/languages.html +32 -0
  42. data/template/assets/naturaldocs/NaturalDocs/Help/menu.html +79 -0
  43. data/template/assets/naturaldocs/NaturalDocs/Help/output.html +84 -0
  44. data/template/assets/naturaldocs/NaturalDocs/Help/running.html +40 -0
  45. data/template/assets/naturaldocs/NaturalDocs/Help/styles.css +290 -0
  46. data/template/assets/naturaldocs/NaturalDocs/Help/styles.html +52 -0
  47. data/template/assets/naturaldocs/NaturalDocs/Help/troubleshooting.html +18 -0
  48. data/template/assets/naturaldocs/NaturalDocs/Info/CSSGuide.txt +947 -0
  49. data/template/assets/naturaldocs/NaturalDocs/Info/File Parsing.txt +83 -0
  50. data/template/assets/naturaldocs/NaturalDocs/Info/HTMLTestCases.pm +269 -0
  51. data/template/assets/naturaldocs/NaturalDocs/Info/Languages.txt +107 -0
  52. data/template/assets/naturaldocs/NaturalDocs/Info/NDMarkup.txt +91 -0
  53. data/template/assets/naturaldocs/NaturalDocs/Info/Symbol Management.txt +59 -0
  54. data/template/assets/naturaldocs/NaturalDocs/Info/images/Logo.png +0 -0
  55. data/template/assets/naturaldocs/NaturalDocs/JavaScript/NaturalDocs.js +836 -0
  56. data/template/assets/naturaldocs/NaturalDocs/License-GPL.txt +341 -0
  57. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/BinaryFile.pm +294 -0
  58. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder.pm +280 -0
  59. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/Base.pm +348 -0
  60. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/FramedHTML.pm +345 -0
  61. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/HTML.pm +398 -0
  62. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/HTMLBase.pm +3693 -0
  63. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy.pm +860 -0
  64. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy/Class.pm +412 -0
  65. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy/File.pm +157 -0
  66. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ConfigFile.pm +497 -0
  67. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Constants.pm +165 -0
  68. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/DefineMembers.pm +100 -0
  69. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Error.pm +305 -0
  70. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/File.pm +540 -0
  71. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable.pm +383 -0
  72. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable/Reference.pm +44 -0
  73. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable/String.pm +110 -0
  74. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages.pm +1475 -0
  75. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/ActionScript.pm +1473 -0
  76. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Ada.pm +38 -0
  77. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced.pm +828 -0
  78. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced/Scope.pm +95 -0
  79. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced/ScopeChange.pm +70 -0
  80. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Base.pm +832 -0
  81. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/CSharp.pm +1484 -0
  82. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/PLSQL.pm +319 -0
  83. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Pascal.pm +143 -0
  84. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Perl.pm +1370 -0
  85. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Prototype.pm +92 -0
  86. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Prototype/Parameter.pm +87 -0
  87. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Simple.pm +503 -0
  88. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Tcl.pm +219 -0
  89. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Menu.pm +3406 -0
  90. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Menu/Entry.pm +201 -0
  91. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/NDMarkup.pm +76 -0
  92. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser.pm +1331 -0
  93. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/JavaDoc.pm +464 -0
  94. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/Native.pm +1060 -0
  95. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/ParsedTopic.pm +253 -0
  96. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project.pm +1402 -0
  97. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project/ImageFile.pm +160 -0
  98. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project/SourceFile.pm +113 -0
  99. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ReferenceString.pm +334 -0
  100. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Settings.pm +1418 -0
  101. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Settings/BuildTarget.pm +66 -0
  102. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB.pm +678 -0
  103. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/Extension.pm +84 -0
  104. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/File.pm +129 -0
  105. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/Item.pm +201 -0
  106. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/ItemDefinition.pm +45 -0
  107. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/WatchedFileDefinitions.pm +159 -0
  108. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/StatusMessage.pm +102 -0
  109. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolString.pm +212 -0
  110. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable.pm +1984 -0
  111. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/File.pm +186 -0
  112. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/IndexElement.pm +522 -0
  113. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/Reference.pm +273 -0
  114. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/ReferenceTarget.pm +97 -0
  115. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/Symbol.pm +428 -0
  116. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/SymbolDefinition.pm +96 -0
  117. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Topics.pm +1319 -0
  118. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Topics/Type.pm +151 -0
  119. data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Version.pm +384 -0
  120. data/template/assets/naturaldocs/NaturalDocs/NaturalDocs +400 -0
  121. data/template/assets/naturaldocs/NaturalDocs/NaturalDocs.bat +17 -0
  122. data/template/assets/naturaldocs/NaturalDocs/Styles/Default.css +767 -0
  123. data/template/assets/naturaldocs/NaturalDocs/Styles/Roman.css +765 -0
  124. data/template/assets/naturaldocs/NaturalDocs/Styles/Small.css +763 -0
  125. data/template/assets/utilities/pngout +0 -0
  126. data/template/deploy/public_html/.htaccess +0 -0
  127. data/template/documentation/js/.htaccess +0 -0
  128. data/template/src/html/.htaccess +76 -0
  129. data/template/src/html/css/cmn/global.css +96 -0
  130. data/template/src/html/css/cmn/ie.css +15 -0
  131. data/template/src/html/css/cmn/ie6.css +15 -0
  132. data/template/src/html/images/cmn/.htaccess +0 -0
  133. data/template/src/html/images/tmp/.htaccess +0 -0
  134. data/template/src/html/includes/debug.inc +5 -0
  135. data/template/src/html/includes/footer.inc +52 -0
  136. data/template/src/html/includes/header.inc +61 -0
  137. data/template/src/html/includes/html.inc +3 -0
  138. data/template/src/html/includes/namespace.inc +19 -0
  139. data/template/src/html/includes/page.inc +151 -0
  140. data/template/src/html/index.html +35 -0
  141. data/template/src/html/js/cmn/bootstrap.js +74 -0
  142. data/template/src/html/js/cmn/global.js +142 -0
  143. data/template/src/html/js/cmn/lib/LAB.js +348 -0
  144. data/template/src/html/min/.htaccess +4 -0
  145. data/template/src/html/min/MinifyCLI.php +19 -0
  146. data/template/src/html/min/README.txt +132 -0
  147. data/template/src/html/min/builder/_index.js +242 -0
  148. data/template/src/html/min/builder/bm.js +36 -0
  149. data/template/src/html/min/builder/index.php +182 -0
  150. data/template/src/html/min/builder/ocCheck.php +36 -0
  151. data/template/src/html/min/builder/rewriteTest.js +1 -0
  152. data/template/src/html/min/config.php +187 -0
  153. data/template/src/html/min/groupsConfig.php +34 -0
  154. data/template/src/html/min/index.php +66 -0
  155. data/template/src/html/min/lib/FirePHP.php +1370 -0
  156. data/template/src/html/min/lib/HTTP/ConditionalGet.php +348 -0
  157. data/template/src/html/min/lib/HTTP/Encoder.php +326 -0
  158. data/template/src/html/min/lib/JSMin.php +314 -0
  159. data/template/src/html/min/lib/JSMinPlus.php +1872 -0
  160. data/template/src/html/min/lib/Minify.php +532 -0
  161. data/template/src/html/min/lib/Minify/Build.php +103 -0
  162. data/template/src/html/min/lib/Minify/CSS.php +83 -0
  163. data/template/src/html/min/lib/Minify/CSS/Compressor.php +250 -0
  164. data/template/src/html/min/lib/Minify/CSS/UriRewriter.php +270 -0
  165. data/template/src/html/min/lib/Minify/Cache/APC.php +130 -0
  166. data/template/src/html/min/lib/Minify/Cache/File.php +125 -0
  167. data/template/src/html/min/lib/Minify/Cache/Memcache.php +137 -0
  168. data/template/src/html/min/lib/Minify/ClosureCompiler.php +85 -0
  169. data/template/src/html/min/lib/Minify/CommentPreserver.php +90 -0
  170. data/template/src/html/min/lib/Minify/Controller/Base.php +202 -0
  171. data/template/src/html/min/lib/Minify/Controller/Files.php +78 -0
  172. data/template/src/html/min/lib/Minify/Controller/Groups.php +94 -0
  173. data/template/src/html/min/lib/Minify/Controller/MinApp.php +132 -0
  174. data/template/src/html/min/lib/Minify/Controller/Page.php +82 -0
  175. data/template/src/html/min/lib/Minify/Controller/Version1.php +118 -0
  176. data/template/src/html/min/lib/Minify/HTML.php +245 -0
  177. data/template/src/html/min/lib/Minify/ImportProcessor.php +157 -0
  178. data/template/src/html/min/lib/Minify/Lines.php +131 -0
  179. data/template/src/html/min/lib/Minify/Logger.php +45 -0
  180. data/template/src/html/min/lib/Minify/Packer.php +37 -0
  181. data/template/src/html/min/lib/Minify/Source.php +187 -0
  182. data/template/src/html/min/lib/Minify/YUICompressor.php +139 -0
  183. data/template/src/html/min/lib/Solar/Dir.php +199 -0
  184. data/template/src/html/min/lib/closure-compiler.jar +0 -0
  185. data/template/src/html/min/lib/yuicompressor-2.4.2.jar +0 -0
  186. data/template/src/html/min/utils.php +90 -0
  187. data/template/src/templates/css/template.css +7 -0
  188. data/template/src/templates/js/template.js +72 -0
  189. data/template/src/templates/template.html +18 -0
  190. data/template/src/yaml/config.yml +46 -0
  191. data/template/src/yaml/deploy.yml +35 -0
  192. data/test/bixbite_test.rb +7 -0
  193. data/test/test_helper.rb +10 -0
  194. metadata +278 -0
@@ -0,0 +1,157 @@
1
+ <?php
2
+ /**
3
+ * Class Minify_ImportProcessor
4
+ * @package Minify
5
+ */
6
+
7
+ /**
8
+ * Linearize a CSS/JS file by including content specified by CSS import
9
+ * declarations. In CSS files, relative URIs are fixed.
10
+ *
11
+ * @imports will be processed regardless of where they appear in the source
12
+ * files; i.e. @imports commented out or in string content will still be
13
+ * processed!
14
+ *
15
+ * This has a unit test but should be considered "experimental".
16
+ *
17
+ * @package Minify
18
+ * @author Stephen Clay <steve@mrclay.org>
19
+ */
20
+ class Minify_ImportProcessor {
21
+
22
+ public static $filesIncluded = array();
23
+
24
+ public static function process($file)
25
+ {
26
+ self::$filesIncluded = array();
27
+ self::$_isCss = (strtolower(substr($file, -4)) === '.css');
28
+ $obj = new Minify_ImportProcessor(dirname($file));
29
+ return $obj->_getContent($file);
30
+ }
31
+
32
+ // allows callback funcs to know the current directory
33
+ private $_currentDir = null;
34
+
35
+ // allows _importCB to write the fetched content back to the obj
36
+ private $_importedContent = '';
37
+
38
+ private static $_isCss = null;
39
+
40
+ private function __construct($currentDir)
41
+ {
42
+ $this->_currentDir = $currentDir;
43
+ }
44
+
45
+ private function _getContent($file)
46
+ {
47
+ $file = realpath($file);
48
+ if (! $file
49
+ || in_array($file, self::$filesIncluded)
50
+ || false === ($content = @file_get_contents($file))
51
+ ) {
52
+ // file missing, already included, or failed read
53
+ return '';
54
+ }
55
+ self::$filesIncluded[] = realpath($file);
56
+ $this->_currentDir = dirname($file);
57
+
58
+ // remove UTF-8 BOM if present
59
+ if (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3)) {
60
+ $content = substr($content, 3);
61
+ }
62
+ // ensure uniform EOLs
63
+ $content = str_replace("\r\n", "\n", $content);
64
+
65
+ // process @imports
66
+ $content = preg_replace_callback(
67
+ '/
68
+ @import\\s+
69
+ (?:url\\(\\s*)? # maybe url(
70
+ [\'"]? # maybe quote
71
+ (.*?) # 1 = URI
72
+ [\'"]? # maybe end quote
73
+ (?:\\s*\\))? # maybe )
74
+ ([a-zA-Z,\\s]*)? # 2 = media list
75
+ ; # end token
76
+ /x'
77
+ ,array($this, '_importCB')
78
+ ,$content
79
+ );
80
+
81
+ if (self::$_isCss) {
82
+ // rewrite remaining relative URIs
83
+ $content = preg_replace_callback(
84
+ '/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
85
+ ,array($this, '_urlCB')
86
+ ,$content
87
+ );
88
+ }
89
+
90
+ return $this->_importedContent . $content;
91
+ }
92
+
93
+ private function _importCB($m)
94
+ {
95
+ $url = $m[1];
96
+ $mediaList = preg_replace('/\\s+/', '', $m[2]);
97
+
98
+ if (strpos($url, '://') > 0) {
99
+ // protocol, leave in place for CSS, comment for JS
100
+ return self::$_isCss
101
+ ? $m[0]
102
+ : "/* Minify_ImportProcessor will not include remote content */";
103
+ }
104
+ if ('/' === $url[0]) {
105
+ // protocol-relative or root path
106
+ $url = ltrim($url, '/');
107
+ $file = realpath($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR
108
+ . strtr($url, '/', DIRECTORY_SEPARATOR);
109
+ } else {
110
+ // relative to current path
111
+ $file = $this->_currentDir . DIRECTORY_SEPARATOR
112
+ . strtr($url, '/', DIRECTORY_SEPARATOR);
113
+ }
114
+ $obj = new Minify_ImportProcessor(dirname($file));
115
+ $content = $obj->_getContent($file);
116
+ if ('' === $content) {
117
+ // failed. leave in place for CSS, comment for JS
118
+ return self::$_isCss
119
+ ? $m[0]
120
+ : "/* Minify_ImportProcessor could not fetch '{$file}' */";;
121
+ }
122
+ return (!self::$_isCss || preg_match('@(?:^$|\\ball\\b)@', $mediaList))
123
+ ? $content
124
+ : "@media {$mediaList} {\n{$content}\n}\n";
125
+ }
126
+
127
+ private function _urlCB($m)
128
+ {
129
+ // $m[1] is either quoted or not
130
+ $quote = ($m[1][0] === "'" || $m[1][0] === '"')
131
+ ? $m[1][0]
132
+ : '';
133
+ $url = ($quote === '')
134
+ ? $m[1]
135
+ : substr($m[1], 1, strlen($m[1]) - 2);
136
+ if ('/' !== $url[0]) {
137
+ if (strpos($url, '//') > 0) {
138
+ // probably starts with protocol, do not alter
139
+ } else {
140
+ // prepend path with current dir separator (OS-independent)
141
+ $path = $this->_currentDir
142
+ . DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
143
+ // strip doc root
144
+ $path = substr($path, strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
145
+ // fix to absolute URL
146
+ $url = strtr($path, '/\\', '//');
147
+ // remove /./ and /../ where possible
148
+ $url = str_replace('/./', '/', $url);
149
+ // inspired by patch from Oleg Cherniy
150
+ do {
151
+ $url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, 1, $changed);
152
+ } while ($changed);
153
+ }
154
+ }
155
+ return "url({$quote}{$url}{$quote})";
156
+ }
157
+ }
@@ -0,0 +1,131 @@
1
+ <?php
2
+ /**
3
+ * Class Minify_Lines
4
+ * @package Minify
5
+ */
6
+
7
+ /**
8
+ * Add line numbers in C-style comments for easier debugging of combined content
9
+ *
10
+ * @package Minify
11
+ * @author Stephen Clay <steve@mrclay.org>
12
+ * @author Adam Pedersen (Issue 55 fix)
13
+ */
14
+ class Minify_Lines {
15
+
16
+ /**
17
+ * Add line numbers in C-style comments
18
+ *
19
+ * This uses a very basic parser easily fooled by comment tokens inside
20
+ * strings or regexes, but, otherwise, generally clean code will not be
21
+ * mangled. URI rewriting can also be performed.
22
+ *
23
+ * @param string $content
24
+ *
25
+ * @param array $options available options:
26
+ *
27
+ * 'id': (optional) string to identify file. E.g. file name/path
28
+ *
29
+ * 'currentDir': (default null) if given, this is assumed to be the
30
+ * directory of the current CSS file. Using this, minify will rewrite
31
+ * all relative URIs in import/url declarations to correctly point to
32
+ * the desired files, and prepend a comment with debugging information about
33
+ * this process.
34
+ *
35
+ * @return string
36
+ */
37
+ public static function minify($content, $options = array())
38
+ {
39
+ $id = (isset($options['id']) && $options['id'])
40
+ ? $options['id']
41
+ : '';
42
+ $content = str_replace("\r\n", "\n", $content);
43
+ $lines = explode("\n", $content);
44
+ $numLines = count($lines);
45
+ // determine left padding
46
+ $padTo = strlen($numLines);
47
+ $inComment = false;
48
+ $i = 0;
49
+ $newLines = array();
50
+ while (null !== ($line = array_shift($lines))) {
51
+ if (('' !== $id) && (0 == $i % 50)) {
52
+ array_push($newLines, '', "/* {$id} */", '');
53
+ }
54
+ ++$i;
55
+ $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
56
+ $inComment = self::_eolInComment($line, $inComment);
57
+ }
58
+ $content = implode("\n", $newLines) . "\n";
59
+
60
+ // check for desired URI rewriting
61
+ if (isset($options['currentDir'])) {
62
+ require_once 'Minify/CSS/UriRewriter.php';
63
+ Minify_CSS_UriRewriter::$debugText = '';
64
+ $content = Minify_CSS_UriRewriter::rewrite(
65
+ $content
66
+ ,$options['currentDir']
67
+ ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
68
+ ,isset($options['symlinks']) ? $options['symlinks'] : array()
69
+ );
70
+ $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
71
+ . Minify_CSS_UriRewriter::$debugText . "*/\n"
72
+ . $content;
73
+ }
74
+
75
+ return $content;
76
+ }
77
+
78
+ /**
79
+ * Is the parser within a C-style comment at the end of this line?
80
+ *
81
+ * @param string $line current line of code
82
+ *
83
+ * @param bool $inComment was the parser in a comment at the
84
+ * beginning of the line?
85
+ *
86
+ * @return bool
87
+ */
88
+ private static function _eolInComment($line, $inComment)
89
+ {
90
+ while (strlen($line)) {
91
+ $search = $inComment
92
+ ? '*/'
93
+ : '/*';
94
+ $pos = strpos($line, $search);
95
+ if (false === $pos) {
96
+ return $inComment;
97
+ } else {
98
+ if ($pos == 0
99
+ || ($inComment
100
+ ? substr($line, $pos, 3)
101
+ : substr($line, $pos-1, 3)) != '*/*')
102
+ {
103
+ $inComment = ! $inComment;
104
+ }
105
+ $line = substr($line, $pos + 2);
106
+ }
107
+ }
108
+ return $inComment;
109
+ }
110
+
111
+ /**
112
+ * Prepend a comment (or note) to the given line
113
+ *
114
+ * @param string $line current line of code
115
+ *
116
+ * @param string $note content of note/comment
117
+ *
118
+ * @param bool $inComment was the parser in a comment at the
119
+ * beginning of the line?
120
+ *
121
+ * @param int $padTo minimum width of comment
122
+ *
123
+ * @return string
124
+ */
125
+ private static function _addNote($line, $note, $inComment, $padTo)
126
+ {
127
+ return $inComment
128
+ ? '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line
129
+ : '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line;
130
+ }
131
+ }
@@ -0,0 +1,45 @@
1
+ <?php
2
+ /**
3
+ * Class Minify_Logger
4
+ * @package Minify
5
+ */
6
+
7
+ /**
8
+ * Message logging class
9
+ *
10
+ * @package Minify
11
+ * @author Stephen Clay <steve@mrclay.org>
12
+ */
13
+ class Minify_Logger {
14
+
15
+ /**
16
+ * Set logger object.
17
+ *
18
+ * The object should have a method "log" that accepts a value as 1st argument and
19
+ * an optional string label as the 2nd.
20
+ *
21
+ * @param mixed $obj or a "falsey" value to disable
22
+ * @return null
23
+ */
24
+ public static function setLogger($obj = null) {
25
+ self::$_logger = $obj
26
+ ? $obj
27
+ : null;
28
+ }
29
+
30
+ /**
31
+ * Pass a message to the logger (if set)
32
+ *
33
+ * @param string $msg message to log
34
+ * @return null
35
+ */
36
+ public static function log($msg, $label = 'Minify') {
37
+ if (! self::$_logger) return;
38
+ self::$_logger->log($msg, $label);
39
+ }
40
+
41
+ /**
42
+ * @var mixed logger object (like FirePHP) or null (i.e. no logger available)
43
+ */
44
+ private static $_logger = null;
45
+ }
@@ -0,0 +1,37 @@
1
+ <?php
2
+ /**
3
+ * Class Minify_Packer
4
+ *
5
+ * To use this class you must first download the PHP port of Packer
6
+ * and place the file "class.JavaScriptPacker.php" in /lib (or your
7
+ * include_path).
8
+ * @link http://joliclic.free.fr/php/javascript-packer/en/
9
+ *
10
+ * Be aware that, as long as HTTP encoding is used, scripts minified with JSMin
11
+ * will provide better client-side performance, as they need not be unpacked in
12
+ * client-side code.
13
+ *
14
+ * @package Minify
15
+ */
16
+
17
+ if (false === (@include 'class.JavaScriptPacker.php')) {
18
+ trigger_error(
19
+ 'The script "class.JavaScriptPacker.php" is required. Please see: http:'
20
+ .'//code.google.com/p/minify/source/browse/trunk/min/lib/Minify/Packer.php'
21
+ ,E_USER_ERROR
22
+ );
23
+ }
24
+
25
+ /**
26
+ * Minify Javascript using Dean Edward's Packer
27
+ *
28
+ * @package Minify
29
+ */
30
+ class Minify_Packer {
31
+ public static function minify($code, $options = array())
32
+ {
33
+ // @todo: set encoding options based on $options :)
34
+ $packer = new JavascriptPacker($code, 'Normal', true, false);
35
+ return trim($packer->pack());
36
+ }
37
+ }
@@ -0,0 +1,187 @@
1
+ <?php
2
+ /**
3
+ * Class Minify_Source
4
+ * @package Minify
5
+ */
6
+
7
+ /**
8
+ * A content source to be minified by Minify.
9
+ *
10
+ * This allows per-source minification options and the mixing of files with
11
+ * content from other sources.
12
+ *
13
+ * @package Minify
14
+ * @author Stephen Clay <steve@mrclay.org>
15
+ */
16
+ class Minify_Source {
17
+
18
+ /**
19
+ * @var int time of last modification
20
+ */
21
+ public $lastModified = null;
22
+
23
+ /**
24
+ * @var callback minifier function specifically for this source.
25
+ */
26
+ public $minifier = null;
27
+
28
+ /**
29
+ * @var array minification options specific to this source.
30
+ */
31
+ public $minifyOptions = null;
32
+
33
+ /**
34
+ * @var string full path of file
35
+ */
36
+ public $filepath = null;
37
+
38
+ /**
39
+ * @var string HTTP Content Type (Minify requires one of the constants Minify::TYPE_*)
40
+ */
41
+ public $contentType = null;
42
+
43
+ /**
44
+ * Create a Minify_Source
45
+ *
46
+ * In the $spec array(), you can either provide a 'filepath' to an existing
47
+ * file (existence will not be checked!) or give 'id' (unique string for
48
+ * the content), 'content' (the string content) and 'lastModified'
49
+ * (unixtime of last update).
50
+ *
51
+ * As a shortcut, the controller will replace "//" at the beginning
52
+ * of a filepath with $_SERVER['DOCUMENT_ROOT'] . '/'.
53
+ *
54
+ * @param array $spec options
55
+ */
56
+ public function __construct($spec)
57
+ {
58
+ if (isset($spec['filepath'])) {
59
+ if (0 === strpos($spec['filepath'], '//')) {
60
+ $spec['filepath'] = $_SERVER['DOCUMENT_ROOT'] . substr($spec['filepath'], 1);
61
+ }
62
+ $segments = explode('.', $spec['filepath']);
63
+ $ext = strtolower(array_pop($segments));
64
+ switch ($ext) {
65
+ case 'js' : $this->contentType = 'application/x-javascript';
66
+ break;
67
+ case 'css' : $this->contentType = 'text/css';
68
+ break;
69
+ case 'htm' : // fallthrough
70
+ case 'html' : $this->contentType = 'text/html';
71
+ break;
72
+ }
73
+ $this->filepath = $spec['filepath'];
74
+ $this->_id = $spec['filepath'];
75
+ $this->lastModified = filemtime($spec['filepath'])
76
+ // offset for Windows uploaders with out of sync clocks
77
+ + round(Minify::$uploaderHoursBehind * 3600);
78
+ } elseif (isset($spec['id'])) {
79
+ $this->_id = 'id::' . $spec['id'];
80
+ if (isset($spec['content'])) {
81
+ $this->_content = $spec['content'];
82
+ } else {
83
+ $this->_getContentFunc = $spec['getContentFunc'];
84
+ }
85
+ $this->lastModified = isset($spec['lastModified'])
86
+ ? $spec['lastModified']
87
+ : time();
88
+ }
89
+ if (isset($spec['contentType'])) {
90
+ $this->contentType = $spec['contentType'];
91
+ }
92
+ if (isset($spec['minifier'])) {
93
+ $this->minifier = $spec['minifier'];
94
+ }
95
+ if (isset($spec['minifyOptions'])) {
96
+ $this->minifyOptions = $spec['minifyOptions'];
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Get content
102
+ *
103
+ * @return string
104
+ */
105
+ public function getContent()
106
+ {
107
+ $content = (null !== $this->filepath)
108
+ ? file_get_contents($this->filepath)
109
+ : ((null !== $this->_content)
110
+ ? $this->_content
111
+ : call_user_func($this->_getContentFunc, $this->_id)
112
+ );
113
+ // remove UTF-8 BOM if present
114
+ return (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3))
115
+ ? substr($content, 3)
116
+ : $content;
117
+ }
118
+
119
+ /**
120
+ * Get id
121
+ *
122
+ * @return string
123
+ */
124
+ public function getId()
125
+ {
126
+ return $this->_id;
127
+ }
128
+
129
+ /**
130
+ * Verifies a single minification call can handle all sources
131
+ *
132
+ * @param array $sources Minify_Source instances
133
+ *
134
+ * @return bool true iff there no sources with specific minifier preferences.
135
+ */
136
+ public static function haveNoMinifyPrefs($sources)
137
+ {
138
+ foreach ($sources as $source) {
139
+ if (null !== $source->minifier
140
+ || null !== $source->minifyOptions) {
141
+ return false;
142
+ }
143
+ }
144
+ return true;
145
+ }
146
+
147
+ /**
148
+ * Get unique string for a set of sources
149
+ *
150
+ * @param array $sources Minify_Source instances
151
+ *
152
+ * @return string
153
+ */
154
+ public static function getDigest($sources)
155
+ {
156
+ foreach ($sources as $source) {
157
+ $info[] = array(
158
+ $source->_id, $source->minifier, $source->minifyOptions
159
+ );
160
+ }
161
+ return md5(serialize($info));
162
+ }
163
+
164
+ /**
165
+ * Get content type from a group of sources
166
+ *
167
+ * This is called if the user doesn't pass in a 'contentType' options
168
+ *
169
+ * @param array $sources Minify_Source instances
170
+ *
171
+ * @return string content type. e.g. 'text/css'
172
+ */
173
+ public static function getContentType($sources)
174
+ {
175
+ foreach ($sources as $source) {
176
+ if ($source->contentType !== null) {
177
+ return $source->contentType;
178
+ }
179
+ }
180
+ return 'text/plain';
181
+ }
182
+
183
+ protected $_content = null;
184
+ protected $_getContentFunc = null;
185
+ protected $_id = null;
186
+ }
187
+