選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

426 行
10 KiB

  1. in_files_main = [
  2. 'utils/rsh.compressed.js'
  3. ,'globals.js'
  4. ,'utils/datatype.js'
  5. ,'utils/browser_detect.js'
  6. ,'utils/datetime.js'
  7. ,'utils/dom.js'
  8. ,'utils/handler.js'
  9. ,'utils/msgprint.js'
  10. ,'utils/json.js'
  11. ,'utils/shortcut.js'
  12. ,'utils/printElement.js'
  13. ,'wn/widgets/dialog.js'
  14. ,'widgets/dialog.js'
  15. ,'widgets/listing.js'
  16. ,'wn/widgets/listing.js'
  17. ,'widgets/tree.js'
  18. ,'widgets/menu.js'
  19. ,'widgets/layout.js'
  20. ,'widgets/tabbedpage.js'
  21. ,'webpage/page_header.js'
  22. ,'widgets/autosuggest.js'
  23. ,'widgets/select.js'
  24. ,'widgets/tags.js'
  25. ,'widgets/export_query.js'
  26. ,'widgets/list_selector.js'
  27. ,'widgets/form/fields.js'
  28. ,'webpage/wntoolbar.js'
  29. ,'webpage/history.js'
  30. ,'webpage/search.js'
  31. ,'webpage/spinner.js'
  32. ,'webpage/freeze_page.js'
  33. ,'webpage/error_console.js'
  34. ,'webpage/about.js'
  35. ,'webpage/loaders.js'
  36. ,'webpage/uploader.js'
  37. ,'webpage/page.js'
  38. ,'webpage/docbrowser.js'
  39. ,'wn/page_layout.js'
  40. #,'wn/widgets/doc_column_view.js'
  41. ,'wn/widgets/page_sidebar.js'
  42. ,'wn/widgets/footer.js'
  43. #,'wn/widgets/follow.js'
  44. ,'model/local_data.js'
  45. ,'model/doclist.js'
  46. ,'webpage/body.js'
  47. ,'app.js'
  48. ,'widgets/calendar.js'
  49. ]
  50. out_file_main = 'js/wnf.compressed.js'
  51. #-------------------------------------------------
  52. in_files_lite = [
  53. 'utils/rsh.compressed.js'
  54. ,'globals.js'
  55. ,'utils/datatype.js'
  56. ,'utils/browser_detect.js'
  57. ,'utils/datetime.js'
  58. ,'utils/dom.js'
  59. ,'utils/handler.js'
  60. ,'utils/msgprint.js'
  61. ,'utils/json.js'
  62. ,'wn/widgets/dialog.js'
  63. ,'widgets/dialog.js'
  64. ,'widgets/listing.js'
  65. ,'widgets/layout.js'
  66. ,'widgets/tabbedpage.js'
  67. ,'webpage/page_header.js'
  68. ,'widgets/autosuggest.js'
  69. ,'widgets/tags.js'
  70. ,'widgets/form/fields.js'
  71. ,'webpage/history.js'
  72. ,'webpage/search.js'
  73. ,'webpage/spinner.js'
  74. ,'webpage/freeze_page.js'
  75. ,'webpage/error_console.js'
  76. ,'webpage/about.js'
  77. ,'webpage/loaders.js'
  78. ,'webpage/uploader.js'
  79. ,'webpage/page.js'
  80. ,'wn/widgets/page_sidebar.js'
  81. ,'wn/widgets/follow.js'
  82. ,'model/local_data.js'
  83. ,'model/doclist.js'
  84. ,'webpage/body.js'
  85. ,'app.js'
  86. ]
  87. out_file_lite = 'js/wnf-lite.compressed.js'
  88. #-------------------------------------------------
  89. in_files_form = [
  90. 'widgets/form/form_container.js'
  91. ,'widgets/form/form_header.js'
  92. ,'widgets/form/form.js'
  93. ,'widgets/form/form_fields.js'
  94. ,'widgets/form/grid.js'
  95. ,'widgets/form/form_grid.js'
  96. ,'widgets/form/print_format.js'
  97. ,'widgets/form/email.js'
  98. ,'widgets/form/clientscriptAPI.js'
  99. ,'widgets/form/form_comments.js'
  100. ,'wn/widgets/form/sidebar.js'
  101. ,'wn/widgets/form/comments.js'
  102. ,'wn/widgets/form/attachments.js'
  103. ]
  104. out_file_form = 'js/form.compressed.js';
  105. in_files_report = [
  106. 'widgets/report_builder/bargraph.js'
  107. ,'widgets/report_builder/report_builder.js'
  108. ,'widgets/report_builder/datatable.js'
  109. ,'widgets/report_builder/calculator.js'
  110. ]
  111. out_file_report = 'js/report.compressed.js'
  112. in_files_css = [
  113. 'css/body.css',
  114. 'css/menus.css',
  115. 'css/messages.css',
  116. 'css/forms.css',
  117. 'css/grid.css',
  118. 'css/listing.css',
  119. 'css/report.css',
  120. 'css/calendar.css',
  121. 'css/autosuggest.css',
  122. 'css/dialog.css',
  123. 'css/wntoolbar.css',
  124. 'css/tabs.css',
  125. 'css/jqplot.css',
  126. 'css/bw-icons.css',
  127. 'css/sidebar.css',
  128. 'css/doc_column_view.css',
  129. ]
  130. out_file_css = 'css/default.css'
  131. #in_files_main += in_files_form
  132. import os, os.path, shutil
  133. # This code is original from jsmin by Douglas Crockford, it was translated to
  134. # Python by Baruch Even. The original code had the following copyright and
  135. # license.
  136. #
  137. # /* jsmin.c
  138. # 2007-05-22
  139. #
  140. # Copyright (c) 2002 Douglas Crockford (www.crockford.com)
  141. #
  142. # Permission is hereby granted, free of charge, to any person obtaining a copy of
  143. # this software and associated documentation files (the "Software"), to deal in
  144. # the Software without restriction, including without limitation the rights to
  145. # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  146. # of the Software, and to permit persons to whom the Software is furnished to do
  147. # so, subject to the following conditions:
  148. #
  149. # The above copyright notice and this permission notice shall be included in all
  150. # copies or substantial portions of the Software.
  151. #
  152. # The Software shall be used for Good, not Evil.
  153. #
  154. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  155. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  156. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  157. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  158. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  159. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  160. # SOFTWARE.
  161. # */
  162. from StringIO import StringIO
  163. def jsmin(js):
  164. ins = StringIO(js)
  165. outs = StringIO()
  166. JavascriptMinify().minify(ins, outs)
  167. str = outs.getvalue()
  168. if len(str) > 0 and str[0] == '\n':
  169. str = str[1:]
  170. return str
  171. def isAlphanum(c):
  172. """return true if the character is a letter, digit, underscore,
  173. dollar sign, or non-ASCII character.
  174. """
  175. return ((c >= 'a' and c <= 'z') or (c >= '0' and c <= '9') or
  176. (c >= 'A' and c <= 'Z') or c == '_' or c == '$' or c == '\\' or (c is not None and ord(c) > 126));
  177. class UnterminatedComment(Exception):
  178. pass
  179. class UnterminatedStringLiteral(Exception):
  180. pass
  181. class UnterminatedRegularExpression(Exception):
  182. pass
  183. class JavascriptMinify(object):
  184. def _outA(self):
  185. self.outstream.write(self.theA)
  186. def _outB(self):
  187. self.outstream.write(self.theB)
  188. def _get(self):
  189. """return the next character from stdin. Watch out for lookahead. If
  190. the character is a control character, translate it to a space or
  191. linefeed.
  192. """
  193. c = self.theLookahead
  194. self.theLookahead = None
  195. if c == None:
  196. c = self.instream.read(1)
  197. if c >= ' ' or c == '\n':
  198. return c
  199. if c == '': # EOF
  200. return '\000'
  201. if c == '\r':
  202. return '\n'
  203. return ' '
  204. def _peek(self):
  205. self.theLookahead = self._get()
  206. return self.theLookahead
  207. def _next(self):
  208. """get the next character, excluding comments. peek() is used to see
  209. if an unescaped '/' is followed by a '/' or '*'.
  210. """
  211. c = self._get()
  212. if c == '/' and self.theA != '\\':
  213. p = self._peek()
  214. if p == '/':
  215. c = self._get()
  216. while c > '\n':
  217. c = self._get()
  218. return c
  219. if p == '*':
  220. c = self._get()
  221. while 1:
  222. c = self._get()
  223. if c == '*':
  224. if self._peek() == '/':
  225. self._get()
  226. return ' '
  227. if c == '\000':
  228. raise UnterminatedComment()
  229. return c
  230. def _action(self, action):
  231. """do something! What you do is determined by the argument:
  232. 1 Output A. Copy B to A. Get the next B.
  233. 2 Copy B to A. Get the next B. (Delete A).
  234. 3 Get the next B. (Delete B).
  235. action treats a string as a single character. Wow!
  236. action recognizes a regular expression if it is preceded by ( or , or =.
  237. """
  238. if action <= 1:
  239. self._outA()
  240. if action <= 2:
  241. self.theA = self.theB
  242. if self.theA == "'" or self.theA == '"':
  243. while 1:
  244. self._outA()
  245. self.theA = self._get()
  246. if self.theA == self.theB:
  247. break
  248. if self.theA <= '\n':
  249. raise UnterminatedStringLiteral()
  250. if self.theA == '\\':
  251. self._outA()
  252. self.theA = self._get()
  253. if action <= 3:
  254. self.theB = self._next()
  255. if self.theB == '/' and (self.theA == '(' or self.theA == ',' or
  256. self.theA == '=' or self.theA == ':' or
  257. self.theA == '[' or self.theA == '?' or
  258. self.theA == '!' or self.theA == '&' or
  259. self.theA == '|' or self.theA == ';' or
  260. self.theA == '{' or self.theA == '}' or
  261. self.theA == '\n'):
  262. self._outA()
  263. self._outB()
  264. while 1:
  265. self.theA = self._get()
  266. if self.theA == '/':
  267. break
  268. elif self.theA == '\\':
  269. self._outA()
  270. self.theA = self._get()
  271. elif self.theA <= '\n':
  272. raise UnterminatedRegularExpression()
  273. self._outA()
  274. self.theB = self._next()
  275. def _jsmin(self):
  276. """Copy the input to the output, deleting the characters which are
  277. insignificant to JavaScript. Comments will be removed. Tabs will be
  278. replaced with spaces. Carriage returns will be replaced with linefeeds.
  279. Most spaces and linefeeds will be removed.
  280. """
  281. self.theA = '\n'
  282. self._action(3)
  283. while self.theA != '\000':
  284. if self.theA == ' ':
  285. if isAlphanum(self.theB):
  286. self._action(1)
  287. else:
  288. self._action(2)
  289. elif self.theA == '\n':
  290. if self.theB in ['{', '[', '(', '+', '-']:
  291. self._action(1)
  292. elif self.theB == ' ':
  293. self._action(3)
  294. else:
  295. if isAlphanum(self.theB):
  296. self._action(1)
  297. else:
  298. self._action(2)
  299. else:
  300. if self.theB == ' ':
  301. if isAlphanum(self.theA):
  302. self._action(1)
  303. else:
  304. self._action(3)
  305. elif self.theB == '\n':
  306. if self.theA in ['}', ']', ')', '+', '-', '"', '\'']:
  307. self._action(1)
  308. else:
  309. if isAlphanum(self.theA):
  310. self._action(1)
  311. else:
  312. self._action(3)
  313. else:
  314. self._action(1)
  315. def minify(self, instream, outstream):
  316. self.instream = instream
  317. self.outstream = outstream
  318. self.theA = '\n'
  319. self.theB = None
  320. self.theLookahead = None
  321. self._jsmin()
  322. self.instream.close()
  323. def combine_css():
  324. global out_file_css, in_files_css
  325. data = ''
  326. for f in in_files_css:
  327. fh = open(f, 'read')
  328. data += fh.read() + '\n'
  329. fh.close()
  330. out_file = open(out_file_css, 'w')
  331. out_file.write(data)
  332. out_file.close()
  333. def _compress(in_files, out_file, in_type='js', verbose=False,
  334. temp_file='.temp'):
  335. import os
  336. temp = open(temp_file, 'w')
  337. for f in in_files:
  338. print f + ' | ' + str(int(os.path.getsize('js/'+f)/1024)) + 'k'
  339. fh = open('js/' + f)
  340. data = fh.read() + '\n'
  341. fh.close()
  342. temp.write(data)
  343. #print ' + %s' % f
  344. temp.close()
  345. out = open(out_file, 'w')
  346. jsm = JavascriptMinify()
  347. jsm.minify(open(temp_file,'r'), out)
  348. out.close()
  349. org_size = os.path.getsize(temp_file)
  350. new_size = os.path.getsize(out_file)
  351. print '=> %s' % out_file
  352. print 'Original: %.2f kB' % (org_size / 1024.0)
  353. print 'Compressed: %.2f kB' % (new_size / 1024.0)
  354. print 'Reduction: %.1f%%' % (float(org_size - new_size) / org_size * 100)
  355. print ''
  356. os.remove(temp_file)
  357. if __name__=='__main__':
  358. import sys
  359. if sys.argv[1]=='main':
  360. _compress(in_files_main, out_file_main)
  361. elif sys.argv[1]=='lite':
  362. _compress(in_files_lite, out_file_lite)
  363. elif sys.argv[1]=='form':
  364. _compress(in_files_form, out_file_form)
  365. elif sys.argv[1]=='report':
  366. _compress(in_files_report, out_file_report)
  367. elif sys.argv[1]=='css':
  368. combine_css()
  369. else:
  370. print 'parameter must be one of main, lite, css, form or report'