clivecrous-ramaze 0.3.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (548) hide show
  1. data/README.markdown +444 -0
  2. data/Rakefile +197 -0
  3. data/bin/ramaze +60 -0
  4. data/doc/AUTHORS +30 -0
  5. data/doc/CHANGELOG +5757 -0
  6. data/doc/COPYING +56 -0
  7. data/doc/FAQ +92 -0
  8. data/doc/GPL +339 -0
  9. data/doc/INSTALL +34 -0
  10. data/doc/LEGAL +26 -0
  11. data/doc/ProjectInfo +53 -0
  12. data/doc/TODO +29 -0
  13. data/doc/meta/announcement.txt +126 -0
  14. data/doc/meta/configuration.txt +162 -0
  15. data/doc/meta/internals.txt +278 -0
  16. data/doc/meta/users.kml +64 -0
  17. data/doc/migrate/1110_to_1111.txt +131 -0
  18. data/doc/readme_chunks/appendix.txt +10 -0
  19. data/doc/readme_chunks/examples.txt +38 -0
  20. data/doc/readme_chunks/features.txt +148 -0
  21. data/doc/readme_chunks/getting_help.txt +5 -0
  22. data/doc/readme_chunks/getting_started.txt +18 -0
  23. data/doc/readme_chunks/installing.txt +55 -0
  24. data/doc/readme_chunks/introduction.txt +18 -0
  25. data/doc/readme_chunks/principles.txt +56 -0
  26. data/doc/readme_chunks/thanks.txt +59 -0
  27. data/doc/tutorial/todolist.html +816 -0
  28. data/doc/tutorial/todolist.mkd +736 -0
  29. data/examples/auth/auth.rb +54 -0
  30. data/examples/auth/template/layout.haml +20 -0
  31. data/examples/auth/template/login.haml +16 -0
  32. data/examples/blog/README +3 -0
  33. data/examples/blog/controller/main.rb +29 -0
  34. data/examples/blog/model/entry.rb +30 -0
  35. data/examples/blog/public/styles/blog.css +132 -0
  36. data/examples/blog/spec/blog.rb +87 -0
  37. data/examples/blog/start.rb +7 -0
  38. data/examples/blog/view/edit.xhtml +17 -0
  39. data/examples/blog/view/index.xhtml +17 -0
  40. data/examples/blog/view/layout.xhtml +11 -0
  41. data/examples/blog/view/new.xhtml +16 -0
  42. data/examples/caching.rb +31 -0
  43. data/examples/chat/model/history.rb +36 -0
  44. data/examples/chat/model/message.rb +7 -0
  45. data/examples/chat/public/js/jquery.js +3436 -0
  46. data/examples/chat/start.rb +40 -0
  47. data/examples/chat/view/chat.xhtml +29 -0
  48. data/examples/chat/view/index.xhtml +6 -0
  49. data/examples/chat/view/layout.xhtml +12 -0
  50. data/examples/css.rb +37 -0
  51. data/examples/element.rb +45 -0
  52. data/examples/facebook.rb +159 -0
  53. data/examples/hello.rb +15 -0
  54. data/examples/httpdigest.rb +50 -0
  55. data/examples/identity.rb +18 -0
  56. data/examples/layout.rb +28 -0
  57. data/examples/linking.rb +29 -0
  58. data/examples/localization/start.rb +35 -0
  59. data/examples/memleak_detector.rb +32 -0
  60. data/examples/nitro_form.rb +23 -0
  61. data/examples/provide.rb +23 -0
  62. data/examples/ramaise.rb +132 -0
  63. data/examples/rammit/spec/rammit.rb +31 -0
  64. data/examples/rammit/src/controller/main.rb +3 -0
  65. data/examples/rammit/src/controller/page.rb +16 -0
  66. data/examples/rammit/src/model.rb +33 -0
  67. data/examples/rammit/start.rb +8 -0
  68. data/examples/rammit/template/index.xhtml +14 -0
  69. data/examples/rammit/template/page/view.xhtml +4 -0
  70. data/examples/rapaste/Rakefile +35 -0
  71. data/examples/rapaste/controller/paste.rb +94 -0
  72. data/examples/rapaste/model/paste.rb +55 -0
  73. data/examples/rapaste/public/css/active4d.css +114 -0
  74. data/examples/rapaste/public/css/all_hallows_eve.css +72 -0
  75. data/examples/rapaste/public/css/amy.css +147 -0
  76. data/examples/rapaste/public/css/blackboard.css +88 -0
  77. data/examples/rapaste/public/css/brilliance_black.css +605 -0
  78. data/examples/rapaste/public/css/brilliance_dull.css +599 -0
  79. data/examples/rapaste/public/css/cobalt.css +149 -0
  80. data/examples/rapaste/public/css/dawn.css +121 -0
  81. data/examples/rapaste/public/css/display.css +197 -0
  82. data/examples/rapaste/public/css/eiffel.css +121 -0
  83. data/examples/rapaste/public/css/espresso_libre.css +109 -0
  84. data/examples/rapaste/public/css/idle.css +62 -0
  85. data/examples/rapaste/public/css/iplastic.css +80 -0
  86. data/examples/rapaste/public/css/lazy.css +73 -0
  87. data/examples/rapaste/public/css/mac_classic.css +123 -0
  88. data/examples/rapaste/public/css/magicwb_amiga.css +104 -0
  89. data/examples/rapaste/public/css/pastels_on_dark.css +188 -0
  90. data/examples/rapaste/public/css/slush_poppies.css +85 -0
  91. data/examples/rapaste/public/css/spacecadet.css +51 -0
  92. data/examples/rapaste/public/css/sunburst.css +180 -0
  93. data/examples/rapaste/public/css/twilight.css +137 -0
  94. data/examples/rapaste/public/css/zenburnesque.css +91 -0
  95. data/examples/rapaste/public/js/jquery.js +11 -0
  96. data/examples/rapaste/spec/rapaste.rb +49 -0
  97. data/examples/rapaste/start.rb +24 -0
  98. data/examples/rapaste/view/copy.xhtml +10 -0
  99. data/examples/rapaste/view/index.xhtml +9 -0
  100. data/examples/rapaste/view/layout.xhtml +25 -0
  101. data/examples/rapaste/view/list.xhtml +29 -0
  102. data/examples/rapaste/view/search.xhtml +41 -0
  103. data/examples/rapaste/view/view.xhtml +37 -0
  104. data/examples/rapp.rb +45 -0
  105. data/examples/rest.rb +28 -0
  106. data/examples/sequel_form.rb +24 -0
  107. data/examples/sequel_scaffolding.rb +24 -0
  108. data/examples/simple.rb +56 -0
  109. data/examples/simple_auth.rb +23 -0
  110. data/examples/sourceview/public/coderay.css +104 -0
  111. data/examples/sourceview/public/images/file.gif +0 -0
  112. data/examples/sourceview/public/images/folder.gif +0 -0
  113. data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
  114. data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
  115. data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
  116. data/examples/sourceview/public/images/tv-expandable.gif +0 -0
  117. data/examples/sourceview/public/images/tv-item-last.gif +0 -0
  118. data/examples/sourceview/public/images/tv-item.gif +0 -0
  119. data/examples/sourceview/public/jquery.js +11 -0
  120. data/examples/sourceview/public/jquery.treeview.css +48 -0
  121. data/examples/sourceview/public/jquery.treeview.js +223 -0
  122. data/examples/sourceview/public/sourceview.js +52 -0
  123. data/examples/sourceview/sourceview.rb +77 -0
  124. data/examples/sourceview/template/index.haml +59 -0
  125. data/examples/templates/template/external.amrita +19 -0
  126. data/examples/templates/template/external.haml +22 -0
  127. data/examples/templates/template/external.liquid +28 -0
  128. data/examples/templates/template/external.mab +30 -0
  129. data/examples/templates/template/external.nag +28 -0
  130. data/examples/templates/template/external.redcloth +19 -0
  131. data/examples/templates/template/external.rem +30 -0
  132. data/examples/templates/template/external.rhtml +28 -0
  133. data/examples/templates/template/external.tenjin +28 -0
  134. data/examples/templates/template/external.xsl +57 -0
  135. data/examples/templates/template/external.zmr +28 -0
  136. data/examples/templates/template_amrita2.rb +74 -0
  137. data/examples/templates/template_erubis.rb +53 -0
  138. data/examples/templates/template_ezamar.rb +50 -0
  139. data/examples/templates/template_haml.rb +50 -0
  140. data/examples/templates/template_liquid.rb +65 -0
  141. data/examples/templates/template_markaby.rb +58 -0
  142. data/examples/templates/template_nagoro.rb +51 -0
  143. data/examples/templates/template_redcloth.rb +59 -0
  144. data/examples/templates/template_remarkably.rb +55 -0
  145. data/examples/templates/template_tenjin.rb +53 -0
  146. data/examples/templates/template_xslt.rb +49 -0
  147. data/examples/todolist/README +1 -0
  148. data/examples/todolist/public/favicon.ico +0 -0
  149. data/examples/todolist/public/js/jquery.js +1923 -0
  150. data/examples/todolist/public/ramaze.png +0 -0
  151. data/examples/todolist/spec/todolist.rb +132 -0
  152. data/examples/todolist/src/controller/main.rb +70 -0
  153. data/examples/todolist/src/element/page.rb +31 -0
  154. data/examples/todolist/src/model.rb +14 -0
  155. data/examples/todolist/start.rb +11 -0
  156. data/examples/todolist/template/index.xhtml +17 -0
  157. data/examples/todolist/template/new.xhtml +7 -0
  158. data/examples/upload/start.rb +19 -0
  159. data/examples/upload/view/index.xhtml +25 -0
  160. data/examples/whywiki/spec/whywiki.rb +58 -0
  161. data/examples/whywiki/start.rb +46 -0
  162. data/examples/whywiki/template/edit.xhtml +14 -0
  163. data/examples/whywiki/template/show.xhtml +18 -0
  164. data/examples/wikore/spec/wikore.rb +111 -0
  165. data/examples/wikore/src/controller.rb +80 -0
  166. data/examples/wikore/src/model.rb +52 -0
  167. data/examples/wikore/start.rb +9 -0
  168. data/examples/wikore/template/index.xhtml +8 -0
  169. data/examples/wiktacular/README +2 -0
  170. data/examples/wiktacular/mkd/link/2007-07-20_19-45-51.mkd +1 -0
  171. data/examples/wiktacular/mkd/link/current.mkd +1 -0
  172. data/examples/wiktacular/mkd/main/2007-07-20_16-31-33.mkd +1 -0
  173. data/examples/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -0
  174. data/examples/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +2 -0
  175. data/examples/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +2 -0
  176. data/examples/wiktacular/mkd/main/current.mkd +2 -0
  177. data/examples/wiktacular/mkd/markdown/current.mkd +3 -0
  178. data/examples/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +2 -0
  179. data/examples/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +3 -0
  180. data/examples/wiktacular/mkd/testing/2007-07-21_18-46-01.mkd +11 -0
  181. data/examples/wiktacular/mkd/testing/2007-07-21_18-46-32.mkd +13 -0
  182. data/examples/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +17 -0
  183. data/examples/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +17 -0
  184. data/examples/wiktacular/mkd/testing/current.mkd +17 -0
  185. data/examples/wiktacular/public/favicon.ico +0 -0
  186. data/examples/wiktacular/public/screen.css +72 -0
  187. data/examples/wiktacular/spec/wiktacular.rb +158 -0
  188. data/examples/wiktacular/src/controller.rb +55 -0
  189. data/examples/wiktacular/src/model.rb +102 -0
  190. data/examples/wiktacular/start.rb +8 -0
  191. data/examples/wiktacular/template/edit.xhtml +6 -0
  192. data/examples/wiktacular/template/html_layout.xhtml +27 -0
  193. data/examples/wiktacular/template/index.xhtml +9 -0
  194. data/examples/wiktacular/template/new.xhtml +6 -0
  195. data/lib/proto/controller/main.rb +22 -0
  196. data/lib/proto/public/css/ramaze_error.css +90 -0
  197. data/lib/proto/public/dispatch.fcgi +11 -0
  198. data/lib/proto/public/favicon.ico +0 -0
  199. data/lib/proto/public/js/jquery.js +3436 -0
  200. data/lib/proto/public/ramaze.png +0 -0
  201. data/lib/proto/spec/main.rb +24 -0
  202. data/lib/proto/start.rb +8 -0
  203. data/lib/proto/start.ru +16 -0
  204. data/lib/proto/view/error.xhtml +64 -0
  205. data/lib/proto/view/index.xhtml +34 -0
  206. data/lib/proto/view/page.xhtml +27 -0
  207. data/lib/ramaze.rb +108 -0
  208. data/lib/ramaze/action.rb +153 -0
  209. data/lib/ramaze/action/render.rb +191 -0
  210. data/lib/ramaze/adapter.rb +101 -0
  211. data/lib/ramaze/adapter/base.rb +103 -0
  212. data/lib/ramaze/adapter/cgi.rb +24 -0
  213. data/lib/ramaze/adapter/ebb.rb +22 -0
  214. data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
  215. data/lib/ramaze/adapter/fcgi.rb +24 -0
  216. data/lib/ramaze/adapter/lsws.rb +23 -0
  217. data/lib/ramaze/adapter/mongrel.rb +25 -0
  218. data/lib/ramaze/adapter/scgi.rb +22 -0
  219. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
  220. data/lib/ramaze/adapter/thin.rb +22 -0
  221. data/lib/ramaze/adapter/webrick.rb +52 -0
  222. data/lib/ramaze/cache.rb +115 -0
  223. data/lib/ramaze/cache/memcached.rb +71 -0
  224. data/lib/ramaze/cache/memory.rb +6 -0
  225. data/lib/ramaze/cache/yaml_store.rb +68 -0
  226. data/lib/ramaze/contrib.rb +82 -0
  227. data/lib/ramaze/contrib/auto_params.rb +135 -0
  228. data/lib/ramaze/contrib/auto_params/get_args.rb +57 -0
  229. data/lib/ramaze/contrib/email.rb +84 -0
  230. data/lib/ramaze/contrib/facebook.rb +23 -0
  231. data/lib/ramaze/contrib/facebook/facebook.rb +171 -0
  232. data/lib/ramaze/contrib/file_cache.rb +65 -0
  233. data/lib/ramaze/contrib/gems.rb +65 -0
  234. data/lib/ramaze/contrib/gettext.rb +113 -0
  235. data/lib/ramaze/contrib/gettext/mo.rb +155 -0
  236. data/lib/ramaze/contrib/gettext/parser.rb +46 -0
  237. data/lib/ramaze/contrib/gettext/po.rb +109 -0
  238. data/lib/ramaze/contrib/gzip_filter.rb +56 -0
  239. data/lib/ramaze/contrib/profiling.rb +36 -0
  240. data/lib/ramaze/contrib/rest.rb +14 -0
  241. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  242. data/lib/ramaze/contrib/sequel_cache.rb +92 -0
  243. data/lib/ramaze/controller.rb +281 -0
  244. data/lib/ramaze/controller/error.rb +46 -0
  245. data/lib/ramaze/controller/main.rb +2 -0
  246. data/lib/ramaze/controller/resolve.rb +252 -0
  247. data/lib/ramaze/current.rb +70 -0
  248. data/lib/ramaze/current/request.rb +204 -0
  249. data/lib/ramaze/current/response.rb +27 -0
  250. data/lib/ramaze/current/session.rb +181 -0
  251. data/lib/ramaze/current/session/flash.rb +79 -0
  252. data/lib/ramaze/current/session/hash.rb +66 -0
  253. data/lib/ramaze/dispatcher.rb +137 -0
  254. data/lib/ramaze/dispatcher/action.rb +41 -0
  255. data/lib/ramaze/dispatcher/directory.rb +119 -0
  256. data/lib/ramaze/dispatcher/error.rb +108 -0
  257. data/lib/ramaze/dispatcher/file.rb +95 -0
  258. data/lib/ramaze/error.rb +24 -0
  259. data/lib/ramaze/gestalt.rb +129 -0
  260. data/lib/ramaze/helper.rb +78 -0
  261. data/lib/ramaze/helper/aspect.rb +110 -0
  262. data/lib/ramaze/helper/auth.rb +125 -0
  263. data/lib/ramaze/helper/cache.rb +140 -0
  264. data/lib/ramaze/helper/cgi.rb +47 -0
  265. data/lib/ramaze/helper/flash.rb +59 -0
  266. data/lib/ramaze/helper/form.rb +281 -0
  267. data/lib/ramaze/helper/formatting.rb +118 -0
  268. data/lib/ramaze/helper/httpdigest.rb +49 -0
  269. data/lib/ramaze/helper/identity.rb +105 -0
  270. data/lib/ramaze/helper/link.rb +124 -0
  271. data/lib/ramaze/helper/markaby.rb +31 -0
  272. data/lib/ramaze/helper/maruku.rb +7 -0
  273. data/lib/ramaze/helper/nitroform.rb +14 -0
  274. data/lib/ramaze/helper/pager.rb +366 -0
  275. data/lib/ramaze/helper/partial.rb +96 -0
  276. data/lib/ramaze/helper/redirect.rb +82 -0
  277. data/lib/ramaze/helper/rest.rb +43 -0
  278. data/lib/ramaze/helper/sendfile.rb +16 -0
  279. data/lib/ramaze/helper/sequel.rb +55 -0
  280. data/lib/ramaze/helper/stack.rb +72 -0
  281. data/lib/ramaze/helper/tagz.rb +19 -0
  282. data/lib/ramaze/helper/user.rb +78 -0
  283. data/lib/ramaze/log.rb +27 -0
  284. data/lib/ramaze/log/analogger.rb +37 -0
  285. data/lib/ramaze/log/growl.rb +35 -0
  286. data/lib/ramaze/log/hub.rb +38 -0
  287. data/lib/ramaze/log/informer.rb +125 -0
  288. data/lib/ramaze/log/knotify.rb +25 -0
  289. data/lib/ramaze/log/logger.rb +23 -0
  290. data/lib/ramaze/log/logging.rb +88 -0
  291. data/lib/ramaze/log/syslog.rb +36 -0
  292. data/lib/ramaze/log/xosd.rb +88 -0
  293. data/lib/ramaze/option.rb +153 -0
  294. data/lib/ramaze/option/dsl.rb +45 -0
  295. data/lib/ramaze/option/holder.rb +143 -0
  296. data/lib/ramaze/option/merger.rb +106 -0
  297. data/lib/ramaze/route.rb +97 -0
  298. data/lib/ramaze/setup.rb +50 -0
  299. data/lib/ramaze/snippets.rb +9 -0
  300. data/lib/ramaze/snippets/array/put_within.rb +37 -0
  301. data/lib/ramaze/snippets/binding/locals.rb +13 -0
  302. data/lib/ramaze/snippets/blankslate.rb +7 -0
  303. data/lib/ramaze/snippets/dictionary.rb +504 -0
  304. data/lib/ramaze/snippets/divide.rb +20 -0
  305. data/lib/ramaze/snippets/kernel/__dir__.rb +23 -0
  306. data/lib/ramaze/snippets/kernel/acquire.rb +34 -0
  307. data/lib/ramaze/snippets/kernel/constant.rb +26 -0
  308. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +15 -0
  309. data/lib/ramaze/snippets/metaid.rb +17 -0
  310. data/lib/ramaze/snippets/numeric/filesize_format.rb +25 -0
  311. data/lib/ramaze/snippets/object/instance_variable_defined.rb +8 -0
  312. data/lib/ramaze/snippets/object/pretty.rb +6 -0
  313. data/lib/ramaze/snippets/object/scope.rb +11 -0
  314. data/lib/ramaze/snippets/object/thread_accessor.rb +5 -0
  315. data/lib/ramaze/snippets/object/traits.rb +76 -0
  316. data/lib/ramaze/snippets/ordered_set.rb +40 -0
  317. data/lib/ramaze/snippets/proc/locals.rb +11 -0
  318. data/lib/ramaze/snippets/ramaze/caller_info.rb +30 -0
  319. data/lib/ramaze/snippets/ramaze/caller_lines.rb +51 -0
  320. data/lib/ramaze/snippets/ramaze/deprecated.rb +7 -0
  321. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +58 -0
  322. data/lib/ramaze/snippets/string/camel_case.rb +16 -0
  323. data/lib/ramaze/snippets/string/color.rb +27 -0
  324. data/lib/ramaze/snippets/string/each.rb +8 -0
  325. data/lib/ramaze/snippets/string/esc.rb +29 -0
  326. data/lib/ramaze/snippets/string/ord.rb +15 -0
  327. data/lib/ramaze/snippets/string/snake_case.rb +15 -0
  328. data/lib/ramaze/snippets/string/start_with.rb +8 -0
  329. data/lib/ramaze/snippets/string/unindent.rb +20 -0
  330. data/lib/ramaze/snippets/struct/fill.rb +23 -0
  331. data/lib/ramaze/snippets/struct/values_at.rb +24 -0
  332. data/lib/ramaze/snippets/symbol/to_proc.rb +24 -0
  333. data/lib/ramaze/snippets/thread/into.rb +18 -0
  334. data/lib/ramaze/sourcereload.rb +169 -0
  335. data/lib/ramaze/spec.rb +1 -0
  336. data/lib/ramaze/spec/helper.rb +131 -0
  337. data/lib/ramaze/spec/helper/bacon.rb +7 -0
  338. data/lib/ramaze/spec/helper/browser.rb +88 -0
  339. data/lib/ramaze/spec/helper/mock_http.rb +69 -0
  340. data/lib/ramaze/spec/helper/pretty_output.rb +82 -0
  341. data/lib/ramaze/spec/helper/requester.rb +63 -0
  342. data/lib/ramaze/spec/helper/simple_http.rb +434 -0
  343. data/lib/ramaze/spec/helper/snippets.rb +6 -0
  344. data/lib/ramaze/store/default.rb +109 -0
  345. data/lib/ramaze/template.rb +84 -0
  346. data/lib/ramaze/template/amrita2.rb +45 -0
  347. data/lib/ramaze/template/builder.rb +28 -0
  348. data/lib/ramaze/template/erubis.rb +41 -0
  349. data/lib/ramaze/template/ezamar.rb +42 -0
  350. data/lib/ramaze/template/ezamar/element.rb +169 -0
  351. data/lib/ramaze/template/ezamar/engine.rb +76 -0
  352. data/lib/ramaze/template/ezamar/morpher.rb +135 -0
  353. data/lib/ramaze/template/ezamar/render_partial.rb +31 -0
  354. data/lib/ramaze/template/haml.rb +37 -0
  355. data/lib/ramaze/template/liquid.rb +36 -0
  356. data/lib/ramaze/template/markaby.rb +52 -0
  357. data/lib/ramaze/template/nagoro.rb +52 -0
  358. data/lib/ramaze/template/none.rb +14 -0
  359. data/lib/ramaze/template/redcloth.rb +25 -0
  360. data/lib/ramaze/template/remarkably.rb +38 -0
  361. data/lib/ramaze/template/sass.rb +37 -0
  362. data/lib/ramaze/template/tagz.rb +79 -0
  363. data/lib/ramaze/template/tenjin.rb +74 -0
  364. data/lib/ramaze/template/xslt.rb +100 -0
  365. data/lib/ramaze/tool.rb +9 -0
  366. data/lib/ramaze/tool/create.rb +74 -0
  367. data/lib/ramaze/tool/localize.rb +198 -0
  368. data/lib/ramaze/tool/mime.rb +25 -0
  369. data/lib/ramaze/tool/mime_types.yaml +615 -0
  370. data/lib/ramaze/tool/record.rb +6 -0
  371. data/lib/ramaze/trinity.rb +13 -0
  372. data/lib/ramaze/version.rb +14 -0
  373. data/lib/vendor/bacon.rb +323 -0
  374. data/rake_tasks/conf.rake +83 -0
  375. data/rake_tasks/coverage.rake +46 -0
  376. data/rake_tasks/darcs.rake +14 -0
  377. data/rake_tasks/gem.rake +85 -0
  378. data/rake_tasks/git.rake +4 -0
  379. data/rake_tasks/maintenance.rake +436 -0
  380. data/rake_tasks/spec.rake +62 -0
  381. data/spec/contrib/auto_params.rb +121 -0
  382. data/spec/contrib/profiling.rb +29 -0
  383. data/spec/contrib/sequel/fill.rb +47 -0
  384. data/spec/examples/caching.rb +19 -0
  385. data/spec/examples/css.rb +15 -0
  386. data/spec/examples/element.rb +15 -0
  387. data/spec/examples/hello.rb +11 -0
  388. data/spec/examples/linking.rb +18 -0
  389. data/spec/examples/simple.rb +45 -0
  390. data/spec/examples/simple_auth.rb +32 -0
  391. data/spec/examples/templates/template_amrita2.rb +16 -0
  392. data/spec/examples/templates/template_erubis.rb +23 -0
  393. data/spec/examples/templates/template_ezamar.rb +23 -0
  394. data/spec/examples/templates/template_haml.rb +25 -0
  395. data/spec/examples/templates/template_liquid.rb +29 -0
  396. data/spec/examples/templates/template_markaby.rb +23 -0
  397. data/spec/examples/templates/template_redcloth.rb +28 -0
  398. data/spec/examples/templates/template_remarkably.rb +23 -0
  399. data/spec/examples/templates/template_tenjin.rb +28 -0
  400. data/spec/helper.rb +3 -0
  401. data/spec/ramaze/action/basics.rb +36 -0
  402. data/spec/ramaze/action/cache.rb +87 -0
  403. data/spec/ramaze/action/file_cache.rb +48 -0
  404. data/spec/ramaze/action/layout.rb +190 -0
  405. data/spec/ramaze/action/render.rb +32 -0
  406. data/spec/ramaze/action/view/bar.xhtml +1 -0
  407. data/spec/ramaze/action/view/instancevars/layout.xhtml +1 -0
  408. data/spec/ramaze/action/view/other_wrapper.xhtml +1 -0
  409. data/spec/ramaze/action/view/single_wrapper.xhtml +1 -0
  410. data/spec/ramaze/action/view/sub/sub_wrapper.xhtml +1 -0
  411. data/spec/ramaze/adapter.rb +39 -0
  412. data/spec/ramaze/adapter/ebb.rb +12 -0
  413. data/spec/ramaze/adapter/mongrel.rb +12 -0
  414. data/spec/ramaze/adapter/record.rb +31 -0
  415. data/spec/ramaze/adapter/webrick.rb +12 -0
  416. data/spec/ramaze/cache.rb +140 -0
  417. data/spec/ramaze/controller.rb +177 -0
  418. data/spec/ramaze/controller/actionless_templates.rb +32 -0
  419. data/spec/ramaze/controller/resolve.rb +32 -0
  420. data/spec/ramaze/controller/subclass.rb +21 -0
  421. data/spec/ramaze/controller/template_resolving.rb +113 -0
  422. data/spec/ramaze/controller/view/greet.xhtml +1 -0
  423. data/spec/ramaze/controller/view/list.xhtml +1 -0
  424. data/spec/ramaze/controller/view/other/greet/other.xhtml +1 -0
  425. data/spec/ramaze/controller/view/other_wrapper.xhtml +1 -0
  426. data/spec/ramaze/current/request.rb +30 -0
  427. data/spec/ramaze/current/session.rb +97 -0
  428. data/spec/ramaze/dispatcher.rb +31 -0
  429. data/spec/ramaze/dispatcher/directory.rb +55 -0
  430. data/spec/ramaze/dispatcher/file.rb +60 -0
  431. data/spec/ramaze/dispatcher/public/favicon.ico +0 -0
  432. data/spec/ramaze/dispatcher/public/file name.txt +1 -0
  433. data/spec/ramaze/dispatcher/public/test_download.css +141 -0
  434. data/spec/ramaze/element.rb +107 -0
  435. data/spec/ramaze/error.rb +94 -0
  436. data/spec/ramaze/gestalt.rb +131 -0
  437. data/spec/ramaze/helper/aspect.rb +92 -0
  438. data/spec/ramaze/helper/auth.rb +66 -0
  439. data/spec/ramaze/helper/cache.rb +160 -0
  440. data/spec/ramaze/helper/cgi.rb +43 -0
  441. data/spec/ramaze/helper/file.rb +18 -0
  442. data/spec/ramaze/helper/flash.rb +133 -0
  443. data/spec/ramaze/helper/form.rb +118 -0
  444. data/spec/ramaze/helper/formatting.rb +41 -0
  445. data/spec/ramaze/helper/link.rb +124 -0
  446. data/spec/ramaze/helper/pager.rb +99 -0
  447. data/spec/ramaze/helper/partial.rb +76 -0
  448. data/spec/ramaze/helper/redirect.rb +112 -0
  449. data/spec/ramaze/helper/stack.rb +73 -0
  450. data/spec/ramaze/helper/user.rb +43 -0
  451. data/spec/ramaze/helper/view/locals.xhtml +1 -0
  452. data/spec/ramaze/helper/view/loop.xhtml +4 -0
  453. data/spec/ramaze/helper/view/num.xhtml +1 -0
  454. data/spec/ramaze/helper/view/partial.xhtml +1 -0
  455. data/spec/ramaze/helper/view/recursive.xhtml +8 -0
  456. data/spec/ramaze/helper/view/recursive_local_ivars.xhtml +7 -0
  457. data/spec/ramaze/helper/view/recursive_locals.xhtml +7 -0
  458. data/spec/ramaze/helper/view/test_template.xhtml +1 -0
  459. data/spec/ramaze/localize.rb +89 -0
  460. data/spec/ramaze/log/informer.rb +72 -0
  461. data/spec/ramaze/log/syslog.rb +10 -0
  462. data/spec/ramaze/morpher.rb +111 -0
  463. data/spec/ramaze/params.rb +157 -0
  464. data/spec/ramaze/public/error404.xhtml +1 -0
  465. data/spec/ramaze/public/favicon.ico +0 -0
  466. data/spec/ramaze/public/ramaze.png +0 -0
  467. data/spec/ramaze/public/test_download.css +141 -0
  468. data/spec/ramaze/request.rb +185 -0
  469. data/spec/ramaze/request/ebb.rb +9 -0
  470. data/spec/ramaze/request/mongrel.rb +9 -0
  471. data/spec/ramaze/request/thin.rb +9 -0
  472. data/spec/ramaze/request/webrick.rb +5 -0
  473. data/spec/ramaze/rewrite.rb +36 -0
  474. data/spec/ramaze/rewrite/file.css +1 -0
  475. data/spec/ramaze/route.rb +131 -0
  476. data/spec/ramaze/session.rb +94 -0
  477. data/spec/ramaze/store/default.rb +71 -0
  478. data/spec/ramaze/template.rb +128 -0
  479. data/spec/ramaze/template/amrita2.rb +50 -0
  480. data/spec/ramaze/template/amrita2/external.amrita +6 -0
  481. data/spec/ramaze/template/amrita2/sum.amrita +1 -0
  482. data/spec/ramaze/template/builder.rb +55 -0
  483. data/spec/ramaze/template/builder/external.rxml +3 -0
  484. data/spec/ramaze/template/erubis.rb +41 -0
  485. data/spec/ramaze/template/erubis/sum.rhtml +1 -0
  486. data/spec/ramaze/template/ezamar.rb +63 -0
  487. data/spec/ramaze/template/ezamar/another/long/action.zmr +1 -0
  488. data/spec/ramaze/template/ezamar/combined.zmr +1 -0
  489. data/spec/ramaze/template/ezamar/file_only.zmr +1 -0
  490. data/spec/ramaze/template/ezamar/index.zmr +1 -0
  491. data/spec/ramaze/template/ezamar/nested.zmr +1 -0
  492. data/spec/ramaze/template/ezamar/other__index.xhtml +1 -0
  493. data/spec/ramaze/template/ezamar/some__long__action.zmr +1 -0
  494. data/spec/ramaze/template/ezamar/sum.zmr +1 -0
  495. data/spec/ramaze/template/haml.rb +66 -0
  496. data/spec/ramaze/template/haml/index.haml +5 -0
  497. data/spec/ramaze/template/haml/locals.haml +2 -0
  498. data/spec/ramaze/template/haml/with_vars.haml +4 -0
  499. data/spec/ramaze/template/liquid.rb +99 -0
  500. data/spec/ramaze/template/liquid/index.liquid +1 -0
  501. data/spec/ramaze/template/liquid/products.liquid +45 -0
  502. data/spec/ramaze/template/markaby.rb +61 -0
  503. data/spec/ramaze/template/markaby/external.mab +8 -0
  504. data/spec/ramaze/template/markaby/sum.mab +1 -0
  505. data/spec/ramaze/template/nagoro.rb +64 -0
  506. data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
  507. data/spec/ramaze/template/nagoro/combined.nag +1 -0
  508. data/spec/ramaze/template/nagoro/file_only.nag +1 -0
  509. data/spec/ramaze/template/nagoro/index.nag +1 -0
  510. data/spec/ramaze/template/nagoro/nested.nag +1 -0
  511. data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
  512. data/spec/ramaze/template/nagoro/sum.nag +1 -0
  513. data/spec/ramaze/template/ramaze/external.test +1 -0
  514. data/spec/ramaze/template/redcloth.rb +38 -0
  515. data/spec/ramaze/template/redcloth/external.redcloth +1 -0
  516. data/spec/ramaze/template/remarkably.rb +58 -0
  517. data/spec/ramaze/template/remarkably/external.rem +8 -0
  518. data/spec/ramaze/template/remarkably/sum.rem +1 -0
  519. data/spec/ramaze/template/sass.rb +69 -0
  520. data/spec/ramaze/template/sass/file.css.sass +5 -0
  521. data/spec/ramaze/template/tagz.rb +62 -0
  522. data/spec/ramaze/template/tagz/external.tagz +8 -0
  523. data/spec/ramaze/template/tagz/sum.tagz +1 -0
  524. data/spec/ramaze/template/tenjin.rb +47 -0
  525. data/spec/ramaze/template/tenjin/external.tenjin +1 -0
  526. data/spec/ramaze/template/xslt.rb +90 -0
  527. data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
  528. data/spec/ramaze/template/xslt/index.xsl +14 -0
  529. data/spec/ramaze/template/xslt/products.xsl +32 -0
  530. data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
  531. data/spec/snippets/array/put_within.rb +33 -0
  532. data/spec/snippets/divide.rb +19 -0
  533. data/spec/snippets/kernel/__dir__.rb +8 -0
  534. data/spec/snippets/kernel/acquire.rb +71 -0
  535. data/spec/snippets/kernel/constant.rb +23 -0
  536. data/spec/snippets/numeric/filesize_format.rb +12 -0
  537. data/spec/snippets/ordered_set.rb +63 -0
  538. data/spec/snippets/ramaze/caller_info.rb +39 -0
  539. data/spec/snippets/ramaze/caller_lines.rb +30 -0
  540. data/spec/snippets/string/camel_case.rb +25 -0
  541. data/spec/snippets/string/color.rb +11 -0
  542. data/spec/snippets/string/snake_case.rb +24 -0
  543. data/spec/snippets/string/unindent.rb +43 -0
  544. data/spec/snippets/struct/fill.rb +26 -0
  545. data/spec/snippets/struct/values_at.rb +44 -0
  546. data/spec/snippets/symbol/to_proc.rb +13 -0
  547. data/spec/snippets/thread/into.rb +20 -0
  548. metadata +789 -0
@@ -0,0 +1,97 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+
6
+ # Ramaze support simple routing using string, regex and lambda based routers.
7
+ # Route are stored in a dictionary, which supports hash-like access but
8
+ # preserves order, so routes are evaluated in the order they are added.
9
+ #
10
+ # String routers are the simplest way to route in Ramaze. One path is
11
+ # translated into another:
12
+ #
13
+ # Ramaze::Route[ '/foo' ] = '/bar'
14
+ # '/foo' => '/bar'
15
+ #
16
+ # Regex routers allow matching against paths using regex. Matches within
17
+ # your regex using () are substituted in the new path using printf-like
18
+ # syntax.
19
+ #
20
+ # Ramaze::Route[ %r!^/(\d+)\.te?xt$! ] = "/text/%d"
21
+ # '/123.txt' => '/text/123'
22
+ # '/789.text' => '/text/789'
23
+ #
24
+ # For more complex routing, lambda routers can be used. Lambda routers are
25
+ # passed in the current path and request object, and must return either a new
26
+ # path string, or nil.
27
+ #
28
+ # Ramaze::Route[ 'name of route' ] = lambda{ |path, request|
29
+ # '/bar' if path == '/foo' and request[:bar] == '1'
30
+ # }
31
+ # '/foo' => '/foo'
32
+ # '/foo?bar=1' => '/bar'
33
+ #
34
+ # Lambda routers can also use this alternative syntax:
35
+ #
36
+ # Ramaze::Route('name of route') do |path, request|
37
+ # '/bar' if path == '/foo' and request[:bar] == '1'
38
+ # end
39
+
40
+ class Route
41
+ trait[:routes] ||= Dictionary.new
42
+
43
+ class << self
44
+ # Retrieve key from trait
45
+ def [](key)
46
+ trait[:routes][key]
47
+ end
48
+
49
+ # Set key to value in trait
50
+ def []=(key, value)
51
+ trait[:routes][key] = value
52
+ end
53
+
54
+ # remove all routes
55
+ def clear
56
+ trait[:routes].clear
57
+ end
58
+
59
+ # Resolve path according to routes.
60
+ def resolve(path)
61
+ trait[:routes].each do |key, val|
62
+ if key.is_a?(Regexp)
63
+ if md = path.match(key)
64
+ return val % md.to_a[1..-1]
65
+ end
66
+
67
+ elsif val.respond_to?(:call)
68
+ if new_path = val.call(path, Request.current)
69
+ return new_path
70
+ end
71
+
72
+ elsif val.is_a?(String)
73
+ return val if path == key
74
+
75
+ else
76
+ Log.error "Invalid route #{key} => #{val}"
77
+ end
78
+ end
79
+
80
+ nil
81
+ end
82
+ end
83
+ end
84
+
85
+ class Rewrite < Route
86
+ trait[:routes] ||= Dictionary.new
87
+ end
88
+
89
+ # Shortcut for defining new routes.
90
+ def self.Route(name, value = nil, &block)
91
+ Route[name] = value || block
92
+ end
93
+
94
+ def self.Rewrite(name, value = nil, &block)
95
+ Rewrite[name] = value || block
96
+ end
97
+ end
@@ -0,0 +1,50 @@
1
+ module Ramaze
2
+ def self.setup(start = true, &block)
3
+ SetupEnvironment.new(&block) if block_given?
4
+ self.start if start
5
+ end
6
+
7
+ class SetupEnvironment
8
+ # FIXME:
9
+ # * This is weird, class scope includes Global, yet it's skipped
10
+ # by Ruby on the lookup only because it's not in the scope of the block
11
+ # at the point of creation, shouldn't instance_eval take the binding of
12
+ # the SetupEnvironment instance in acocunt?
13
+
14
+ def initialize(&block)
15
+ instance_eval(&block)
16
+ end
17
+
18
+ # Shortcut for Ramaze::Gems::gem
19
+ def gem(*args)
20
+ require 'ramaze/contrib/gems'
21
+ Ramaze::Gems::gem(*args)
22
+ Ramaze::Gems::setup
23
+ end
24
+
25
+ # Shortcut if you don't need specific versions but tons of gems
26
+ def gems(*args)
27
+ gems.each{|g| gem(g) }
28
+ end
29
+
30
+ def global(hash = nil)
31
+ if hash
32
+ Global.merge!(hash)
33
+ else
34
+ Global
35
+ end
36
+ end
37
+ alias option global
38
+ end
39
+ end
40
+
41
+ __END__
42
+ Usage example:
43
+
44
+ Ramaze.setup do
45
+ gem 'json'
46
+
47
+ option :middleware => true
48
+ global.adapter = :thin
49
+ option.port = 7000
50
+ end
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ dir = File.join(File.expand_path(File.dirname(__FILE__)), 'snippets')
5
+ glob = File.join(dir, '**', '*.rb')
6
+
7
+ Dir[glob].each do |snippet|
8
+ require(snippet)
9
+ end
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ class Array
5
+
6
+ # a = [1, 2, 3]
7
+ # a.put_within(4, :after => 2, :before => 3)
8
+ # a # => [1, 2, 4, 3]
9
+
10
+ def put_within(object, constrain)
11
+ pre, post = constrain.values_at(:after, :before)
12
+
13
+ unless rindex(post) - index(pre) == 1
14
+ raise ArgumentError, "Too many elements within constrain"
15
+ end
16
+
17
+ put_after(pre, object)
18
+ end
19
+
20
+ # a = [1, 2, 3]
21
+ # a.put_after(2, 4)
22
+ # a # => [1, 2, 4, 3]
23
+
24
+ def put_after(element, object)
25
+ raise ArgumentError, "The given element doesn't exist" unless include?(element)
26
+ self[index(element) + 1, 0] = object
27
+ end
28
+
29
+ # a = [1, 2, 3]
30
+ # a.put_before(2, 4)
31
+ # a # => [1, 4, 2, 3]
32
+
33
+ def put_before(element, object)
34
+ raise ArgumentError, "The given element doesn't exist" unless include?(element)
35
+ self[rindex(element), 0] = object
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ class Binding
2
+
3
+ # returns a hash of localvar/localvar-values from binding, useful for
4
+ # template engines that do not accept bindings and force passing locals via
5
+ # hash
6
+ # usage: x = 42; p binding.locals #=> {'x'=> 42}
7
+ def locals
8
+ Kernel::eval '
9
+ local_variables.inject({}){|h,v| h.update v => eval(v)}
10
+ ', self
11
+ end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ unless defined?(BlankSlate)
2
+ class BlankSlate < BasicObject; end if defined?(BasicObject)
3
+
4
+ class BlankSlate
5
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
6
+ end
7
+ end
@@ -0,0 +1,504 @@
1
+ # = dictionary.rb
2
+ #
3
+ # == Copyright (c) 2005 Jan Molic, Thomas Sawyer
4
+ #
5
+ # Ruby License
6
+ #
7
+ # This module is free software. You may use, modify, and/or redistribute this
8
+ # software under the same terms as Ruby.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but WITHOUT
11
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
+ # FOR A PARTICULAR PURPOSE.
13
+ #
14
+ # == Special Thanks
15
+ #
16
+ # Ported from OrderHash 2.0, Copyright (c) 2005 jan molic
17
+ #
18
+ # Thanks to Andrew Johnson for his suggestions and fixes of Hash[],
19
+ # merge, to_a, inspect and shift.
20
+ #
21
+ # == Authors & Contributors
22
+ #
23
+ # * Jan Molic
24
+ # * Thomas Sawyer
25
+
26
+ # Author:: Jan Molic
27
+ # Copyright:: Copyright (c) 2006 Jan Molic
28
+ # License:: Ruby License
29
+
30
+ # = Dictionary
31
+ #
32
+ # The Dictionary class is a Hash that preserves order.
33
+ # So it has some array-like extensions also. By defualt
34
+ # a Dictionary object preserves insertion order, but any
35
+ # order can be specified including alphabetical key order.
36
+ #
37
+ # == Usage
38
+ #
39
+ # Just require this file and use Dictionary instead of Hash.
40
+ #
41
+ # # You can do simply
42
+ # hsh = Dictionary.new
43
+ # hsh['z'] = 1
44
+ # hsh['a'] = 2
45
+ # hsh['c'] = 3
46
+ # p hsh.keys #=> ['z','a','c']
47
+ #
48
+ # # or using Dictionary[] method
49
+ # hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
50
+ # p hsh.keys #=> ['z','a','c']
51
+ #
52
+ # # but this don't preserve order
53
+ # hsh = Dictionary['z'=>1, 'a'=>2, 'c'=>3]
54
+ # p hsh.keys #=> ['a','c','z']
55
+ #
56
+ # # Dictionary has useful extensions: push, pop and unshift
57
+ # p hsh.push('to_end', 15) #=> true, key added
58
+ # p hsh.push('to_end', 30) #=> false, already - nothing happen
59
+ # p hsh.unshift('to_begin', 50) #=> true, key added
60
+ # p hsh.unshift('to_begin', 60) #=> false, already - nothing happen
61
+ # p hsh.keys #=> ["to_begin", "a", "c", "z", "to_end"]
62
+ # p hsh.pop #=> ["to_end", 15], if nothing remains, return nil
63
+ # p hsh.keys #=> ["to_begin", "a", "c", "z"]
64
+ # p hsh.shift #=> ["to_begin", 30], if nothing remains, return nil
65
+ #
66
+ # == Usage Notes
67
+ #
68
+ # * You can use #order_by to set internal sort order.
69
+ # * #<< takes a two element [k,v] array and inserts.
70
+ # * Use ::auto which creates Dictionay sub-entries as needed.
71
+ # * And ::alpha which creates a new Dictionary sorted by key.
72
+
73
+ module Ramaze
74
+ class Dictionary
75
+
76
+ class << self
77
+
78
+ #--
79
+ # TODO is this needed? Doesn't the super class do this?
80
+ #++
81
+
82
+ def []( *args )
83
+ hsh = new
84
+ if Hash === args[0]
85
+ hsh.replace(args[0])
86
+ elsif (args.size % 2) != 0
87
+ raise ArgumentError, "odd number of elements for Hash"
88
+ else
89
+ while !args.empty?
90
+ hsh[args.shift] = args.shift
91
+ end
92
+ end
93
+ hsh
94
+ end
95
+
96
+ # Like #new but the block sets the order.
97
+ #
98
+ def new_by( *args, &blk )
99
+ new(*args).order_by(&blk)
100
+ end
101
+
102
+ # Alternate to #new which creates a dictionary sorted by key.
103
+ #
104
+ # d = Dictionary.alpha
105
+ # d["z"] = 1
106
+ # d["y"] = 2
107
+ # d["x"] = 3
108
+ # d #=> {"x"=>3,"y"=>2,"z"=>2}
109
+ #
110
+ # This is equivalent to:
111
+ #
112
+ # Dictionary.new.order_by { |key,value| key }
113
+
114
+ def alpha( *args, &block )
115
+ new( *args, &block ).order_by_key
116
+ end
117
+
118
+ # Alternate to #new which auto-creates sub-dictionaries as needed.
119
+ #
120
+ # d = Dictionary.auto
121
+ # d["a"]["b"]["c"] = "abc" #=> { "a"=>{"b"=>{"c"=>"abc"}}}
122
+ #
123
+ def auto( *args )
124
+ #AutoDictionary.new(*args)
125
+ leet = lambda { |hsh, key| hsh[key] = new( &leet ) }
126
+ new(*args, &leet)
127
+ end
128
+ end
129
+
130
+ def initialize( *args, &blk )
131
+ @order = []
132
+ @order_by = nil
133
+ @hash = Hash.new( *args, &blk )
134
+ end
135
+
136
+ def order
137
+ reorder if @order_by
138
+ @order
139
+ end
140
+
141
+ # Keep dictionary sorted by a specific sort order.
142
+
143
+ def order_by( &block )
144
+ @order_by = block
145
+ order
146
+ self
147
+ end
148
+
149
+ # Keep dictionary sorted by key.
150
+ #
151
+ # d = Dictionary.new.order_by_key
152
+ # d["z"] = 1
153
+ # d["y"] = 2
154
+ # d["x"] = 3
155
+ # d #=> {"x"=>3,"y"=>2,"z"=>2}
156
+ #
157
+ # This is equivalent to:
158
+ #
159
+ # Dictionary.new.order_by { |key,value| key }
160
+ #
161
+ # The initializer Dictionary#alpha also provides this.
162
+
163
+ def order_by_key
164
+ @order_by = lambda { |k,v| k }
165
+ order
166
+ self
167
+ end
168
+
169
+ # Keep dictionary sorted by value.
170
+ #
171
+ # d = Dictionary.new.order_by_value
172
+ # d["z"] = 1
173
+ # d["y"] = 2
174
+ # d["x"] = 3
175
+ # d #=> {"x"=>3,"y"=>2,"z"=>2}
176
+ #
177
+ # This is equivalent to:
178
+ #
179
+ # Dictionary.new.order_by { |key,value| value }
180
+
181
+ def order_by_value
182
+ @order_by = lambda { |k,v| v }
183
+ order
184
+ self
185
+ end
186
+
187
+ #
188
+
189
+ def reorder
190
+ if @order_by
191
+ assoc = @order.collect{ |k| [k,@hash[k]] }.sort_by( &@order_by )
192
+ @order = assoc.collect{ |k,v| k }
193
+ end
194
+ @order
195
+ end
196
+
197
+ #def ==( hsh2 )
198
+ # return false if @order != hsh2.order
199
+ # super hsh2
200
+ #end
201
+
202
+ def ==( hsh2 )
203
+ if hsh2.is_a?( Dictionary )
204
+ @order == hsh2.order &&
205
+ @hash == hsh2.instance_variable_get("@hash")
206
+ else
207
+ false
208
+ end
209
+ end
210
+
211
+ def [] k
212
+ @hash[ k ]
213
+ end
214
+
215
+ def fetch( k )
216
+ @hash.fetch( k )
217
+ end
218
+
219
+ # Store operator.
220
+ #
221
+ # h[key] = value
222
+ #
223
+ # Or with additional index.
224
+ #
225
+ # h[key,index] = value
226
+
227
+ def []=(k, i=nil, v=nil)
228
+ if v
229
+ insert(i,k,v)
230
+ else
231
+ store(k,i)
232
+ end
233
+ end
234
+
235
+ def insert( i,k,v )
236
+ @order.insert( i,k )
237
+ @hash.store( k,v )
238
+ end
239
+
240
+ def store( a,b )
241
+ @order.push( a ) unless @hash.has_key?( a )
242
+ @hash.store( a,b )
243
+ end
244
+
245
+ def clear
246
+ @order = []
247
+ @hash.clear
248
+ end
249
+
250
+ def delete( key )
251
+ @order.delete( key )
252
+ @hash.delete( key )
253
+ end
254
+
255
+ def each_key
256
+ order.each { |k| yield( k ) }
257
+ self
258
+ end
259
+
260
+ def each_value
261
+ order.each { |k| yield( @hash[k] ) }
262
+ self
263
+ end
264
+
265
+ def each
266
+ order.each { |k| yield( k,@hash[k] ) }
267
+ self
268
+ end
269
+ alias each_pair each
270
+
271
+ def delete_if
272
+ order.clone.each { |k| delete k if yield }
273
+ self
274
+ end
275
+
276
+ def values
277
+ ary = []
278
+ order.each { |k| ary.push @hash[k] }
279
+ ary
280
+ end
281
+
282
+ def keys
283
+ order
284
+ end
285
+
286
+ def invert
287
+ hsh2 = self.class.new
288
+ order.each { |k| hsh2[@hash[k]] = k }
289
+ hsh2
290
+ end
291
+
292
+ def reject( &block )
293
+ self.dup.delete_if(&block)
294
+ end
295
+
296
+ def reject!( &block )
297
+ hsh2 = reject(&block)
298
+ self == hsh2 ? nil : hsh2
299
+ end
300
+
301
+ def replace( hsh2 )
302
+ @order = hsh2.order
303
+ @hash = hsh2.hash
304
+ end
305
+
306
+ def shift
307
+ key = order.first
308
+ key ? [key,delete(key)] : super
309
+ end
310
+
311
+ def unshift( k,v )
312
+ unless @hash.include?( k )
313
+ @order.unshift( k )
314
+ @hash.store( k,v )
315
+ true
316
+ else
317
+ false
318
+ end
319
+ end
320
+
321
+ def <<(kv)
322
+ push(*kv)
323
+ end
324
+
325
+ def push( k,v )
326
+ unless @hash.include?( k )
327
+ @order.push( k )
328
+ @hash.store( k,v )
329
+ true
330
+ else
331
+ false
332
+ end
333
+ end
334
+
335
+ def pop
336
+ key = order.last
337
+ key ? [key,delete(key)] : nil
338
+ end
339
+
340
+ def to_a
341
+ ary = []
342
+ each { |k,v| ary << [k,v] }
343
+ ary
344
+ end
345
+
346
+ def to_s
347
+ self.to_a.to_s
348
+ end
349
+
350
+ def inspect
351
+ ary = []
352
+ each {|k,v| ary << k.inspect + "=>" + v.inspect}
353
+ '{' + ary.join(", ") + '}'
354
+ end
355
+
356
+ def dup
357
+ self.class[*to_a.flatten]
358
+ end
359
+
360
+ def update( hsh2 )
361
+ hsh2.each { |k,v| self[k] = v }
362
+ reorder
363
+ self
364
+ end
365
+ alias :merge! update
366
+
367
+ def merge( hsh2 )
368
+ self.dup.update(hsh2)
369
+ end
370
+
371
+ def select
372
+ ary = []
373
+ each { |k,v| ary << [k,v] if yield k,v }
374
+ ary
375
+ end
376
+
377
+ def find
378
+ each{|k,v| return k, v if yield(k,v) }
379
+ return nil
380
+ end
381
+
382
+ def first
383
+ @hash[order.first]
384
+ end
385
+
386
+ def last
387
+ @hash[order.last]
388
+ end
389
+
390
+ def length
391
+ @order.length
392
+ end
393
+ alias :size :length
394
+
395
+ def empty?
396
+ @hash.empty?
397
+ end
398
+
399
+ end
400
+ end
401
+
402
+
403
+
404
+ # _____ _
405
+ # |_ _|__ ___| |_
406
+ # | |/ _ \/ __| __|
407
+ # | | __/\__ \ |_
408
+ # |_|\___||___/\__|
409
+ #
410
+
411
+ =begin testing
412
+
413
+ require 'test/unit'
414
+
415
+ class TC_Dictionary < Test::Unit::TestCase
416
+
417
+ def test_create
418
+ hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
419
+ assert_equal( ['z','a','c'], hsh.keys )
420
+ end
421
+
422
+ def test_op_store
423
+ hsh = Dictionary.new
424
+ hsh['z'] = 1
425
+ hsh['a'] = 2
426
+ hsh['c'] = 3
427
+ assert_equal( ['z','a','c'], hsh.keys )
428
+ end
429
+
430
+ def test_push
431
+ hsh = Dictionary['a', 1, 'c', 2, 'z', 3]
432
+ assert( hsh.push('end', 15) )
433
+ assert_equal( 15, hsh['end'] )
434
+ assert( ! hsh.push('end', 30) )
435
+ assert( hsh.unshift('begin', 50) )
436
+ assert_equal( 50, hsh['begin'] )
437
+ assert( ! hsh.unshift('begin', 60) )
438
+ assert_equal( ["begin", "a", "c", "z", "end"], hsh.keys )
439
+ assert_equal( ["end", 15], hsh.pop )
440
+ assert_equal( ["begin", "a", "c", "z"], hsh.keys )
441
+ assert_equal( ["begin", 50], hsh.shift )
442
+ end
443
+
444
+ def test_insert
445
+ # front
446
+ h = Dictionary['a', 1, 'b', 2, 'c', 3]
447
+ r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3]
448
+ assert_equal( 4, h.insert(0,'d',4) )
449
+ assert_equal( r, h )
450
+ # back
451
+ h = Dictionary['a', 1, 'b', 2, 'c', 3]
452
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
453
+ assert_equal( 4, h.insert(-1,'d',4) )
454
+ assert_equal( r, h )
455
+ end
456
+
457
+ def test_update
458
+ # with other orderred hash
459
+ h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
460
+ h2 = Dictionary['d', 4]
461
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
462
+ assert_equal( r, h1.update(h2) )
463
+ assert_equal( r, h1 )
464
+ # with other hash
465
+ h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
466
+ h2 = { 'd' => 4 }
467
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
468
+ assert_equal( r, h1.update(h2) )
469
+ assert_equal( r, h1 )
470
+ end
471
+
472
+ def test_merge
473
+ # with other orderred hash
474
+ h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
475
+ h2 = Dictionary['d', 4]
476
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
477
+ assert_equal( r, h1.merge(h2) )
478
+ # with other hash
479
+ h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
480
+ h2 = { 'd' => 4 }
481
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
482
+ assert_equal( r, h1.merge(h2) )
483
+ end
484
+
485
+ def test_order_by
486
+ h1 = Dictionary['a', 3, 'b', 2, 'c', 1]
487
+ h1.order_by{ |k,v| v }
488
+ assert_equal( [1,2,3], h1.values )
489
+ assert_equal( ['c','b','a'], h1.keys )
490
+ end
491
+
492
+ def test_op_store
493
+ h1 = Dictionary[]
494
+ h1[:a] = 1
495
+ h1[:c] = 3
496
+ assert_equal( [1,3], h1.values )
497
+ h1[:b,1] = 2
498
+ assert_equal( [1,2,3], h1.values )
499
+ assert_equal( [:a,:b,:c], h1.keys )
500
+ end
501
+
502
+ end
503
+
504
+ =end