zena 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. data/History.txt +23 -0
  2. data/README.rdoc +1 -1
  3. data/app/controllers/columns_controller.rb +3 -31
  4. data/app/controllers/comments_controller.rb +8 -3
  5. data/app/controllers/data_entries_controller.rb +1 -1
  6. data/app/controllers/documents_controller.rb +2 -2
  7. data/app/controllers/nodes_controller.rb +29 -12
  8. data/app/controllers/relations_controller.rb +2 -2
  9. data/app/controllers/sites_controller.rb +1 -1
  10. data/app/controllers/user_sessions_controller.rb +6 -3
  11. data/app/controllers/users_controller.rb +18 -16
  12. data/app/controllers/versions_controller.rb +20 -18
  13. data/app/controllers/virtual_classes_controller.rb +103 -17
  14. data/app/helpers/users_helper.rb +1 -1
  15. data/app/models/column.rb +19 -50
  16. data/app/models/comment.rb +2 -1
  17. data/app/models/node.rb +45 -22
  18. data/app/models/relation.rb +13 -0
  19. data/app/models/relation_proxy.rb +3 -2
  20. data/app/models/role.rb +213 -4
  21. data/app/models/site.rb +18 -11
  22. data/app/models/template.rb +37 -35
  23. data/app/models/version.rb +1 -1
  24. data/app/models/virtual_class.rb +154 -86
  25. data/app/views/columns/_li.html.erb +1 -1
  26. data/app/views/columns/index.html.erb +1 -9
  27. data/app/views/comments/index.rhtml +10 -8
  28. data/app/views/documents/_crop.rhtml +5 -6
  29. data/app/views/documents/crop_form.rjs +3 -2
  30. data/app/views/groups/index.rhtml +1 -1
  31. data/app/views/iformats/index.rhtml +1 -1
  32. data/app/views/nodes/_import_results.rhtml +1 -1
  33. data/app/views/nodes/_parent.rhtml +1 -2
  34. data/app/views/nodes/update.rjs +3 -4
  35. data/app/views/relations/index.erb +1 -1
  36. data/app/views/sites/index.erb +1 -1
  37. data/app/views/templates/drive_tabs/_drive.rhtml +0 -2
  38. data/app/views/templates/edit_tabs/_image.rhtml +1 -1
  39. data/app/views/templates/edit_tabs/_title.rhtml +0 -6
  40. data/app/views/users/index.rhtml +1 -1
  41. data/app/views/users/preferences.html.erb +2 -2
  42. data/app/views/versions/backup.rjs +1 -1
  43. data/app/views/versions/custom_tab.rhtml +9 -4
  44. data/app/views/versions/destroy.rjs +2 -2
  45. data/app/views/versions/update.rjs +2 -9
  46. data/app/views/virtual_classes/_form.erb +3 -2
  47. data/app/views/virtual_classes/import_prepare.html.erb +13 -0
  48. data/app/views/virtual_classes/index.erb +28 -8
  49. data/app/views/zafu/default/Node-+adminLayout.zafu +1 -13
  50. data/app/views/zafu/default/Node-+login.zafu +1 -0
  51. data/app/views/zafu/default/Node-+notFound.zafu +1 -1
  52. data/app/views/zafu/default/Node-+popupLayout.zafu +1 -2
  53. data/app/views/zafu/default/Node-+search.zafu +1 -1
  54. data/app/views/zafu/default/Node-admin.zafu +205 -0
  55. data/app/views/zafu/default/Node.zafu +11 -11
  56. data/bricks/captcha/lib/bricks/captcha.rb +3 -2
  57. data/bricks/mongrel/zena/init.rb +2 -1
  58. data/bricks/pdf/README +5 -5
  59. data/bricks/pdf/lib/bricks/pdf/engine/prince.rb +2 -2
  60. data/bricks/pdf/lib/bricks/pdf/engine/xhtml2pdf.rb +2 -2
  61. data/bricks/pdf/lib/bricks/pdf/install.rb +5 -5
  62. data/bricks/pdf/lib/bricks/pdf.rb +11 -11
  63. data/bricks/pdf/test/engines/test_prince.rb +4 -4
  64. data/bricks/pdf/test/engines/test_xhtml2pdf.rb +4 -4
  65. data/bricks/pdf/test/shoulda_macros/shoulda_pdf.rb +2 -2
  66. data/bricks/pdf/zena/init.rb +2 -2
  67. data/bricks/pdf/zena/tasks.rb +2 -2
  68. data/bricks/sphinx/lib/bricks/sphinx.rb +6 -2
  69. data/bricks/sphinx/zena/{sphinx.yml → sphinx.yml.erb} +2 -2
  70. data/bricks/sphinx/zena/tasks.rb +28 -2
  71. data/bricks/tags/lib/bricks/tags.rb +16 -1
  72. data/bricks/tags/zena/test/unit/tags_test.rb +15 -0
  73. data/bricks/tags/zena/test/zafu/tags.yml +5 -1
  74. data/bricks/worker/lib/bricks/worker.rb +39 -0
  75. data/bricks/worker/zena/deploy.rb +0 -2
  76. data/bricks/worker/zena/init.rb +1 -0
  77. data/bricks/worker/zena/test/sites/zena/delayed_jobs.yml +16 -0
  78. data/bricks/worker/zena/test/zafu/worker.yml +8 -0
  79. data/bricks/zena/zena/migrate/01_base.rb +36 -60
  80. data/bricks/zena/zena/migrate/02_zerox1_schema.rb +388 -0
  81. data/bricks/zena/zena/migrate/03_zerox1_data.rb +380 -0
  82. data/bricks/zena/zena/migrate/20110315161158_add_reverse_scope_to_roles.rb +9 -0
  83. data/config/database_example.yml +1 -1
  84. data/config/environment.rb +1 -1
  85. data/config/gems.yml +17 -14
  86. data/db/init/base/skins/default/Node-+index.zafu +8 -1
  87. data/db/init/base/skins/default/Node-+login.zafu +1 -0
  88. data/db/init/base/skins/default/Node-+popupLayout.zafu +1 -2
  89. data/db/init/base/skins/default/Node-+search.zafu +2 -2
  90. data/db/init/base/skins/default/Node.zafu +9 -9
  91. data/db/init/base/skins/default/{favicon.png → img/favicon.png} +0 -0
  92. data/db/init/base/skins/default/{style.css → img/style.css} +0 -0
  93. data/db/init/base/skins/default/img/translations.yml +11 -0
  94. data/db/init/base/skins/default/notes.zafu +7 -9
  95. data/doc/zafu_changes.yml +12 -0
  96. data/lib/bricks/loader.rb +38 -15
  97. data/lib/tasks/zena.rake +74 -24
  98. data/lib/zena/acts/enrollable.rb +4 -1
  99. data/lib/zena/acts/secure.rb +2 -48
  100. data/lib/zena/acts/serializable.rb +13 -1
  101. data/lib/zena/app.rb +9 -0
  102. data/lib/zena/code_syntax.rb +154 -151
  103. data/lib/zena/console.rb +141 -0
  104. data/lib/zena/controller/test_case.rb +1 -1
  105. data/lib/zena/db_helper/abstract_db.rb +17 -5
  106. data/lib/zena/db_helper/mysql.rb +14 -12
  107. data/lib/zena/db_helper/postgresql.rb +1 -2
  108. data/lib/zena/db_helper/sqlite3.rb +6 -6
  109. data/lib/zena/deploy/awstats.conf.rhtml +1 -1
  110. data/lib/zena/deploy/httpd.rhtml +6 -1
  111. data/lib/zena/deploy/vhost.rhtml +9 -1
  112. data/lib/zena/deploy.rb +12 -7
  113. data/lib/zena/foxy_parser.rb +3 -1
  114. data/lib/zena/info.rb +1 -1
  115. data/lib/zena/parser/zafu_tags.rb +1 -0
  116. data/lib/zena/parser/zazen_rules.rb +1 -1
  117. data/lib/zena/remote/node.rb +15 -3
  118. data/lib/zena/remote/serializable_array.rb +19 -0
  119. data/lib/zena/remote.rb +1 -0
  120. data/lib/zena/routes.rb +7 -2
  121. data/lib/zena/site_worker.rb +11 -1
  122. data/lib/zena/unit/test_case.rb +68 -0
  123. data/lib/zena/use/action.rb +6 -2
  124. data/lib/zena/use/ajax.rb +127 -53
  125. data/lib/zena/use/ancestry.rb +11 -8
  126. data/lib/zena/use/calendar.rb +265 -129
  127. data/lib/zena/use/conditional.rb +1 -1
  128. data/lib/zena/use/context.rb +5 -5
  129. data/lib/zena/use/dates.rb +172 -60
  130. data/lib/zena/use/display.rb +70 -39
  131. data/lib/zena/use/error_rendering.rb +1 -3
  132. data/lib/zena/use/field_index.rb +4 -1
  133. data/lib/zena/use/forms.rb +94 -72
  134. data/lib/zena/use/fulltext.rb +16 -24
  135. data/lib/zena/use/html_tags.rb +20 -12
  136. data/lib/zena/use/i18n.rb +37 -37
  137. data/lib/zena/use/image_builder.rb +8 -1
  138. data/lib/zena/use/ml_index.rb +16 -16
  139. data/lib/zena/use/prop_eval.rb +10 -5
  140. data/lib/zena/use/query_builder.rb +55 -23
  141. data/lib/zena/use/query_node.rb +51 -25
  142. data/lib/zena/use/refactor.rb +2 -28
  143. data/lib/zena/use/relations.rb +1 -1
  144. data/lib/zena/use/rendering.rb +29 -0
  145. data/lib/zena/use/scope_index.rb +75 -14
  146. data/lib/zena/use/search.rb +5 -10
  147. data/lib/zena/use/test_helper.rb +2 -2
  148. data/lib/zena/use/urls.rb +125 -104
  149. data/lib/zena/use/workflow.rb +2 -1
  150. data/lib/zena/use/zafu_attributes.rb +2 -2
  151. data/lib/zena/use/zafu_safe_definitions.rb +20 -0
  152. data/lib/zena/use/zafu_templates.rb +20 -6
  153. data/lib/zena/use/zazen.rb +31 -20
  154. data/lib/zena/view/test_case.rb +5 -0
  155. data/lib/zena/zafu_compiler.rb +24 -2
  156. data/lib/zena.rb +12 -6
  157. data/locale/de/LC_MESSAGES/zena.mo +0 -0
  158. data/locale/de/zena.po +1345 -1164
  159. data/locale/en/LC_MESSAGES/zena.mo +0 -0
  160. data/locale/en/zena.po +1275 -1129
  161. data/locale/fr/LC_MESSAGES/zena.mo +0 -0
  162. data/locale/fr/zena.mo +0 -0
  163. data/locale/fr/zena.po +1617 -1441
  164. data/locale/log.txt +9 -0
  165. data/locale/zena.pot +957 -748
  166. data/public/javascripts/prototype.js +1 -1
  167. data/public/javascripts/zena.js +99 -44
  168. data/public/stylesheets/admin.css +6 -4
  169. data/public/stylesheets/backend.css +71 -0
  170. data/public/stylesheets/calendar.css +24 -25
  171. data/public/stylesheets/code.css +11 -6
  172. data/public/stylesheets/comment.css +2 -1
  173. data/public/stylesheets/popup.css +7 -8
  174. data/test/custom_queries/complex.host.yml +15 -1
  175. data/test/fixtures/files/Node-test.zafu +29 -28
  176. data/test/fixtures/files/translations_de.yml +12 -1
  177. data/test/fixtures/files/translations_fr.yml +12 -1
  178. data/test/functional/comments_controller_test.rb +9 -0
  179. data/test/functional/iformats_controller_test.rb +1 -1
  180. data/test/functional/nodes_controller_test.rb +124 -35
  181. data/test/functional/users_controller_test.rb +132 -3
  182. data/test/functional/virtual_classes_controller_test.rb +75 -4
  183. data/test/integration/navigation_test.rb +51 -9
  184. data/test/integration/query_node/basic.yml +19 -7
  185. data/test/integration/query_node/complex.yml +1 -1
  186. data/test/integration/query_node/dates.yml +27 -1
  187. data/test/integration/query_node/filters.yml +1 -1
  188. data/test/integration/query_node/relations.yml +13 -4
  189. data/test/integration/query_node_test.rb +4 -0
  190. data/test/integration/xml_api_test.rb +6 -1
  191. data/test/integration/zafu_compiler/action.yml +3 -3
  192. data/test/integration/zafu_compiler/ajax.yml +103 -22
  193. data/test/integration/zafu_compiler/basic.yml +0 -52
  194. data/test/integration/zafu_compiler/calendar.yml +44 -20
  195. data/test/integration/zafu_compiler/comments.yml +53 -0
  196. data/test/integration/zafu_compiler/complex.yml +11 -11
  197. data/test/integration/zafu_compiler/complex_ok.yml +16 -3
  198. data/test/integration/zafu_compiler/conditional.yml +15 -5
  199. data/test/integration/zafu_compiler/context.yml +9 -0
  200. data/test/integration/zafu_compiler/dates.yml +43 -15
  201. data/test/integration/zafu_compiler/display.yml +60 -6
  202. data/test/integration/zafu_compiler/errors.yml +6 -2
  203. data/test/integration/zafu_compiler/forms.yml +45 -6
  204. data/test/integration/zafu_compiler/i18n.yml +8 -1
  205. data/test/integration/zafu_compiler/meta.yml +38 -0
  206. data/test/integration/zafu_compiler/query.yml +43 -4
  207. data/test/integration/zafu_compiler/relations.yml +26 -33
  208. data/test/integration/zafu_compiler/rubyless.yml +10 -0
  209. data/test/integration/zafu_compiler/safe_definitions.yml +21 -1
  210. data/test/integration/zafu_compiler/urls.yml +75 -5
  211. data/test/integration/zafu_compiler/version.yml +2 -2
  212. data/test/integration/zafu_compiler/zafu_attributes.yml +5 -1
  213. data/test/integration/zafu_compiler/zazen.yml +14 -6
  214. data/test/integration/zafu_compiler_test.rb +5 -1
  215. data/test/sites/complex/columns.yml +5 -0
  216. data/test/sites/complex/roles.yml +4 -0
  217. data/test/sites/zena/nodes.yml +13 -2
  218. data/test/sites/zena/roles.yml +13 -5
  219. data/test/sites/zena/versions.yml +27 -9
  220. data/test/unit/column_test.rb +51 -5
  221. data/test/unit/iformat_test.rb +2 -2
  222. data/test/unit/node_test.rb +29 -17
  223. data/test/unit/note_test.rb +1 -1
  224. data/test/unit/relation_proxy_test.rb +4 -5
  225. data/test/unit/relation_test.rb +16 -0
  226. data/test/unit/remote_test.rb +2 -2
  227. data/test/unit/role_test.rb +292 -4
  228. data/test/unit/site_test.rb +12 -0
  229. data/test/unit/template_test.rb +1 -1
  230. data/test/unit/text_document_test.rb +1 -1
  231. data/test/unit/virtual_class_test.rb +200 -83
  232. data/test/unit/zena/acts/enrollable_test.rb +26 -31
  233. data/test/unit/zena/use/calendar_test.rb +90 -37
  234. data/test/unit/zena/use/field_index_test.rb +28 -0
  235. data/test/unit/zena/use/html_tags_test.rb +7 -3
  236. data/test/unit/zena/use/ml_index_test.rb +2 -16
  237. data/test/unit/zena/use/nested_attributes_alias_view_test.rb +2 -2
  238. data/test/unit/zena/use/prop_eval_test.rb +50 -8
  239. data/test/unit/zena/use/query_node_test.rb +11 -0
  240. data/test/unit/zena/use/rendering_test.rb +72 -0
  241. data/test/unit/zena/use/scope_index_test.rb +37 -2
  242. data/test/unit/zena/use/urls_test.rb +10 -0
  243. data/test/unit/zena/use/zazen_test.rb +3 -3
  244. data/vendor/plugins/gettext_i18n_rails/Gemfile +11 -0
  245. data/vendor/plugins/gettext_i18n_rails/Gemfile.lock +92 -0
  246. data/vendor/plugins/gettext_i18n_rails/Rakefile +12 -17
  247. data/vendor/plugins/gettext_i18n_rails/Readme.md +215 -0
  248. data/vendor/plugins/gettext_i18n_rails/VERSION +1 -1
  249. data/vendor/plugins/gettext_i18n_rails/gettext_i18n_rails.gemspec +38 -34
  250. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/active_record.rb +1 -1
  251. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/backend.rb +30 -14
  252. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/haml_parser.rb +1 -1
  253. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/html_safe_translations.rb +29 -0
  254. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/i18n_hacks.rb +29 -1
  255. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/model_attributes_finder.rb +7 -1
  256. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/railtie.rb +10 -0
  257. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/ruby_gettext_extractor.rb +6 -2
  258. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/string_interpolate_fix.rb +20 -0
  259. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/tasks.rb +120 -0
  260. data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails.rb +10 -3
  261. data/vendor/plugins/gettext_i18n_rails/lib/tasks/gettext_rails_i18n.rake +1 -74
  262. data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb +51 -20
  263. data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb +12 -7
  264. data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb +32 -0
  265. data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb +38 -1
  266. data/vendor/plugins/gettext_i18n_rails/spec/rails2/Gemfile +11 -0
  267. data/vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb +1 -8
  268. data/zena.gemspec +2241 -2217
  269. metadata +123 -83
  270. data/.gitignore +0 -36
  271. data/app/views/nodes/_dates.rhtml +0 -13
  272. data/db/init/base/skins/default/Node-+adminLayout.zafu +0 -46
  273. data/db/init/base/skins/default/Node-tree.zafu +0 -19
  274. data/vendor/plugins/gettext_i18n_rails/README.markdown +0 -143
@@ -1,58 +1,62 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gettext_i18n_rails}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.19"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-06-17}
12
+ s.date = %q{2011-03-29}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.markdown"
16
- ]
17
14
  s.files = [
18
- "README.markdown",
19
- "Rakefile",
20
- "VERSION",
21
- "gettext_i18n_rails.gemspec",
22
- "init.rb",
23
- "lib/gettext_i18n_rails.rb",
24
- "lib/gettext_i18n_rails/action_controller.rb",
25
- "lib/gettext_i18n_rails/active_record.rb",
26
- "lib/gettext_i18n_rails/backend.rb",
27
- "lib/gettext_i18n_rails/haml_parser.rb",
28
- "lib/gettext_i18n_rails/i18n_hacks.rb",
29
- "lib/gettext_i18n_rails/model_attributes_finder.rb",
30
- "lib/gettext_i18n_rails/ruby_gettext_extractor.rb",
31
- "lib/tasks/gettext_rails_i18n.rake",
32
- "spec/gettext_i18n_rails/action_controller_spec.rb",
33
- "spec/gettext_i18n_rails/active_record_spec.rb",
34
- "spec/gettext_i18n_rails/backend_spec.rb",
35
- "spec/gettext_i18n_rails_spec.rb",
36
- "spec/spec_helper.rb"
15
+ "Gemfile",
16
+ "Gemfile.lock",
17
+ "Rakefile",
18
+ "Readme.md",
19
+ "VERSION",
20
+ "gettext_i18n_rails.gemspec",
21
+ "init.rb",
22
+ "lib/gettext_i18n_rails.rb",
23
+ "lib/gettext_i18n_rails/action_controller.rb",
24
+ "lib/gettext_i18n_rails/active_record.rb",
25
+ "lib/gettext_i18n_rails/backend.rb",
26
+ "lib/gettext_i18n_rails/haml_parser.rb",
27
+ "lib/gettext_i18n_rails/html_safe_translations.rb",
28
+ "lib/gettext_i18n_rails/i18n_hacks.rb",
29
+ "lib/gettext_i18n_rails/model_attributes_finder.rb",
30
+ "lib/gettext_i18n_rails/railtie.rb",
31
+ "lib/gettext_i18n_rails/ruby_gettext_extractor.rb",
32
+ "lib/gettext_i18n_rails/string_interpolate_fix.rb",
33
+ "lib/gettext_i18n_rails/tasks.rb",
34
+ "lib/tasks/gettext_rails_i18n.rake",
35
+ "spec/gettext_i18n_rails/action_controller_spec.rb",
36
+ "spec/gettext_i18n_rails/active_record_spec.rb",
37
+ "spec/gettext_i18n_rails/backend_spec.rb",
38
+ "spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
39
+ "spec/gettext_i18n_rails_spec.rb",
40
+ "spec/rails2/Gemfile",
41
+ "spec/spec_helper.rb"
37
42
  ]
38
43
  s.homepage = %q{http://github.com/grosser/gettext_i18n_rails}
39
- s.rdoc_options = ["--charset=UTF-8"]
40
44
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.6}
45
+ s.rubygems_version = %q{1.4.2}
42
46
  s.summary = %q{Simple FastGettext Rails integration.}
43
47
  s.test_files = [
44
- "spec/spec_helper.rb",
45
- "spec/gettext_i18n_rails/active_record_spec.rb",
46
- "spec/gettext_i18n_rails/backend_spec.rb",
47
- "spec/gettext_i18n_rails/action_controller_spec.rb",
48
- "spec/gettext_i18n_rails_spec.rb"
48
+ "spec/gettext_i18n_rails/action_controller_spec.rb",
49
+ "spec/gettext_i18n_rails/active_record_spec.rb",
50
+ "spec/gettext_i18n_rails/backend_spec.rb",
51
+ "spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
52
+ "spec/gettext_i18n_rails_spec.rb",
53
+ "spec/spec_helper.rb"
49
54
  ]
50
55
 
51
56
  if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
57
  s.specification_version = 3
54
58
 
55
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
60
  s.add_runtime_dependency(%q<fast_gettext>, [">= 0"])
57
61
  else
58
62
  s.add_dependency(%q<fast_gettext>, [">= 0"])
@@ -16,6 +16,6 @@ class ActiveRecord::Base
16
16
  private
17
17
 
18
18
  def self.gettext_translation_for_attribute_name(attribute)
19
- "#{self}|#{attribute.to_s.gsub('_',' ').capitalize}"
19
+ "#{self}|#{attribute.to_s.split('.').map! {|a| a.gsub('_',' ').capitalize }.join('|')}"
20
20
  end
21
21
  end
@@ -14,21 +14,10 @@ module GettextI18nRails
14
14
  end
15
15
 
16
16
  def translate(locale, key, options)
17
- flat_key = flatten_key key, options
18
- if FastGettext.key_exist?(flat_key)
19
- raise "no yet build..." if options[:locale]
20
- _(flat_key)
17
+ if gettext_key = gettext_key(key, options)
18
+ translation = FastGettext._(gettext_key)
19
+ interpolate(translation, options)
21
20
  else
22
- if self.class.translate_defaults
23
- [*options[:default]].each do |default|
24
- #try the more specific key first e.g. 'activerecord.errors.my custom message'
25
- flat_key = flatten_key default, options
26
- return FastGettext._(flat_key) if FastGettext.key_exist?(flat_key)
27
-
28
- #try the short key thereafter e.g. 'my custom message'
29
- return FastGettext._(default) if FastGettext.key_exist?(default)
30
- end
31
- end
32
21
  backend.translate locale, key, options
33
22
  end
34
23
  end
@@ -39,6 +28,33 @@ module GettextI18nRails
39
28
 
40
29
  protected
41
30
 
31
+ def gettext_key(key, options)
32
+ flat_key = flatten_key key, options
33
+ if FastGettext.key_exist?(flat_key)
34
+ flat_key
35
+ elsif self.class.translate_defaults
36
+ [*options[:default]].each do |default|
37
+ #try the scoped(more specific) key first e.g. 'activerecord.errors.my custom message'
38
+ flat_key = flatten_key default, options
39
+ return flat_key if FastGettext.key_exist?(flat_key)
40
+
41
+ #try the short key thereafter e.g. 'my custom message'
42
+ return default if FastGettext.key_exist?(default)
43
+ end
44
+ return nil
45
+ end
46
+ end
47
+
48
+ def interpolate(string, values)
49
+ reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+
50
+ I18n::RESERVED_KEYS
51
+ else
52
+ I18n::Backend::Base::RESERVED_KEYS
53
+ end
54
+
55
+ string % values.except(*reserved_keys)
56
+ end
57
+
42
58
  def flatten_key key, options
43
59
  scope = [*(options[:scope] || [])]
44
60
  scope.empty? ? key.to_s : "#{scope*'.'}.#{key}"
@@ -27,7 +27,7 @@ module GettextI18nRails
27
27
  def load_haml
28
28
  return true if @haml_loaded
29
29
  begin
30
- require "#{RAILS_ROOT}/vendor/plugins/haml/lib/haml"
30
+ require "#{::Rails.root.to_s}/vendor/plugins/haml/lib/haml"
31
31
  rescue LoadError
32
32
  begin
33
33
  require 'haml' # From gem
@@ -0,0 +1,29 @@
1
+ module GettextI18nRails
2
+ mattr_accessor :translations_are_html_safe
3
+
4
+ module HtmlSafeTranslations
5
+ # also make available on class methods
6
+ def self.included(base)
7
+ base.extend self
8
+ end
9
+
10
+ def _(*args)
11
+ html_safe_if_wanted super
12
+ end
13
+
14
+ def n_(*args)
15
+ html_safe_if_wanted super
16
+ end
17
+
18
+ def s_(*args)
19
+ html_safe_if_wanted super
20
+ end
21
+
22
+ private
23
+
24
+ def html_safe_if_wanted(text)
25
+ return text unless GettextI18nRails.translations_are_html_safe
26
+ text.to_s.html_safe
27
+ end
28
+ end
29
+ end
@@ -1,10 +1,38 @@
1
1
  module I18n
2
2
  module_function
3
- # this is not chainable, since FastGettext may reject this locale!
3
+
4
4
  def locale=(new_locale)
5
5
  FastGettext.locale = new_locale
6
6
  end
7
+
7
8
  def locale
8
9
  FastGettext.locale.to_sym
9
10
  end
11
+
12
+ # since Rails 2.3.8 a config object is used instead of just .locale
13
+ if defined? Config
14
+ class Config
15
+ def locale
16
+ FastGettext.locale.to_sym
17
+ end
18
+
19
+ def locale=(new_locale)
20
+ FastGettext.locale=(new_locale)
21
+ end
22
+ end
23
+ end
24
+
25
+ # backport I18n.with_locale if it does not exist
26
+ unless respond_to?(:with_locale)
27
+ # Executes block with given I18n.locale set.
28
+ def with_locale(tmp_locale = nil)
29
+ if tmp_locale
30
+ current_locale = self.locale
31
+ self.locale = tmp_locale
32
+ end
33
+ yield
34
+ ensure
35
+ self.locale = current_locale if tmp_locale
36
+ end
37
+ end
10
38
  end
@@ -6,7 +6,12 @@ module GettextI18nRails
6
6
  f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
7
7
  ModelAttributesFinder.new.find(options).each do |table_name,column_names|
8
8
  #model name
9
- model = table_name.singularize.camelcase.constantize
9
+ begin
10
+ model = table_name.singularize.camelcase.constantize
11
+ rescue NameError
12
+ # Some tables are not models, for example: translation tables created by globalize2.
13
+ next
14
+ end
10
15
  f.puts("_('#{model.human_name_without_translation}')")
11
16
 
12
17
  #all columns namespaced under the model
@@ -18,6 +23,7 @@ module GettextI18nRails
18
23
  f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
19
24
  end
20
25
  end
26
+ module_function :store_model_attributes
21
27
 
22
28
  class ModelAttributesFinder
23
29
  # options:
@@ -0,0 +1,10 @@
1
+ # add rake tasks if we are inside Rails
2
+ if defined?(Rails::Railtie)
3
+ module GettextI18nRails
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ require 'gettext_i18n_rails/tasks'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -44,7 +44,11 @@ module RubyGettextExtractor
44
44
  end
45
45
 
46
46
  def run(content)
47
- self.parse(content)
47
+ # ruby parser has an ugly bug which causes that several \000's take
48
+ # ages to parse. This avoids this probelm by stripping them away (they probably wont appear in keys anyway)
49
+ # See bug report: http://rubyforge.org/tracker/index.php?func=detail&aid=26898&group_id=439&atid=1778
50
+ safe_content = content.gsub(/\\\d\d\d/, '')
51
+ self.parse(safe_content)
48
52
  return @results
49
53
  end
50
54
 
@@ -109,7 +113,7 @@ module RubyGettextExtractor
109
113
  def new_call recv, meth, args = nil
110
114
  # we dont care if the method is called on a a object
111
115
  if recv.nil?
112
- if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext)
116
+ if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext || meth == :s_)
113
117
  key = extract_key(args, "\004")
114
118
  elsif meth == :n_
115
119
  key = extract_key(args, "\000")
@@ -0,0 +1,20 @@
1
+ needed = "".respond_to?(:html_safe) and
2
+ (
3
+ "".html_safe % {:x => '<br/>'} == '<br/>' or
4
+ not ("".html_safe % {:x=>'a'}).html_safe?
5
+ )
6
+
7
+ if needed
8
+ class String
9
+ alias :interpolate_without_html_safe :%
10
+
11
+ def %(*args)
12
+ if args.first.is_a?(Hash) and html_safe?
13
+ safe_replacement = Hash[args.first.map{|k,v| [k,ERB::Util.h(v)] }]
14
+ interpolate_without_html_safe(safe_replacement).html_safe
15
+ else
16
+ interpolate_without_html_safe(*args).dup # make sure its not html_safe
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,120 @@
1
+ namespace :gettext do
2
+ def load_gettext
3
+ require 'gettext'
4
+ require 'gettext/utils'
5
+ end
6
+
7
+ desc "Create mo-files for L10n"
8
+ task :pack => :environment do
9
+ load_gettext
10
+ GetText.create_mofiles(true, locale_path, locale_path)
11
+ end
12
+
13
+ desc "Update pot/po files."
14
+ task :find => :environment do
15
+ load_gettext
16
+ $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
17
+ require 'gettext_i18n_rails/haml_parser'
18
+
19
+
20
+ if GetText.respond_to? :update_pofiles_org
21
+ GetText.update_pofiles_org(
22
+ text_domain,
23
+ files_to_translate,
24
+ "version 0.0.1",
25
+ :po_root => locale_path,
26
+ :msgmerge=>['--sort-output']
27
+ )
28
+ else #we are on a version < 2.0
29
+ puts "install new GetText with gettext:install to gain more features..."
30
+ #kill ar parser...
31
+ require 'gettext/parser/active_record'
32
+ module GetText
33
+ module ActiveRecordParser
34
+ module_function
35
+ def init(x);end
36
+ end
37
+ end
38
+
39
+ #parse files.. (models are simply parsed as ruby files)
40
+ GetText.update_pofiles(
41
+ text_domain,
42
+ files_to_translate,
43
+ "version 0.0.1",
44
+ locale_path
45
+ )
46
+ end
47
+ end
48
+
49
+ # This is more of an example, ignoring
50
+ # the columns/tables that mostly do not need translation.
51
+ # This can also be done with GetText::ActiveRecord
52
+ # but this crashed too often for me, and
53
+ # IMO which column should/should-not be translated does not
54
+ # belong into the model
55
+ #
56
+ # You can get your translations from GetText::ActiveRecord
57
+ # by adding this to you gettext:find task
58
+ #
59
+ # require 'active_record'
60
+ # gem "gettext_activerecord", '>=0.1.0' #download and install from github
61
+ # require 'gettext_activerecord/parser'
62
+ desc "write the model attributes to <locale_path>/model_attributes.rb"
63
+ task :store_model_attributes => :environment do
64
+ FastGettext.silence_errors
65
+
66
+ require 'gettext_i18n_rails/model_attributes_finder'
67
+ require 'gettext_i18n_rails/active_record'
68
+
69
+ storage_file = "#{locale_path}/model_attributes.rb"
70
+ puts "writing model translations to: #{storage_file}"
71
+
72
+ ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
73
+ GettextI18nRails.store_model_attributes(
74
+ :to => storage_file,
75
+ :ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],
76
+ :ignore_tables => ignore_tables
77
+ )
78
+ end
79
+
80
+ desc "add a new language"
81
+ task :add_language, [:language] => :environment do |_, args|
82
+ language = args.language || ENV["LANGUAGE"]
83
+
84
+ # Let's do some pre-verification of the environment.
85
+ if language.nil?
86
+ puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:add_languange' or 'rake gettext:add_languange[eo]'"
87
+ next
88
+ end
89
+ pot = File.join(locale_path, "#{text_domain}.pot")
90
+ if !File.exists? pot
91
+ puts "You don't have a pot file yet, you probably should run 'rake gettext:find' at least once. Tried '#{pot}'."
92
+ next
93
+ end
94
+
95
+ # Create the directory for the new language.
96
+ dir = File.join(locale_path, language)
97
+ puts "Creating directory #{dir}"
98
+ Dir.mkdir dir
99
+
100
+ # Create the po file for the new language.
101
+ new_po = File.join(locale_path, language, "#{text_domain}.po")
102
+ puts "Initializing #{new_po} from #{pot}."
103
+ system "msginit --locale=#{language} --input=#{pot} --output=#{new_po}"
104
+ end
105
+
106
+ def locale_path
107
+ FastGettext.translation_repositories[text_domain].instance_variable_get(:@options)[:path]
108
+ rescue
109
+ File.join(RAILS_ROOT, "locale")
110
+ end
111
+
112
+ def text_domain
113
+ # if your textdomain is not 'app': require the environment before calling e.g. gettext:find OR add TEXTDOMAIN=my_domain
114
+ ENV['TEXTDOMAIN'] || (FastGettext.text_domain rescue nil) || "app"
115
+ end
116
+
117
+ def files_to_translate
118
+ Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml}")
119
+ end
120
+ end
@@ -10,11 +10,18 @@ if Gem::Version.new(FastGettext::VERSION) < Gem::Version.new("0.4.8")
10
10
  end
11
11
 
12
12
  # include translations into all the places it needs to go...
13
- Object.send(:include,FastGettext::Translation)
13
+ Object.send(:include, FastGettext::Translation)
14
+
15
+ # make translations html_safe if possible and wanted
16
+ if "".respond_to?(:html_safe?)
17
+ require 'gettext_i18n_rails/html_safe_translations'
18
+ Object.send(:include, GettextI18nRails::HtmlSafeTranslations)
19
+ end
14
20
 
15
21
  require 'gettext_i18n_rails/backend'
16
22
  I18n.backend = GettextI18nRails::Backend.new
17
23
 
18
24
  require 'gettext_i18n_rails/i18n_hacks'
19
- require 'gettext_i18n_rails/active_record'
20
- require 'gettext_i18n_rails/action_controller'
25
+ require 'gettext_i18n_rails/active_record' if defined?(ActiveRecord)
26
+ require 'gettext_i18n_rails/action_controller' if defined?(ActionController) # so that bundle console can work in a rails project
27
+ require 'gettext_i18n_rails/railtie'
@@ -1,74 +1 @@
1
- namespace :gettext do
2
- def load_gettext
3
- require 'gettext'
4
- require 'gettext/utils'
5
- end
6
-
7
- desc "Create mo-files for L10n"
8
- task :pack do
9
- load_gettext
10
- GetText.create_mofiles(true, "locale", "locale")
11
- end
12
-
13
- desc "Update pot/po files."
14
- task :find do
15
- load_gettext
16
- $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
17
- require 'gettext_i18n_rails/haml_parser'
18
-
19
- if GetText.respond_to? :update_pofiles_org
20
- GetText.update_pofiles_org(
21
- "app",
22
- Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml}"),
23
- "version 0.0.1",
24
- :po_root => 'locale',
25
- :msgmerge=>['--sort-output']
26
- )
27
- else #we are on a version < 2.0
28
- puts "install new GetText with gettext:install to gain more features..."
29
- #kill ar parser...
30
- require 'gettext/parser/active_record'
31
- module GetText
32
- module ActiveRecordParser
33
- module_function
34
- def init(x);end
35
- end
36
- end
37
-
38
- #parse files.. (models are simply parsed as ruby files)
39
- GetText.update_pofiles(
40
- "app",
41
- Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml}"),
42
- "version 0.0.1",
43
- 'locale'
44
- )
45
- end
46
- end
47
-
48
- # This is more of an example, ignoring
49
- # the columns/tables that mostly do not need translation.
50
- # This can also be done with GetText::ActiveRecord
51
- # but this crashed too often for me, and
52
- # IMO which column should/should-not be translated does not
53
- # belong into the model
54
- #
55
- # You can get your translations from GetText::ActiveRecord
56
- # by adding this to you gettext:find task
57
- #
58
- # require 'active_record'
59
- # gem "gettext_activerecord", '>=0.1.0' #download and install from github
60
- # require 'gettext_activerecord/parser'
61
- desc "write the locale/model_attributes.rb"
62
- task :store_model_attributes => :environment do
63
- FastGettext.silence_errors
64
- require 'gettext_i18n_rails/model_attributes_finder'
65
- storage_file = 'locale/model_attributes.rb'
66
- puts "writing model translations to: #{storage_file}"
67
- ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions']
68
- GettextI18nRails.store_model_attributes(
69
- :to => storage_file,
70
- :ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],
71
- :ignore_tables => ignore_tables
72
- )
73
- end
74
- end
1
+ require File.join(File.dirname(__FILE__), "/../gettext_i18n_rails/tasks")
@@ -12,10 +12,21 @@ ActiveRecord::Schema.define(:version => 1) do
12
12
  create_table :car_seats, :force=>true do |t|
13
13
  t.string :seat_color
14
14
  end
15
+
16
+ create_table :parts, :force=>true do |t|
17
+ t.string :name
18
+ t.references :car_seat
19
+ end
15
20
  end
16
21
 
17
22
  class CarSeat < ActiveRecord::Base
18
23
  validates_presence_of :seat_color, :message=>"translate me"
24
+ has_many :parts
25
+ accepts_nested_attributes_for :parts
26
+ end
27
+
28
+ class Part < ActiveRecord::Base
29
+ belongs_to :car_seat
19
30
  end
20
31
 
21
32
  describe ActiveRecord::Base do
@@ -23,30 +34,50 @@ describe ActiveRecord::Base do
23
34
  FastGettext.current_cache = {}
24
35
  end
25
36
 
26
- it "has a human name that is translated through FastGettext" do
27
- CarSeat.should_receive(:_).with('car seat').and_return('Autositz')
28
- CarSeat.human_name.should == 'Autositz'
37
+ describe :human_name do
38
+ it "is translated through FastGettext" do
39
+ CarSeat.should_receive(:_).with('car seat').and_return('Autositz')
40
+ CarSeat.human_name.should == 'Autositz'
41
+ end
29
42
  end
30
43
 
31
- it "translates attributes through FastGettext" do
32
- CarSeat.should_receive(:s_).with('CarSeat|Seat color').and_return('Sitz farbe')
33
- CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe'
34
- end
44
+ describe :human_attribute_name do
45
+ it "translates attributes through FastGettext" do
46
+ CarSeat.should_receive(:s_).with('CarSeat|Seat color').and_return('Sitz farbe')
47
+ CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe'
48
+ end
35
49
 
36
- it "translates error messages" do
37
- FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz mich!")
38
- FastGettext._('translate me').should == "Übersetz mich!"
39
- c = CarSeat.new
40
- c.valid?
41
- c.errors.on(:seat_color).should == "Übersetz mich!"
50
+ it "translates nested attributes through FastGettext" do
51
+ CarSeat.should_receive(:s_).with('CarSeat|Parts|Name').and_return('Handle')
52
+ CarSeat.human_attribute_name(:"parts.name").should == 'Handle'
53
+ end
42
54
  end
43
55
 
44
- it "translates scoped error messages" do
45
- pending 'scope is no longer added in 3.x' if ActiveRecord::VERSION::MAJOR >= 3
46
- FastGettext.stub!(:current_repository).and_return('activerecord.errors.translate me'=>"Übersetz mich!")
47
- FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!"
48
- c = CarSeat.new
49
- c.valid?
50
- c.errors.on(:seat_color).should == "Übersetz mich!"
56
+ describe 'error messages' do
57
+ let(:model){
58
+ c = CarSeat.new
59
+ c.valid?
60
+ c
61
+ }
62
+
63
+ it "translates error messages" do
64
+ FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz mich!")
65
+ FastGettext._('translate me').should == "Übersetz mich!"
66
+ model.errors.on(:seat_color).should == "Übersetz mich!"
67
+ end
68
+
69
+ it "translates scoped error messages" do
70
+ pending 'scope is no longer added in 3.x' if ActiveRecord::VERSION::MAJOR >= 3
71
+ FastGettext.stub!(:current_repository).and_return('activerecord.errors.translate me'=>"Übersetz mich!")
72
+ FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!"
73
+ model.errors.on(:seat_color).should == "Übersetz mich!"
74
+ end
75
+
76
+ it "translates error messages with %{fn}" do
77
+ pending
78
+ FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz %{fn} mich!")
79
+ FastGettext._('translate me').should == "Übersetz %{fn} mich!"
80
+ model.errors.on(:seat_color).should == "Übersetz car_seat mich!"
81
+ end
51
82
  end
52
83
  end