savage-beast 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. data/.gitignore +2 -0
  2. data/README.rdoc +42 -0
  3. data/Rakefile +25 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/application.rb +6 -0
  6. data/app/controllers/beast_application_controller.rb +3 -0
  7. data/app/controllers/forums_controller.rb +64 -0
  8. data/app/controllers/moderators_controller.rb +10 -0
  9. data/app/controllers/monitorships_controller.rb +22 -0
  10. data/app/controllers/posts_controller.rb +134 -0
  11. data/app/controllers/topics_controller.rb +110 -0
  12. data/app/helpers/count_helper.rb +13 -0
  13. data/app/helpers/forums_helper.rb +15 -0
  14. data/app/helpers/moderators_helper.rb +2 -0
  15. data/app/helpers/monitorships_helper.rb +2 -0
  16. data/app/helpers/posts_helper.rb +3 -0
  17. data/app/helpers/topics_helper.rb +3 -0
  18. data/app/models/forum.rb +26 -0
  19. data/app/models/moderatorship.rb +6 -0
  20. data/app/models/monitorship.rb +5 -0
  21. data/app/models/monitorships_sweeper.rb +9 -0
  22. data/app/models/post.rb +33 -0
  23. data/app/models/posts_sweeper.rb +12 -0
  24. data/app/models/topic.rb +94 -0
  25. data/app/views/forums/_form.html.erb +21 -0
  26. data/app/views/forums/edit.html.erb +12 -0
  27. data/app/views/forums/index.html.erb +77 -0
  28. data/app/views/forums/new.html.erb +10 -0
  29. data/app/views/forums/show.html.erb +94 -0
  30. data/app/views/layouts/_head.html.erb +34 -0
  31. data/app/views/layouts/_post.rss.builder +9 -0
  32. data/app/views/layouts/application.html.erb +29 -0
  33. data/app/views/layouts/beast.html.erb +29 -0
  34. data/app/views/monitorships/create.js.rjs +4 -0
  35. data/app/views/monitorships/destroy.js.rjs +4 -0
  36. data/app/views/posts/_edit.html.erb +38 -0
  37. data/app/views/posts/edit.html.erb +14 -0
  38. data/app/views/posts/edit.js.rjs +6 -0
  39. data/app/views/posts/index.html.erb +53 -0
  40. data/app/views/posts/index.rss.builder +20 -0
  41. data/app/views/posts/monitored.html.erb +55 -0
  42. data/app/views/posts/monitored.rss.builder +15 -0
  43. data/app/views/posts/update.js.rjs +3 -0
  44. data/app/views/topics/_form.html.erb +28 -0
  45. data/app/views/topics/edit.html.erb +10 -0
  46. data/app/views/topics/index.html.erb +2 -0
  47. data/app/views/topics/new.html.erb +18 -0
  48. data/app/views/topics/show.html.erb +183 -0
  49. data/app/views/topics/show.rss.builder +16 -0
  50. data/config/routes.rb +18 -0
  51. data/generators/beast/beast_generator.rb +88 -0
  52. data/generators/beast/templates/migrations/create_savage_tables.rb +73 -0
  53. data/generators/beast/templates/public/images/clearbits/_readme.txt +12 -0
  54. data/generators/beast/templates/public/images/clearbits/add.gif +0 -0
  55. data/generators/beast/templates/public/images/clearbits/addressbook.gif +0 -0
  56. data/generators/beast/templates/public/images/clearbits/alert.gif +0 -0
  57. data/generators/beast/templates/public/images/clearbits/apple.gif +0 -0
  58. data/generators/beast/templates/public/images/clearbits/arrow1_e.gif +0 -0
  59. data/generators/beast/templates/public/images/clearbits/arrow1_n.gif +0 -0
  60. data/generators/beast/templates/public/images/clearbits/arrow1_ne.gif +0 -0
  61. data/generators/beast/templates/public/images/clearbits/arrow1_nw.gif +0 -0
  62. data/generators/beast/templates/public/images/clearbits/arrow1_s.gif +0 -0
  63. data/generators/beast/templates/public/images/clearbits/arrow1_se.gif +0 -0
  64. data/generators/beast/templates/public/images/clearbits/arrow1_sw.gif +0 -0
  65. data/generators/beast/templates/public/images/clearbits/arrow1_w.gif +0 -0
  66. data/generators/beast/templates/public/images/clearbits/arrow2_e.gif +0 -0
  67. data/generators/beast/templates/public/images/clearbits/arrow2_n.gif +0 -0
  68. data/generators/beast/templates/public/images/clearbits/arrow2_ne.gif +0 -0
  69. data/generators/beast/templates/public/images/clearbits/arrow2_nw.gif +0 -0
  70. data/generators/beast/templates/public/images/clearbits/arrow2_s.gif +0 -0
  71. data/generators/beast/templates/public/images/clearbits/arrow2_se.gif +0 -0
  72. data/generators/beast/templates/public/images/clearbits/arrow2_sw.gif +0 -0
  73. data/generators/beast/templates/public/images/clearbits/arrow2_w.gif +0 -0
  74. data/generators/beast/templates/public/images/clearbits/arrow3_e.gif +0 -0
  75. data/generators/beast/templates/public/images/clearbits/arrow3_n.gif +0 -0
  76. data/generators/beast/templates/public/images/clearbits/arrow3_ne.gif +0 -0
  77. data/generators/beast/templates/public/images/clearbits/arrow3_nw.gif +0 -0
  78. data/generators/beast/templates/public/images/clearbits/arrow3_s.gif +0 -0
  79. data/generators/beast/templates/public/images/clearbits/arrow3_se.gif +0 -0
  80. data/generators/beast/templates/public/images/clearbits/arrow3_sw.gif +0 -0
  81. data/generators/beast/templates/public/images/clearbits/arrow3_w.gif +0 -0
  82. data/generators/beast/templates/public/images/clearbits/ascii.gif +0 -0
  83. data/generators/beast/templates/public/images/clearbits/back.gif +0 -0
  84. data/generators/beast/templates/public/images/clearbits/bg_blank.gif +0 -0
  85. data/generators/beast/templates/public/images/clearbits/bg_circle.gif +0 -0
  86. data/generators/beast/templates/public/images/clearbits/bg_rounded.gif +0 -0
  87. data/generators/beast/templates/public/images/clearbits/bg_rounded_ne.gif +0 -0
  88. data/generators/beast/templates/public/images/clearbits/bg_rounded_nw.gif +0 -0
  89. data/generators/beast/templates/public/images/clearbits/bg_rounded_se.gif +0 -0
  90. data/generators/beast/templates/public/images/clearbits/bg_rounded_sw.gif +0 -0
  91. data/generators/beast/templates/public/images/clearbits/bigsmile.gif +0 -0
  92. data/generators/beast/templates/public/images/clearbits/binary.gif +0 -0
  93. data/generators/beast/templates/public/images/clearbits/blah.gif +0 -0
  94. data/generators/beast/templates/public/images/clearbits/bstop.gif +0 -0
  95. data/generators/beast/templates/public/images/clearbits/buy.gif +0 -0
  96. data/generators/beast/templates/public/images/clearbits/calday.gif +0 -0
  97. data/generators/beast/templates/public/images/clearbits/calendar.gif +0 -0
  98. data/generators/beast/templates/public/images/clearbits/camera.gif +0 -0
  99. data/generators/beast/templates/public/images/clearbits/cart.gif +0 -0
  100. data/generators/beast/templates/public/images/clearbits/cd.gif +0 -0
  101. data/generators/beast/templates/public/images/clearbits/cellphone.gif +0 -0
  102. data/generators/beast/templates/public/images/clearbits/chat.gif +0 -0
  103. data/generators/beast/templates/public/images/clearbits/check.gif +0 -0
  104. data/generators/beast/templates/public/images/clearbits/close.gif +0 -0
  105. data/generators/beast/templates/public/images/clearbits/comment.gif +0 -0
  106. data/generators/beast/templates/public/images/clearbits/cube.gif +0 -0
  107. data/generators/beast/templates/public/images/clearbits/day.gif +0 -0
  108. data/generators/beast/templates/public/images/clearbits/denied.gif +0 -0
  109. data/generators/beast/templates/public/images/clearbits/document.gif +0 -0
  110. data/generators/beast/templates/public/images/clearbits/download.gif +0 -0
  111. data/generators/beast/templates/public/images/clearbits/edit.gif +0 -0
  112. data/generators/beast/templates/public/images/clearbits/eject.gif +0 -0
  113. data/generators/beast/templates/public/images/clearbits/equalizer.gif +0 -0
  114. data/generators/beast/templates/public/images/clearbits/first.gif +0 -0
  115. data/generators/beast/templates/public/images/clearbits/flag.gif +0 -0
  116. data/generators/beast/templates/public/images/clearbits/flash.gif +0 -0
  117. data/generators/beast/templates/public/images/clearbits/folder.gif +0 -0
  118. data/generators/beast/templates/public/images/clearbits/forward.gif +0 -0
  119. data/generators/beast/templates/public/images/clearbits/frown.gif +0 -0
  120. data/generators/beast/templates/public/images/clearbits/ftp.gif +0 -0
  121. data/generators/beast/templates/public/images/clearbits/graph.gif +0 -0
  122. data/generators/beast/templates/public/images/clearbits/heart.gif +0 -0
  123. data/generators/beast/templates/public/images/clearbits/home.gif +0 -0
  124. data/generators/beast/templates/public/images/clearbits/html.gif +0 -0
  125. data/generators/beast/templates/public/images/clearbits/ipod.gif +0 -0
  126. data/generators/beast/templates/public/images/clearbits/last.gif +0 -0
  127. data/generators/beast/templates/public/images/clearbits/lock.gif +0 -0
  128. data/generators/beast/templates/public/images/clearbits/loop.gif +0 -0
  129. data/generators/beast/templates/public/images/clearbits/mail.gif +0 -0
  130. data/generators/beast/templates/public/images/clearbits/man.gif +0 -0
  131. data/generators/beast/templates/public/images/clearbits/manman.gif +0 -0
  132. data/generators/beast/templates/public/images/clearbits/music.gif +0 -0
  133. data/generators/beast/templates/public/images/clearbits/mute.gif +0 -0
  134. data/generators/beast/templates/public/images/clearbits/mute_centered.gif +0 -0
  135. data/generators/beast/templates/public/images/clearbits/newwindow.gif +0 -0
  136. data/generators/beast/templates/public/images/clearbits/next.gif +0 -0
  137. data/generators/beast/templates/public/images/clearbits/night.gif +0 -0
  138. data/generators/beast/templates/public/images/clearbits/open.gif +0 -0
  139. data/generators/beast/templates/public/images/clearbits/pause.gif +0 -0
  140. data/generators/beast/templates/public/images/clearbits/phone.gif +0 -0
  141. data/generators/beast/templates/public/images/clearbits/play.gif +0 -0
  142. data/generators/beast/templates/public/images/clearbits/previous.gif +0 -0
  143. data/generators/beast/templates/public/images/clearbits/quicktime.gif +0 -0
  144. data/generators/beast/templates/public/images/clearbits/redo.gif +0 -0
  145. data/generators/beast/templates/public/images/clearbits/reload.gif +0 -0
  146. data/generators/beast/templates/public/images/clearbits/sad.gif +0 -0
  147. data/generators/beast/templates/public/images/clearbits/save.gif +0 -0
  148. data/generators/beast/templates/public/images/clearbits/scream.gif +0 -0
  149. data/generators/beast/templates/public/images/clearbits/search.gif +0 -0
  150. data/generators/beast/templates/public/images/clearbits/seconds.gif +0 -0
  151. data/generators/beast/templates/public/images/clearbits/smile.gif +0 -0
  152. data/generators/beast/templates/public/images/clearbits/smirk.gif +0 -0
  153. data/generators/beast/templates/public/images/clearbits/star.gif +0 -0
  154. data/generators/beast/templates/public/images/clearbits/stop.gif +0 -0
  155. data/generators/beast/templates/public/images/clearbits/subtract.gif +0 -0
  156. data/generators/beast/templates/public/images/clearbits/switch.gif +0 -0
  157. data/generators/beast/templates/public/images/clearbits/target.gif +0 -0
  158. data/generators/beast/templates/public/images/clearbits/tcp.gif +0 -0
  159. data/generators/beast/templates/public/images/clearbits/time.gif +0 -0
  160. data/generators/beast/templates/public/images/clearbits/toggle.gif +0 -0
  161. data/generators/beast/templates/public/images/clearbits/tongue.gif +0 -0
  162. data/generators/beast/templates/public/images/clearbits/tools.gif +0 -0
  163. data/generators/beast/templates/public/images/clearbits/trackback.gif +0 -0
  164. data/generators/beast/templates/public/images/clearbits/trash.gif +0 -0
  165. data/generators/beast/templates/public/images/clearbits/tv.gif +0 -0
  166. data/generators/beast/templates/public/images/clearbits/type.gif +0 -0
  167. data/generators/beast/templates/public/images/clearbits/undo.gif +0 -0
  168. data/generators/beast/templates/public/images/clearbits/unlock.gif +0 -0
  169. data/generators/beast/templates/public/images/clearbits/upload.gif +0 -0
  170. data/generators/beast/templates/public/images/clearbits/user.gif +0 -0
  171. data/generators/beast/templates/public/images/clearbits/video.gif +0 -0
  172. data/generators/beast/templates/public/images/clearbits/volume_high.gif +0 -0
  173. data/generators/beast/templates/public/images/clearbits/volume_low.gif +0 -0
  174. data/generators/beast/templates/public/images/clearbits/wifi.gif +0 -0
  175. data/generators/beast/templates/public/images/clearbits/window.gif +0 -0
  176. data/generators/beast/templates/public/images/clearbits/woman.gif +0 -0
  177. data/generators/beast/templates/public/images/clearbits/womanman.gif +0 -0
  178. data/generators/beast/templates/public/images/clearbits/work.gif +0 -0
  179. data/generators/beast/templates/public/images/clearbits/zoomin.gif +0 -0
  180. data/generators/beast/templates/public/images/clearbits/zoomout.gif +0 -0
  181. data/generators/beast/templates/public/images/feed-icon.png +0 -0
  182. data/generators/beast/templates/public/images/rails.png +0 -0
  183. data/generators/beast/templates/public/images/reply_background.png +0 -0
  184. data/generators/beast/templates/public/images/small_circle.gif +0 -0
  185. data/generators/beast/templates/public/images/spinner.gif +0 -0
  186. data/generators/beast/templates/public/images/spinner_black.gif +0 -0
  187. data/generators/beast/templates/public/images/spinner_bounce.gif +0 -0
  188. data/generators/beast/templates/public/javascripts/beast.js +80 -0
  189. data/generators/beast/templates/public/stylesheets/display.css +941 -0
  190. data/lang/en.yml +206 -0
  191. data/lib/beast.rb +79 -0
  192. data/lib/savage_beast/application_helper.rb +91 -0
  193. data/lib/savage_beast/authentication_system.rb +47 -0
  194. data/lib/savage_beast/user_init.rb +79 -0
  195. data/lib/tasks/capistrano.rake +90 -0
  196. data/lib/tasks/deploy_edge.rake +44 -0
  197. data/lib/tasks/savage_beast.rake +133 -0
  198. data/po/beast.pot +712 -0
  199. data/po/nl/beast.po +700 -0
  200. data/tested_plugins/acts_as_list/README +23 -0
  201. data/tested_plugins/acts_as_list/init.rb +3 -0
  202. data/tested_plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  203. data/tested_plugins/acts_as_list/test/list_test.rb +332 -0
  204. data/tested_plugins/gibberish/LICENSE +18 -0
  205. data/tested_plugins/gibberish/README +118 -0
  206. data/tested_plugins/gibberish/Rakefile +14 -0
  207. data/tested_plugins/gibberish/init.rb +3 -0
  208. data/tested_plugins/gibberish/lang/es.yml +3 -0
  209. data/tested_plugins/gibberish/lang/fr.yml +3 -0
  210. data/tested_plugins/gibberish/lib/gibberish.rb +8 -0
  211. data/tested_plugins/gibberish/lib/gibberish/localize.rb +88 -0
  212. data/tested_plugins/gibberish/lib/gibberish/string_ext.rb +17 -0
  213. data/tested_plugins/gibberish/test/gibberish_test.rb +203 -0
  214. data/tested_plugins/gibberish/test/lang/es.yml +1 -0
  215. data/tested_plugins/gibberish/test/lang/fr.yml +1 -0
  216. data/tested_plugins/mislav-will_paginate/CHANGELOG.rdoc +110 -0
  217. data/tested_plugins/mislav-will_paginate/LICENSE +18 -0
  218. data/tested_plugins/mislav-will_paginate/README.rdoc +107 -0
  219. data/tested_plugins/mislav-will_paginate/Rakefile +53 -0
  220. data/tested_plugins/mislav-will_paginate/examples/apple-circle.gif +0 -0
  221. data/tested_plugins/mislav-will_paginate/examples/index.haml +69 -0
  222. data/tested_plugins/mislav-will_paginate/examples/index.html +92 -0
  223. data/tested_plugins/mislav-will_paginate/examples/pagination.css +90 -0
  224. data/tested_plugins/mislav-will_paginate/examples/pagination.sass +91 -0
  225. data/tested_plugins/mislav-will_paginate/init.rb +1 -0
  226. data/tested_plugins/mislav-will_paginate/lib/will_paginate.rb +78 -0
  227. data/tested_plugins/mislav-will_paginate/lib/will_paginate/array.rb +16 -0
  228. data/tested_plugins/mislav-will_paginate/lib/will_paginate/collection.rb +146 -0
  229. data/tested_plugins/mislav-will_paginate/lib/will_paginate/core_ext.rb +32 -0
  230. data/tested_plugins/mislav-will_paginate/lib/will_paginate/finder.rb +264 -0
  231. data/tested_plugins/mislav-will_paginate/lib/will_paginate/named_scope.rb +170 -0
  232. data/tested_plugins/mislav-will_paginate/lib/will_paginate/named_scope_patch.rb +37 -0
  233. data/tested_plugins/mislav-will_paginate/lib/will_paginate/version.rb +9 -0
  234. data/tested_plugins/mislav-will_paginate/lib/will_paginate/view_helpers.rb +402 -0
  235. data/tested_plugins/mislav-will_paginate/test/boot.rb +21 -0
  236. data/tested_plugins/mislav-will_paginate/test/collection_test.rb +143 -0
  237. data/tested_plugins/mislav-will_paginate/test/console +8 -0
  238. data/tested_plugins/mislav-will_paginate/test/database.yml +22 -0
  239. data/tested_plugins/mislav-will_paginate/test/finder_test.rb +476 -0
  240. data/tested_plugins/mislav-will_paginate/test/fixtures/admin.rb +3 -0
  241. data/tested_plugins/mislav-will_paginate/test/fixtures/developer.rb +14 -0
  242. data/tested_plugins/mislav-will_paginate/test/fixtures/developers_projects.yml +13 -0
  243. data/tested_plugins/mislav-will_paginate/test/fixtures/project.rb +15 -0
  244. data/tested_plugins/mislav-will_paginate/test/fixtures/projects.yml +6 -0
  245. data/tested_plugins/mislav-will_paginate/test/fixtures/replies.yml +29 -0
  246. data/tested_plugins/mislav-will_paginate/test/fixtures/reply.rb +7 -0
  247. data/tested_plugins/mislav-will_paginate/test/fixtures/schema.rb +38 -0
  248. data/tested_plugins/mislav-will_paginate/test/fixtures/topic.rb +10 -0
  249. data/tested_plugins/mislav-will_paginate/test/fixtures/topics.yml +30 -0
  250. data/tested_plugins/mislav-will_paginate/test/fixtures/user.rb +2 -0
  251. data/tested_plugins/mislav-will_paginate/test/fixtures/users.yml +35 -0
  252. data/tested_plugins/mislav-will_paginate/test/helper.rb +40 -0
  253. data/tested_plugins/mislav-will_paginate/test/lib/activerecord_test_case.rb +43 -0
  254. data/tested_plugins/mislav-will_paginate/test/lib/activerecord_test_connector.rb +75 -0
  255. data/tested_plugins/mislav-will_paginate/test/lib/load_fixtures.rb +11 -0
  256. data/tested_plugins/mislav-will_paginate/test/lib/view_test_process.rb +178 -0
  257. data/tested_plugins/mislav-will_paginate/test/tasks.rake +59 -0
  258. data/tested_plugins/mislav-will_paginate/test/view_test.rb +365 -0
  259. data/tested_plugins/white_list/README +29 -0
  260. data/tested_plugins/white_list/Rakefile +22 -0
  261. data/tested_plugins/white_list/init.rb +2 -0
  262. data/tested_plugins/white_list/lib/white_list_helper.rb +97 -0
  263. data/tested_plugins/white_list/test/white_list_test.rb +132 -0
  264. data/tested_plugins/white_list_formatted_content/init.rb +27 -0
  265. metadata +322 -0
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,118 @@
1
+ = Gibberish
2
+
3
+ Yet another localization library. Maybe with the most agreeable API?
4
+
5
+ = Usage
6
+
7
+ It's simple. Your default language, by default, is English (:en).
8
+
9
+ >> "Hey there!"[:hey]
10
+ => "Hey there!"
11
+
12
+ Gibberish looks in RAILS_ROOT/lang/*.yml for translation files. Say you have RAILS_ROOT/lang/es.yml,
13
+ right? Gibberish will detect that you know about the :es language and will serve up translations
14
+ defined in that file if requested to do so.
15
+
16
+ Here's a real simple example file (it's just "key: translation"):
17
+
18
+ $ cat lang/es.yml
19
+ hey: �Hey all�!
20
+
21
+ And, as follows, a real simple example session:
22
+
23
+ >> "Hey there!"[:hey]
24
+ => "Hey there!"
25
+ >> Gibberish.current_language
26
+ => :en
27
+ >> Gibberish.current_language = :es
28
+ => :es
29
+ >> "Hey there!"[:hey]
30
+ => "�Hey all�!"
31
+ >> Gibberish.current_language = nil
32
+ => nil
33
+ >> "Hey there!"[:hey]
34
+ => "Hey there!"
35
+
36
+ It even works with simple interpolation:
37
+
38
+ >> "Hey, {name}!"[:hey_name, 'Chris']
39
+ => "Hey, Chris!"
40
+ >> "{name} is from {place}"[:hey_place, 'Chris', 'the Dreamworld']
41
+ => "Chris is from the Dreamworld"
42
+
43
+ Notice we don't use hashes (#) like normal Ruby interpolation. Also, the names of the variables
44
+ in the brackets don't really mean much. Interpolation is done in order -- the first argument replaces
45
+ the first variable in brackets, the second the second, etc.
46
+
47
+ Interpolation can also be done via hash:
48
+
49
+ >> "{name} is from {place}"[:hey_place, { :place => 'Gotham City', :name => 'Batman' }]
50
+ => "Batman is from Gotham City"
51
+
52
+ This of course works with your translations:
53
+
54
+ $ cat lang/es.yml
55
+ hey: �Hey all�!
56
+ hey_name: �Hola {name}!
57
+
58
+ >> "Hey, {name}!"[:hey_name, 'Chris']
59
+ => "Hey, Chris!"
60
+ >> Gibberish.current_language = :es
61
+ => :es
62
+ >> "Hey, {name}!"[:hey_name, 'Crist�bal']
63
+ => �Hola Crist�bal!
64
+
65
+ Neat. What other methods do we get?
66
+
67
+ The classic around_filter:
68
+
69
+ class ApplicationController < ActionController::Base
70
+ around_filter :set_language
71
+
72
+ private
73
+ def set_language
74
+ Gibberish.use_language(session[:language]) { yield }
75
+ end
76
+ end
77
+
78
+ For the duration of the block, :es is set as the language of choice. After the block is run everything
79
+ returns to normal. Rad.
80
+
81
+ Finally, some checking methods, if you need them:
82
+
83
+ >> Gibberish.default_language?
84
+ => true
85
+ >> Gibberish.current_language = :es
86
+ => :es
87
+ >> Gibberish.current_language
88
+ => :es
89
+ >> Gibberish.default_language?
90
+ => false
91
+
92
+ Languages are loaded by default at Rails startup. In dev mode, language YAML files are reloaded when
93
+ modified. No need to reboot the server.
94
+
95
+ >> Gibberish.load_languages!
96
+ => [:es, :fr, :de, :kl]
97
+ >> Gibberish.languages
98
+ => [:es, :fr, :de, :kl]
99
+
100
+ More as it's needed.
101
+
102
+ = Warning
103
+
104
+ By default, Ruby returns nil when a symbol is passed to String's [] method. Some of Rails, it seems, depends
105
+ on this behavior. Yes, I am changing !!core Ruby behavior!! The humanity!
106
+
107
+ To deal with this assumption, Gibberish has a reserved_keys array. It, by default, contains :limit (so Rails
108
+ migrations don't explode on you.) To add to this array, just pass it more keys:
109
+
110
+ >> Gibberish.add_reserved_key :another_key
111
+ => [:limit, :another_key]
112
+ >> Gibberish.add_reserved_keys :more, :keys
113
+ => [:limit, :another_key, :more, :keys]
114
+
115
+ You've been warned. It really shouldn't affect you, though.
116
+
117
+ >> Chris Wanstrath
118
+ => chris[at]ozmm[dot]org
@@ -0,0 +1,14 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Generate RDoc documentation for the Gibberish plugin.'
6
+ Rake::RDocTask.new(:rdoc) do |rdoc|
7
+ files = ['README', 'LICENSE', 'lib/**/*.rb']
8
+ rdoc.rdoc_files.add(files)
9
+ rdoc.main = "README" # page to start on
10
+ rdoc.title = "gibberish"
11
+ rdoc.template = File.exists?(t="/Users/chris/ruby/projects/err/rock/template.rb") ? t : "/var/www/rock/template.rb"
12
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
13
+ rdoc.options << '--inline-source'
14
+ end
@@ -0,0 +1,3 @@
1
+ require 'gibberish'
2
+
3
+ Gibberish.load_languages!
@@ -0,0 +1,3 @@
1
+ welcome_friend: �Bienvenido amigo!
2
+ welcome_user: �Bienvenido {user}!
3
+ love_rails: Amo los carriles.
@@ -0,0 +1,3 @@
1
+ welcome_friend: Bienvenue, ami!
2
+ welcome_user: Bienvenue, {user}!
3
+ love_rails: J'aime des rails.
@@ -0,0 +1,8 @@
1
+ require 'gibberish/localize'
2
+ require 'gibberish/string_ext'
3
+
4
+ String.send :include, Gibberish::StringExt
5
+
6
+ module Gibberish
7
+ extend Localize
8
+ end
@@ -0,0 +1,88 @@
1
+ module Gibberish
2
+ module Localize
3
+ @@default_language = :en
4
+ mattr_reader :default_language
5
+
6
+ @@reserved_keys = [ :limit ]
7
+ mattr_reader :reserved_keys
8
+
9
+ def add_reserved_key(*key)
10
+ (@@reserved_keys += key.flatten).uniq!
11
+ end
12
+ alias :add_reserved_keys :add_reserved_key
13
+
14
+ @@languages = {}
15
+ def languages
16
+ @@languages.keys
17
+ end
18
+
19
+ @@current_language = nil
20
+ def current_language
21
+ @@current_language || default_language
22
+ end
23
+
24
+ def current_language=(language)
25
+ load_languages! if defined?(RAILS_ENV) && RAILS_ENV == 'development'
26
+
27
+ language = language.to_sym if language.respond_to? :to_sym
28
+ @@current_language = @@languages[language] ? language : nil
29
+ end
30
+
31
+ def use_language(language)
32
+ start_language = current_language
33
+ self.current_language = language
34
+ yield
35
+ self.current_language = start_language
36
+ end
37
+
38
+ def default_language?
39
+ current_language == default_language
40
+ end
41
+
42
+ def translations
43
+ @@languages[current_language] || {}
44
+ end
45
+
46
+ def translate(string, key, *args)
47
+ return if reserved_keys.include? key
48
+ target = translations[key] || string
49
+ interpolate_string(target.dup, *args.dup)
50
+ end
51
+
52
+ def load_languages!
53
+ language_files.each do |file|
54
+ key = File.basename(file, '.*').to_sym
55
+ @@languages[key] ||= {}
56
+ @@languages[key].merge! YAML.load_file(file).symbolize_keys
57
+ end
58
+ languages
59
+ end
60
+
61
+ @@language_paths = [RAILS_ROOT]
62
+ def language_paths
63
+ @@language_paths ||= []
64
+ end
65
+ private
66
+ def interpolate_string(string, *args)
67
+ if args.last.is_a? Hash
68
+ interpolate_with_hash(string, args.last)
69
+ else
70
+ interpolate_with_strings(string, args)
71
+ end
72
+ end
73
+
74
+ def interpolate_with_hash(string, hash)
75
+ hash.inject(string) do |target, (search, replace)|
76
+ target.sub("{#{search}}", replace)
77
+ end
78
+ end
79
+
80
+ def interpolate_with_strings(string, strings)
81
+ string.gsub(/\{\w+\}/) { strings.shift }
82
+ end
83
+
84
+ def language_files
85
+ @@language_paths.map {|path| Dir[File.join(path, 'lang', '*.{yml,yaml}')]}.flatten
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,17 @@
1
+ module Gibberish
2
+ module StringExt
3
+ def brackets_with_translation(*args)
4
+ args = [underscore.tr(' ', '_').to_sym] if args.empty?
5
+ return brackets_without_translation(*args) unless args.first.is_a? Symbol
6
+ Gibberish.translate(self, args.shift, *args)
7
+ end
8
+
9
+ def self.included(base)
10
+ base.class_eval do
11
+ alias :brackets :[]
12
+ alias_method_chain :brackets, :translation
13
+ alias :[] :brackets
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,203 @@
1
+ begin
2
+ require 'rubygems'
3
+ require 'test/spec'
4
+ rescue LoadError
5
+ puts "==> The test/spec library (gem) is required to run the Gibberish tests."
6
+ exit
7
+ end
8
+
9
+ $:.unshift File.dirname(__FILE__) + '/../lib'
10
+ RAILS_ROOT = File.dirname(__FILE__) + '/..'
11
+
12
+ require 'active_support'
13
+ require 'gibberish'
14
+
15
+ Gibberish.load_languages!
16
+
17
+ context "After loading languages, Gibberish" do
18
+ teardown do
19
+ Gibberish.current_language = nil
20
+ end
21
+
22
+ specify "should know what languages it has translations for" do
23
+ Gibberish.languages.should.include :es
24
+ end
25
+
26
+ specify "should know if it is using the default language" do
27
+ Gibberish.should.be.default_language
28
+ end
29
+
30
+ specify "should be able to switch between existing languages" do
31
+ Gibberish.current_language = :es
32
+ string = "Welcome, friend!"
33
+ string[:welcome_friend].should.not.equal string
34
+
35
+ Gibberish.current_language = :fr
36
+ string[:welcome_friend].should.not.equal string
37
+
38
+ Gibberish.current_language = nil
39
+ string[:welcome_friend].should.equal string
40
+ end
41
+
42
+ specify "should be able to switch languages using strings" do
43
+ Gibberish.current_language = 'es'
44
+ Gibberish.current_language.should.equal :es
45
+ end
46
+
47
+ specify "should be able to switch to the default language at any time" do
48
+ Gibberish.current_language = :fr
49
+ Gibberish.should.not.be.default_language
50
+
51
+ Gibberish.current_language = nil
52
+ Gibberish.should.be.default_language
53
+ end
54
+
55
+ specify "should be able to switch to a certain language for the duration of a block" do
56
+ Gibberish.should.be.default_language
57
+
58
+ string = "Welcome, friend!"
59
+ string[:welcome_friend].should.equal string
60
+
61
+ Gibberish.use_language :es do
62
+ string[:welcome_friend].should.not.equal string
63
+ Gibberish.should.not.be.default_language
64
+ end
65
+
66
+ Gibberish.should.be.default_language
67
+ string[:welcome_friend].should.equal string
68
+ end
69
+
70
+ specify "should return an array of the languages it loaded" do
71
+ languages = Gibberish.load_languages!
72
+ languages.should.be.an.instance_of Array
73
+ languages.should.include :es
74
+ languages.should.include :fr
75
+ end
76
+
77
+ specify "should know what languages it has loaded" do
78
+ languages = Gibberish.languages
79
+ languages.should.be.an.instance_of Array
80
+ languages.should.include :es
81
+ languages.should.include :fr
82
+ end
83
+
84
+ specify "should be able to accept new, unique reserved keys" do
85
+ key = :something_evil
86
+ Gibberish.add_reserved_key key
87
+ Gibberish.reserved_keys.should.include key
88
+ Gibberish.reserved_keys.size.should.equal 2
89
+ Gibberish.add_reserved_key key
90
+ Gibberish.add_reserved_key key
91
+ Gibberish.reserved_keys.size.should.equal 2
92
+ end
93
+
94
+ specify "should have loaded language files from directories other than the default" do
95
+ Gibberish.language_paths << File.dirname(__FILE__)
96
+ Gibberish.load_languages!
97
+ string = "I don't speak Babble."
98
+ Gibberish.use_language :es do
99
+ string[:no_babble].should.equal "No hablo Bable."
100
+ end
101
+ Gibberish.use_language :fr do
102
+ string[:no_babble].should.equal "Je ne parle pas Babble."
103
+ end
104
+ end
105
+ end
106
+
107
+ context "When no language is set" do
108
+ setup do
109
+ Gibberish.current_language = nil
110
+ end
111
+
112
+ specify "the default language should be used" do
113
+ Gibberish.current_language.should.equal Gibberish.default_language
114
+ end
115
+
116
+ specify "a gibberish string should return itself" do
117
+ string = "Welcome, friend!"
118
+ Gibberish.translate(string, :welcome_friend).should.equal string
119
+
120
+ string[:welcome_friend].should.equal string
121
+ end
122
+ end
123
+
124
+ context "When a non-existent language is set" do
125
+ setup do
126
+ Gibberish.current_language = :klingon
127
+ end
128
+
129
+ specify "the default language should be used" do
130
+ Gibberish.current_language.should.equal Gibberish.default_language
131
+ end
132
+
133
+ specify "gibberish strings should return themselves" do
134
+ string = "something gibberishy"
135
+ string[:welcome_friend].should.equal string
136
+ end
137
+ end
138
+
139
+ context "A gibberish string (in general)" do
140
+ specify "should be a string" do
141
+ "gibberish"[:just_a_string].should.be.an.instance_of String
142
+ "non-gibberish".should.be.an.instance_of String
143
+ end
144
+
145
+ specify "should interpolate if passed arguments and replaces are present" do
146
+ 'Hi, {user} of {place}'[:hi_there, 'chris', 'france'].should.equal "Hi, chris of france"
147
+ '{computer} omg?'[:puter, 'mac'].should.equal "mac omg?"
148
+ end
149
+
150
+ specify "should interpolate based on key if passed a hash" do
151
+ 'Hi, {user} of {place}'[:hi_there, { :place => 'france', :user => 'chris' }].should.equal "Hi, chris of france"
152
+
153
+ bands = { 'other_bad_band' => 'Deputy', :good_band => 'Word Picture', 'bad_band' => 'Dagger' }
154
+ answer = 'Well, Dagger sucks and so does Deputy, but Word Picture is pretty rad.'
155
+ 'Well, {bad_band} sucks and so does {other_bad_band}, but {good_band} is pretty rad.'[:snobbish, bands].should.equal answer
156
+ end
157
+
158
+ specify "should not affect existing string methods" do
159
+ string = "chris"
160
+ answer = 'ch'
161
+ string[0..1].should.equal answer
162
+ string[0, 2].should.equal answer
163
+ string[0].should.equal 99
164
+ string[/ch/].should.equal answer
165
+ string['ch'].should.equal answer
166
+ string['bc'].should.be.nil
167
+ string[/dog/].should.be.nil
168
+ end
169
+
170
+ specify "should return nil if a reserved key is used" do
171
+ "string"[:limit].should.be.nil
172
+ end
173
+
174
+ specify "should set default key to underscored string" do
175
+ Gibberish.current_language = :es
176
+ 'welcome friend'[].should == '�Bienvenido amigo!'
177
+ end
178
+ end
179
+
180
+ context "When a non-default language is set" do
181
+ setup do
182
+ Gibberish.current_language = :es
183
+ end
184
+
185
+ specify "that language should be used" do
186
+ Gibberish.current_language.should.equal :es
187
+ end
188
+
189
+ specify "the default language should not be used" do
190
+ Gibberish.should.not.be.default_language
191
+ end
192
+
193
+ specify "a gibberish string should return itself if a corresponding key is not found" do
194
+ string = "The internet!"
195
+ string[:the_internet].should.equal string
196
+ end
197
+
198
+ specify "a gibberish string should return a translated version of itself if a corresponding key is found" do
199
+ "Welcome, friend!"[:welcome_friend].should.equal '�Bienvenido amigo!'
200
+ "I love Rails."[:love_rails].should.equal "Amo los carriles."
201
+ 'Welcome, {user}!'[:welcome_user, 'Marvin'].should.equal '�Bienvenido Marvin!'
202
+ end
203
+ end