zen 0.2.8 → 0.3b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (422) hide show
  1. data/.gems +20 -0
  2. data/.mailmap +3 -2
  3. data/.rvmrc +1 -1
  4. data/.travis.yml +13 -2
  5. data/.yardopts +13 -0
  6. data/AUTHORS +1 -1
  7. data/README.md +115 -77
  8. data/Rakefile +6 -7
  9. data/bin/zen +12 -5
  10. data/guide/_static/categories/categories.png +0 -0
  11. data/guide/_static/categories/category_groups.png +0 -0
  12. data/guide/_static/categories/new_category.png +0 -0
  13. data/guide/_static/categories/new_category_group.png +0 -0
  14. data/guide/_static/comments/comments.png +0 -0
  15. data/guide/_static/comments/edit_comment.png +0 -0
  16. data/guide/_static/custom_fields/custom_field_groups.png +0 -0
  17. data/guide/_static/custom_fields/custom_field_types.png +0 -0
  18. data/guide/_static/custom_fields/custom_fields.png +0 -0
  19. data/guide/_static/custom_fields/edit_custom_field_general.png +0 -0
  20. data/guide/_static/custom_fields/edit_custom_field_group.png +0 -0
  21. data/guide/_static/custom_fields/edit_custom_field_settings.png +0 -0
  22. data/guide/_static/custom_fields/edit_custom_field_type.png +0 -0
  23. data/guide/_static/menus/edit_menu.png +0 -0
  24. data/guide/_static/menus/edit_menu_item.png +0 -0
  25. data/guide/_static/menus/menu_items.png +0 -0
  26. data/guide/_static/menus/menus.png +0 -0
  27. data/guide/_static/sections/edit_entry.png +0 -0
  28. data/guide/_static/sections/edit_entry_categories.png +0 -0
  29. data/guide/_static/sections/edit_entry_general.png +0 -0
  30. data/guide/_static/sections/edit_entry_meta.png +0 -0
  31. data/guide/_static/sections/edit_section_comments.png +0 -0
  32. data/guide/_static/sections/edit_section_general.png +0 -0
  33. data/guide/_static/sections/edit_section_groups.png +0 -0
  34. data/guide/_static/sections/entries.png +0 -0
  35. data/guide/_static/sections/sections.png +0 -0
  36. data/guide/_static/settings/overview_general.png +0 -0
  37. data/guide/_static/settings/overview_security.png +0 -0
  38. data/guide/_static/settings/overview_user.png +0 -0
  39. data/guide/_static/users/edit_user.png +0 -0
  40. data/guide/_static/users/edit_user_group.png +0 -0
  41. data/guide/_static/users/edit_user_group_permissions.png +0 -0
  42. data/guide/_static/users/edit_user_permissions.png +0 -0
  43. data/guide/_static/users/overview.png +0 -0
  44. data/guide/_static/users/user_groups_overview.png +0 -0
  45. data/guide/asset_management.md +117 -0
  46. data/{CHANGELOG.md → guide/changelog.md} +42 -0
  47. data/guide/css/common.css +20 -0
  48. data/guide/getting_started.md +61 -0
  49. data/guide/hacking.md +52 -0
  50. data/guide/installation.md +44 -0
  51. data/guide/javascript.md +352 -0
  52. data/lib/vendor/sequel_sluggable.rb +137 -0
  53. data/lib/yard/tags.rb +13 -0
  54. data/lib/zen.rb +148 -78
  55. data/lib/zen/asset_groups.rb +85 -0
  56. data/lib/zen/bin/create.rb +267 -56
  57. data/lib/zen/bin/default.rb +84 -0
  58. data/lib/zen/controller/admin_controller.rb +1 -82
  59. data/lib/zen/controller/base_controller.rb +9 -5
  60. data/lib/zen/controller/frontend_controller.rb +0 -1
  61. data/lib/zen/controller/main_controller.rb +30 -42
  62. data/lib/zen/controller/preview.rb +9 -8
  63. data/lib/zen/controller/translations.rb +49 -0
  64. data/lib/zen/error.rb +17 -0
  65. data/lib/zen/event.rb +118 -0
  66. data/lib/zen/helper/asset.rb +63 -0
  67. data/lib/zen/helper/breadcrumb.rb +1 -4
  68. data/lib/zen/helper/controller.rb +73 -0
  69. data/lib/zen/helper/locale.rb +42 -0
  70. data/lib/zen/helper/message.rb +0 -3
  71. data/lib/zen/helper/search.rb +54 -0
  72. data/lib/zen/helper/stacked_aspect.rb +249 -0
  73. data/lib/zen/helper/theme.rb +3 -10
  74. data/lib/zen/language.rb +356 -181
  75. data/lib/zen/language/en/zen_general.rb +52 -0
  76. data/lib/zen/language/en/zen_models.rb +19 -0
  77. data/lib/zen/language/nl/zen_general.rb +57 -0
  78. data/lib/zen/language/nl/zen_models.rb +22 -0
  79. data/lib/zen/language/translation.rb +132 -0
  80. data/lib/zen/languages.rb +9 -0
  81. data/lib/zen/layout/admin.xhtml +3 -3
  82. data/lib/zen/layout/login.xhtml +1 -1
  83. data/lib/zen/markup.rb +189 -0
  84. data/lib/zen/model/helper.rb +65 -0
  85. data/lib/zen/model/init.rb +62 -0
  86. data/lib/zen/model/methods.rb +6 -7
  87. data/lib/zen/package.rb +312 -201
  88. data/lib/zen/package/all.rb +4 -3
  89. data/lib/zen/package/categories/lib/categories.rb +29 -41
  90. data/lib/zen/package/categories/lib/categories/controller/categories.rb +185 -130
  91. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +172 -102
  92. data/lib/zen/package/categories/lib/categories/helper/category.rb +4 -9
  93. data/lib/zen/package/categories/lib/categories/helper/category_frontend.rb +86 -0
  94. data/lib/zen/package/categories/lib/categories/language/en/categories.rb +40 -0
  95. data/lib/zen/package/categories/lib/categories/language/en/category_groups.rb +39 -0
  96. data/lib/zen/package/categories/lib/categories/language/nl/categories.rb +42 -0
  97. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.rb +42 -0
  98. data/lib/zen/package/categories/lib/categories/model/category.rb +21 -25
  99. data/lib/zen/package/categories/lib/categories/model/category_group.rb +21 -15
  100. data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +25 -26
  101. data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +24 -24
  102. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/form.xhtml +18 -20
  103. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +21 -18
  104. data/lib/zen/package/comments/lib/comments.rb +30 -50
  105. data/lib/zen/package/comments/lib/comments/anti_spam.rb +138 -0
  106. data/lib/zen/package/comments/lib/comments/controller/comments.rb +159 -92
  107. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +122 -34
  108. data/lib/zen/package/comments/lib/comments/helper/comment.rb +0 -3
  109. data/lib/zen/package/comments/lib/comments/helper/comment_frontend.rb +90 -0
  110. data/lib/zen/package/comments/lib/comments/language/en/comments.rb +57 -0
  111. data/lib/zen/package/comments/lib/comments/language/nl/comments.rb +61 -0
  112. data/lib/zen/package/comments/lib/comments/model/comment.rb +147 -49
  113. data/lib/zen/package/comments/lib/comments/model/comment_status.rb +0 -2
  114. data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +37 -40
  115. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +23 -42
  116. data/lib/zen/package/comments/migrations/1308774099_comment_status.rb +12 -4
  117. data/lib/zen/package/comments/migrations/1313851786_remove_defensio_signature.rb +11 -0
  118. data/lib/zen/package/custom_fields/lib/custom_fields.rb +40 -43
  119. data/lib/zen/package/custom_fields/lib/custom_fields/blue_form_parameters.rb +72 -17
  120. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +154 -118
  121. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_types.rb +147 -90
  122. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +161 -131
  123. data/lib/zen/package/custom_fields/lib/custom_fields/helper/custom_field.rb +4 -9
  124. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_groups.rb +42 -0
  125. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_types.rb +51 -0
  126. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.rb +60 -0
  127. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.rb +41 -0
  128. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_types.rb +49 -0
  129. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.rb +61 -0
  130. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +18 -23
  131. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +20 -19
  132. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_method.rb +1 -3
  133. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb +19 -9
  134. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +18 -15
  135. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/form.xhtml +18 -18
  136. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +30 -24
  137. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/form.xhtml +15 -10
  138. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/index.xhtml +24 -19
  139. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +18 -13
  140. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +30 -20
  141. data/lib/zen/package/extensions/lib/extensions.rb +20 -0
  142. data/lib/zen/package/extensions/lib/extensions/controller/extensions.rb +41 -0
  143. data/lib/zen/package/extensions/lib/extensions/language/en/extensions.rb +23 -0
  144. data/lib/zen/package/extensions/lib/extensions/language/nl/extensions.rb +25 -0
  145. data/lib/zen/package/extensions/lib/extensions/view/admin/extensions/index.xhtml +86 -0
  146. data/lib/zen/package/menu.rb +109 -0
  147. data/lib/zen/package/menus/lib/menus.rb +25 -34
  148. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +143 -107
  149. data/lib/zen/package/menus/lib/menus/controller/menus.rb +166 -115
  150. data/lib/zen/package/menus/lib/menus/helper/menu.rb +2 -8
  151. data/lib/zen/package/menus/lib/menus/helper/menu_frontend.rb +114 -0
  152. data/lib/zen/package/menus/lib/menus/language/en/menu_items.rb +48 -0
  153. data/lib/zen/package/menus/lib/menus/language/en/menus.rb +48 -0
  154. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.rb +48 -0
  155. data/lib/zen/package/menus/lib/menus/language/nl/menus.rb +50 -0
  156. data/lib/zen/package/menus/lib/menus/model/menu.rb +24 -17
  157. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +37 -13
  158. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +32 -25
  159. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +23 -17
  160. data/lib/zen/package/menus/lib/menus/view/admin/menus/form.xhtml +31 -26
  161. data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +20 -22
  162. data/lib/zen/package/sections/lib/sections.rb +25 -68
  163. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +178 -138
  164. data/lib/zen/package/sections/lib/sections/controller/sections.rb +173 -140
  165. data/lib/zen/package/sections/lib/sections/helper/section.rb +3 -6
  166. data/lib/zen/package/sections/lib/sections/helper/section_frontend.rb +146 -0
  167. data/lib/zen/package/sections/lib/sections/language/en/section_entries.rb +50 -0
  168. data/lib/zen/package/sections/lib/sections/language/en/sections.rb +55 -0
  169. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.rb +50 -0
  170. data/lib/zen/package/sections/lib/sections/language/nl/sections.rb +55 -0
  171. data/lib/zen/package/sections/lib/sections/model/section.rb +36 -36
  172. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +52 -59
  173. data/lib/zen/package/sections/lib/sections/model/section_entry_status.rb +2 -2
  174. data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +24 -21
  175. data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +24 -26
  176. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +33 -31
  177. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +24 -25
  178. data/lib/zen/package/sections/migrations/1308672298_use_id_for_default_section.rb +14 -10
  179. data/lib/zen/package/sections/migrations/1308813320_section_entry_statuses.rb +12 -6
  180. data/lib/zen/package/settings/lib/settings.rb +25 -120
  181. data/lib/zen/package/settings/lib/settings/blue_form_parameters.rb +157 -0
  182. data/lib/zen/package/settings/lib/settings/controller/settings.rb +94 -69
  183. data/lib/zen/package/settings/lib/settings/language/en/settings.rb +41 -0
  184. data/lib/zen/package/settings/lib/settings/language/nl/settings.rb +41 -0
  185. data/lib/zen/package/settings/lib/settings/model/setting.rb +0 -2
  186. data/lib/zen/package/settings/lib/settings/setting.rb +379 -0
  187. data/lib/zen/package/settings/lib/settings/setting_groups.rb +11 -0
  188. data/lib/zen/package/settings/lib/settings/settings.rb +83 -0
  189. data/lib/zen/package/settings/lib/settings/settings_group.rb +84 -0
  190. data/lib/zen/package/settings/lib/settings/singleton_methods.rb +35 -0
  191. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +15 -57
  192. data/lib/zen/package/settings/migrations/1321197919_remove_unused_columns.rb +17 -0
  193. data/lib/zen/package/users/lib/users.rb +51 -36
  194. data/lib/zen/package/users/lib/users/controller/user_groups.rb +133 -98
  195. data/lib/zen/package/users/lib/users/controller/users.rb +253 -136
  196. data/lib/zen/package/users/lib/users/helper/access.rb +102 -0
  197. data/lib/zen/package/users/lib/users/helper/acl.rb +113 -0
  198. data/lib/zen/package/users/lib/users/helper/users.rb +41 -24
  199. data/lib/zen/package/users/lib/users/language/en/permissions.rb +16 -0
  200. data/lib/zen/package/users/lib/users/language/en/user_groups.rb +39 -0
  201. data/lib/zen/package/users/lib/users/language/en/users.rb +73 -0
  202. data/lib/zen/package/users/lib/users/language/nl/permissions.rb +16 -0
  203. data/lib/zen/package/users/lib/users/language/nl/user_groups.rb +41 -0
  204. data/lib/zen/package/users/lib/users/language/nl/users.rb +74 -0
  205. data/lib/zen/package/users/lib/users/model/permission.rb +28 -0
  206. data/lib/zen/package/users/lib/users/model/user.rb +104 -65
  207. data/lib/zen/package/users/lib/users/model/user_group.rb +28 -24
  208. data/lib/zen/package/users/lib/users/model/user_status.rb +27 -0
  209. data/lib/zen/package/users/lib/users/public/admin/css/users/permissions.css +22 -0
  210. data/lib/zen/package/users/lib/users/public/admin/js/users/permissions.js +33 -0
  211. data/lib/zen/package/users/lib/users/settings.rb +19 -0
  212. data/lib/zen/package/users/lib/users/view/admin/user-groups/form.xhtml +58 -28
  213. data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +19 -15
  214. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +93 -62
  215. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +23 -36
  216. data/lib/zen/package/users/lib/users/view/admin/users/login.xhtml +13 -6
  217. data/lib/zen/package/users/lib/users/view/admin/users/permissions.xhtml +33 -0
  218. data/lib/zen/package/users/lib/users/view/admin/users/register.xhtml +52 -0
  219. data/lib/zen/package/users/migrations/1313786058_update_default_date.rb +41 -0
  220. data/lib/zen/package/users/migrations/1316432327_permissions.rb +36 -0
  221. data/lib/zen/package/users/migrations/1320272365_status_ids.rb +67 -0
  222. data/lib/zen/public/admin/css/zen/buttons.css +3 -11
  223. data/lib/zen/public/admin/css/zen/datepicker.css +23 -13
  224. data/lib/zen/public/admin/css/zen/editor.css +6 -14
  225. data/lib/zen/public/admin/css/zen/forms.css +19 -12
  226. data/lib/zen/public/admin/css/zen/general.css +22 -18
  227. data/lib/zen/public/admin/css/zen/grid.css +1 -20
  228. data/lib/zen/public/admin/css/zen/layout.css +26 -11
  229. data/lib/zen/public/admin/css/zen/messages.css +3 -10
  230. data/lib/zen/public/admin/css/zen/reset.css +13 -15
  231. data/lib/zen/public/admin/css/zen/tables.css +8 -10
  232. data/lib/zen/public/admin/css/zen/tabs.css +2 -10
  233. data/lib/zen/public/admin/css/zen/window.css +2 -8
  234. data/lib/zen/public/admin/js/vendor/datepicker.js +540 -240
  235. data/lib/zen/public/admin/js/vendor/mootools/core.js +273 -283
  236. data/lib/zen/public/admin/js/vendor/mootools/more.js +131 -136
  237. data/lib/zen/public/admin/js/zen/index.js +8 -14
  238. data/lib/zen/public/admin/js/zen/lib/editor.js +36 -33
  239. data/lib/zen/public/admin/js/zen/lib/editor/markdown.js +0 -6
  240. data/lib/zen/public/admin/js/zen/lib/editor/textile.js +0 -6
  241. data/lib/zen/public/admin/js/zen/lib/html_table.js +0 -5
  242. data/lib/zen/public/admin/js/zen/lib/tabs.js +22 -79
  243. data/lib/zen/public/admin/js/zen/lib/window.js +12 -22
  244. data/lib/zen/spec/bacon/color_output.rb +1 -1
  245. data/lib/zen/spec/helper.rb +6 -11
  246. data/lib/zen/spec/simplecov.rb +3 -3
  247. data/lib/zen/task.rb +0 -1
  248. data/lib/zen/task/build.rake +46 -26
  249. data/lib/zen/task/clean.rake +14 -7
  250. data/lib/zen/task/db.rake +31 -29
  251. data/lib/zen/task/package.rake +19 -23
  252. data/lib/zen/task/proto.rake +3 -5
  253. data/lib/zen/task/setup.rake +4 -0
  254. data/lib/zen/task/test.rake +31 -6
  255. data/lib/zen/task/theme.rake +13 -19
  256. data/lib/zen/theme.rb +377 -52
  257. data/lib/zen/validation.rb +22 -30
  258. data/lib/zen/version.rb +1 -2
  259. data/lib/zen/view/bottom.xhtml +9 -1
  260. data/lib/zen/view/head.xhtml +1 -1
  261. data/lib/zen/view/main.xhtml +1 -1
  262. data/lib/zen/view/search.xhtml +9 -0
  263. data/proto/app/Rakefile +0 -1
  264. data/proto/app/app.rb +21 -16
  265. data/proto/app/config/config.rb.erb +41 -0
  266. data/proto/app/config/{database.rb → database.rb.erb} +17 -14
  267. data/proto/app/config/middlewares.rb +1 -1
  268. data/proto/app/theme/default/index.xhtml +25 -0
  269. data/proto/app/theme/theme.rb +19 -0
  270. data/proto/app/{log/database/dev → tmp}/.gitkeep +0 -0
  271. data/proto/migration.rb +3 -5
  272. data/proto/rack/thin.yml +41 -0
  273. data/proto/rack/unicorn.rb +38 -0
  274. data/spec/Rakefile +15 -11
  275. data/spec/fixtures/zen/helper/controller.rb +13 -0
  276. data/spec/fixtures/zen/helper/locale.rb +7 -0
  277. data/spec/fixtures/zen/helper/message.rb +0 -4
  278. data/spec/fixtures/zen/language.rb +31 -0
  279. data/spec/fixtures/zen/language/en/spec.rb +11 -0
  280. data/spec/fixtures/zen/language/nl/spec.rb +11 -0
  281. data/spec/fixtures/zen/package.rb +0 -10
  282. data/spec/fixtures/zen/package/categories/helper/category_frontend.rb +16 -0
  283. data/spec/fixtures/zen/package/comments/helper/comment_frontend.rb +16 -0
  284. data/spec/fixtures/zen/package/sections/helper/section_frontend.rb +16 -0
  285. data/spec/fixtures/zen/package/settings/controller/settings.rb +17 -0
  286. data/spec/fixtures/zen/package/users/helper/access.rb +18 -0
  287. data/spec/fixtures/zen/package/users/helper/acl.rb +23 -0
  288. data/spec/fixtures/zen/theme/{default-section → default}/index.xhtml +0 -0
  289. data/spec/helper.rb +12 -27
  290. data/{proto/app/log/database/live → spec/public}/.gitkeep +0 -0
  291. data/spec/zen/controller/admin_controller.rb +5 -6
  292. data/spec/zen/controller/main_controller.rb +29 -35
  293. data/spec/zen/controller/preview.rb +9 -10
  294. data/spec/zen/event.rb +44 -0
  295. data/spec/zen/helper/breadcrumb.rb +4 -5
  296. data/spec/zen/helper/controller.rb +21 -0
  297. data/spec/zen/helper/locale.rb +25 -0
  298. data/spec/zen/helper/message.rb +4 -11
  299. data/spec/zen/helper/theme.rb +11 -14
  300. data/spec/zen/language.rb +48 -22
  301. data/spec/zen/markup.rb +39 -0
  302. data/spec/zen/package.rb +48 -11
  303. data/spec/zen/package/categories/controller/categories.rb +99 -45
  304. data/spec/zen/package/categories/controller/category_groups.rb +109 -33
  305. data/spec/zen/package/categories/helper/category.rb +19 -32
  306. data/spec/zen/package/categories/helper/category_frontend.rb +61 -0
  307. data/spec/zen/package/comments/anti_spam.rb +50 -0
  308. data/spec/zen/package/comments/controller/comments.rb +121 -61
  309. data/spec/zen/package/comments/controller/comments_form.rb +120 -94
  310. data/spec/zen/package/comments/helper/comment.rb +13 -13
  311. data/spec/zen/package/comments/helper/comment_frontend.rb +92 -0
  312. data/spec/zen/package/custom_fields/blue_form_parameters.rb +50 -50
  313. data/spec/zen/package/custom_fields/controller/custom_field_groups.rb +135 -43
  314. data/spec/zen/package/custom_fields/controller/custom_field_types.rb +153 -48
  315. data/spec/zen/package/custom_fields/controller/custom_fields.rb +130 -51
  316. data/spec/zen/package/custom_fields/helper/custom_field.rb +8 -8
  317. data/spec/zen/package/extensions/controller/extensions.rb +38 -0
  318. data/spec/zen/package/menus/controller/menu_items.rb +121 -42
  319. data/spec/zen/package/menus/controller/menus.rb +125 -38
  320. data/spec/zen/package/menus/helper/menu.rb +26 -26
  321. data/spec/zen/package/menus/helper/menu_frontend.rb +104 -0
  322. data/spec/zen/package/sections/controller/section_entries.rb +145 -89
  323. data/spec/zen/package/sections/controller/sections.rb +130 -35
  324. data/spec/zen/package/sections/helper/section.rb +27 -38
  325. data/spec/zen/package/sections/helper/section_frontend.rb +160 -0
  326. data/spec/zen/package/settings/controller/settings.rb +73 -8
  327. data/spec/zen/package/settings/settings.rb +119 -0
  328. data/spec/zen/package/users/controller/user_groups.rb +134 -34
  329. data/spec/zen/package/users/controller/users.rb +189 -44
  330. data/spec/zen/package/users/helper/access.rb +29 -0
  331. data/spec/zen/package/users/helper/acl.rb +46 -0
  332. data/spec/zen/package/users/helper/users.rb +20 -64
  333. data/spec/zen/theme.rb +7 -9
  334. data/spec/zen/validation.rb +1 -2
  335. data/zen.gemspec +25 -22
  336. metadata +303 -222
  337. data/lib/zen/asset.rb +0 -292
  338. data/lib/zen/bin/runner.rb +0 -118
  339. data/lib/zen/error/language_error.rb +0 -10
  340. data/lib/zen/error/package_error.rb +0 -10
  341. data/lib/zen/error/plugin_error.rb +0 -10
  342. data/lib/zen/error/theme_error.rb +0 -10
  343. data/lib/zen/error/validation_error.rb +0 -10
  344. data/lib/zen/helper/acl.rb +0 -182
  345. data/lib/zen/helper/blue_form_vendor.rb +0 -689
  346. data/lib/zen/language/en/zen_general.yml +0 -25
  347. data/lib/zen/language/en/zen_models.yml +0 -13
  348. data/lib/zen/language/nl/zen_general.yml +0 -25
  349. data/lib/zen/language/nl/zen_models.yml +0 -13
  350. data/lib/zen/model/settings.rb +0 -78
  351. data/lib/zen/package/base.rb +0 -62
  352. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +0 -36
  353. data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +0 -34
  354. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +0 -40
  355. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +0 -34
  356. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +0 -141
  357. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +0 -48
  358. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +0 -50
  359. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +0 -156
  360. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +0 -115
  361. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_groups.yml +0 -33
  362. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_types.yml +0 -40
  363. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +0 -54
  364. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +0 -33
  365. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_types.yml +0 -40
  366. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +0 -54
  367. data/lib/zen/package/menus/lib/menus/language/en/menu_items.yml +0 -41
  368. data/lib/zen/package/menus/lib/menus/language/en/menus.yml +0 -40
  369. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +0 -41
  370. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +0 -40
  371. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +0 -152
  372. data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +0 -44
  373. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -48
  374. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +0 -44
  375. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +0 -48
  376. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +0 -244
  377. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +0 -87
  378. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +0 -36
  379. data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +0 -37
  380. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +0 -39
  381. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +0 -133
  382. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +0 -251
  383. data/lib/zen/package/users/lib/users/controller/access_rules.rb +0 -284
  384. data/lib/zen/package/users/lib/users/language/en/access_rules.yml +0 -38
  385. data/lib/zen/package/users/lib/users/language/en/user_groups.yml +0 -32
  386. data/lib/zen/package/users/lib/users/language/en/users.yml +0 -57
  387. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +0 -38
  388. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +0 -32
  389. data/lib/zen/package/users/lib/users/language/nl/users.yml +0 -57
  390. data/lib/zen/package/users/lib/users/model/access_rule.rb +0 -42
  391. data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +0 -65
  392. data/lib/zen/package/users/lib/users/public/admin/js/users/lib/access_rules.js +0 -49
  393. data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +0 -120
  394. data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +0 -102
  395. data/lib/zen/plugin.rb +0 -182
  396. data/lib/zen/plugin/base.rb +0 -46
  397. data/lib/zen/plugin/helper.rb +0 -47
  398. data/lib/zen/plugin/markup/lib/markup.rb +0 -14
  399. data/lib/zen/plugin/markup/lib/markup/language/en/markup.yml +0 -6
  400. data/lib/zen/plugin/markup/lib/markup/markup.rb +0 -165
  401. data/lib/zen/public/admin/js/zen/lib/asset.js +0 -111
  402. data/lib/zen/task/plugin.rake +0 -18
  403. data/lib/zen/theme/base.rb +0 -65
  404. data/proto/app/config/config.rb +0 -18
  405. data/spec/fixtures/zen/language/en/spec.yml +0 -10
  406. data/spec/fixtures/zen/language/nl/spec.yml +0 -7
  407. data/spec/fixtures/zen/package/settings/plugin/settings.rb +0 -20
  408. data/spec/zen/asset.rb +0 -97
  409. data/spec/zen/bin/create.rb +0 -89
  410. data/spec/zen/bin/runner.rb +0 -47
  411. data/spec/zen/helper/acl.rb +0 -149
  412. data/spec/zen/package/categories/plugin/categories.rb +0 -92
  413. data/spec/zen/package/comments/plugin/anti_spam.rb +0 -59
  414. data/spec/zen/package/comments/plugin/comments.rb +0 -107
  415. data/spec/zen/package/menus/plugin/menus.rb +0 -120
  416. data/spec/zen/package/sections/plugin/section_entries.rb +0 -161
  417. data/spec/zen/package/sections/plugin/sections.rb +0 -75
  418. data/spec/zen/package/settings/plugin/settings.rb +0 -33
  419. data/spec/zen/package/users/controller/access_rules.rb +0 -90
  420. data/spec/zen/plugin.rb +0 -64
  421. data/spec/zen/plugin/helper.rb +0 -11
  422. data/spec/zen/plugin/markup.rb +0 -44
@@ -1,76 +1,102 @@
1
- #:nodoc:
1
+ ##
2
+ # Package for managing and registering settings.
3
+ #
4
+ # ## Controllers
5
+ #
6
+ # * {Settings::Controller::Settings}
7
+ #
8
+ # ## Models
9
+ #
10
+ # * {Settings::Model::Setting}
11
+ #
12
+ # ## Generic Modules & Classes
13
+ #
14
+ # * {Settings::Setting}
15
+ # * {Settings::SettingsGroup}
16
+ # * {Settings::SingletonMethods}
17
+ #
2
18
  module Settings
3
19
  #:nodoc:
4
20
  module Controller
5
21
  ##
6
- # Controller for managing settings. Each setting is saved as a separate
7
- # row in the database, making management and retrieving them easier.
22
+ # Controller for managing settings. Settings are used to store the name of
23
+ # the website, what anti-spam system to use and so on. These settings can be
24
+ # managed via the admin interface rather than having to edit configuration
25
+ # files. Settings can be managed by going to ``/admin/settings``. This page
26
+ # shows an overview of all the available settings organized in a number of
27
+ # groups where each group is placed under it's own tab. An example of this
28
+ # overview can be seen in the image below.
29
+ #
30
+ # ![General](../../_static/settings/overview_general.png)
31
+ # ![Security](../../_static/settings/overview_security.png)
32
+ # ![User Settings](../../_static/settings/overview_user.png)
33
+ #
34
+ # Out of the box Zen ships with the following settings:
35
+ #
36
+ # * **Website name**: the name of the website.
37
+ # * **Website description**: a short description of the website.
38
+ # * **Language**: the default language to use for the admin interface.
39
+ # * **Frontend Language**: the default language to use for the frontend of
40
+ # your website.
41
+ # * **Theme**: the theme to use for the frontend.
42
+ # * **Date format**: the default date format to use in the backend.
43
+ # * **Enable anti-spam**: whether or not comments should be verified to see
44
+ # if they're spam or ham.
45
+ # * **Anti-spam system**: the anti-spam system to use. Zen by default only
46
+ # comes with Defensio support.
47
+ # * **Defensio key**: the API key for the Defensio anti-spam system.
48
+ # * **Allow Registration**: defines whether or not visitors are allowed to
49
+ # register a user account.
50
+ #
51
+ # ## Used Permissions
52
+ #
53
+ # This controller uses the following permissions:
54
+ #
55
+ # * show_setting
56
+ # * edit_setting
57
+ #
58
+ # ## Events
59
+ #
60
+ # Unlike other controllers events in this controller do not receive an
61
+ # instance of a model. Instead they'll receive an instance of
62
+ # {Settings::Plugin::SettingBase}. In order to update the value of a setting
63
+ # you'll simply call ``#value=()`` and specify a new value.
64
+ #
65
+ # @example Trimming the value of a setting
66
+ # Zen::Event(:after_edit_setting) do |setting|
67
+ # if setting.name == 'website_name'
68
+ # setting.value = setting.value.strip
69
+ # end
70
+ # end
8
71
  #
9
- # @author Yorick Peterse
10
72
  # @since 0.1
73
+ # @map /admin/settings
74
+ # @event after_edit_setting
11
75
  #
12
76
  class Settings < Zen::Controller::AdminController
13
- include ::Settings::Model
14
-
15
- map '/admin/settings'
77
+ map '/admin/settings'
78
+ title 'settings.titles.%s'
16
79
 
17
- # Load all required Javascript files
18
- javascript ['zen/lib/tabs']
19
-
20
- before_all do
21
- csrf_protection(:save, :delete) do
22
- respond(lang('zen_general.errors.csrf'), 403)
23
- end
24
- end
25
-
26
- ##
27
- # Load our language packs, set the form URLs and define our page title.
28
- #
29
- # This method loads the following language files:
30
- #
31
- # * settings
32
- #
33
- # @author Yorick Peterse
34
- # @since 0.1
35
- #
36
- def initialize
37
- super
38
-
39
- @form_save_url = Settings.r(:save)
40
-
41
- # Set the page title
42
- if !action.method.nil?
43
- method = action.method.to_sym
44
- @page_title = lang("settings.titles.#{method}") rescue nil
45
- end
46
- end
80
+ csrf_protection :save
81
+ load_asset_group :tabs
47
82
 
48
83
  ##
49
84
  # Show all settings and allow the user to change them.
50
- # The values of each setting item are stored in the database,
51
- # the descriptions, names and possible values are stored in
52
- # the language packs that come with this module.
53
- #
54
- # This method requires the following permissions:
55
85
  #
56
- # * read
57
- # * update
58
- #
59
- # @author Yorick Peterse
60
- # @since 0.1
86
+ # @since 0.1
87
+ # @permission show_setting
61
88
  #
62
89
  def index
63
- require_permissions(:read, :update)
90
+ authorize_user!(:show_setting)
64
91
 
65
92
  set_breadcrumbs(lang('settings.titles.index'))
66
93
 
67
94
  @settings_ordered = {}
68
- @groups = ::Settings::Plugin::Settings::Registered[:groups]
95
+ @groups = ::Settings::SettingsGroup::REGISTERED
69
96
 
70
97
  # Organize the settings so that each item is a child
71
98
  # item of it's group.
72
- ::Settings::Plugin::Settings::Registered[:settings].each \
73
- do |name, setting|
99
+ ::Settings::Setting::REGISTERED.each do |name, setting|
74
100
  if !@settings_ordered.key?(setting.group)
75
101
  @settings_ordered[setting.group] = []
76
102
  end
@@ -80,42 +106,41 @@ module Settings
80
106
  end
81
107
 
82
108
  ##
83
- # Saves the values of each setting. Since each setting
84
- # is a new row we'll have to loop through them and execute quite
85
- # a few queries.
86
- #
87
- # This method requires the following permissions:
109
+ # Updates all the settings in both the database and the cache
110
+ # (Ramaze::Cache.settings).
88
111
  #
89
- # * update
90
- #
91
- # @author Yorick Peterse
92
- # @since 0.1
112
+ # @since 0.1
113
+ # @permission edit_setting
114
+ # @event after_edit_setting
93
115
  #
94
116
  def save
95
- require_permissions(:update)
117
+ authorize_user!(:edit_setting)
96
118
 
97
- post = request.params.dup
119
+ post = request.params
98
120
  post.delete('csrf_token')
99
121
  post.delete('id')
100
122
 
101
- flash_success = lang('settings.success.save')
102
- flash_error = lang('settings.errors.save')
103
- success = true
123
+ success = lang('settings.success.save')
124
+ error = lang('settings.errors.save')
104
125
 
105
126
  # Update all settings
106
127
  post.each do |key, value|
128
+ setting = get_setting(key)
129
+
107
130
  begin
108
- plugin(:settings, :get, key).value = value
131
+ setting.value = value
109
132
  rescue => e
110
133
  Ramaze::Log.error(e.inspect)
111
- message(:error, flash_error)
134
+ message(:error, error)
112
135
 
113
136
  flash[:form_errors] = setting.errors
114
- success = false
137
+ redirect_referrer
115
138
  end
139
+
140
+ Zen::Event.call(:after_edit_setting, setting)
116
141
  end
117
142
 
118
- message(:success, flash_success) if success === true
143
+ message(:success, success)
119
144
  redirect_referrer
120
145
  end
121
146
  end # Settings
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ Zen::Language::Translation.add do |trans|
4
+ trans.language = 'en'
5
+ trans.name = 'settings'
6
+
7
+ trans.translate do |t|
8
+ t['titles.index'] = 'Settings'
9
+
10
+ t['labels.website_name'] = 'Website name'
11
+ t['labels.website_description'] = 'Website description'
12
+ t['labels.language'] = 'Language'
13
+ t['labels.frontend_language'] = 'Frontend language'
14
+ t['labels.theme'] = 'Theme'
15
+ t['labels.enable_antispam'] = 'Enable anti-spam'
16
+ t['labels.date_format'] = 'Date format'
17
+
18
+ t['descriptions.website_name'] = 'The name of the website.'
19
+ t['descriptions.website_description'] = 'The description of the website.'
20
+ t['descriptions.language'] = 'The language to use for the system.'
21
+ t['descriptions.theme'] = 'The frontend theme to use.'
22
+ t['descriptions.enable_antispam'] = 'Whether or not anti-spam protection ' \
23
+ 'should be used for comments'
24
+ t['descriptions.frontend_language'] = 'The language to use for the ' \
25
+ 'frontend of the website.'
26
+ t['descriptions.date_format'] = 'A custom format used for all the dates ' \
27
+ 'displayed in the backend.'
28
+
29
+ t['tabs.general'] = 'General'
30
+ t['tabs.security'] = 'Security'
31
+
32
+ t['buttons.save'] = 'Save'
33
+
34
+ t['success.save'] = 'The settings have been saved.'
35
+ t['errors.save'] = 'The settings could not be saved.'
36
+ t['description'] = 'Package for managing settings.'
37
+
38
+ t['permissions.show'] = 'Show setting'
39
+ t['permissions.edit'] = 'Edit setting'
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ Zen::Language::Translation.add do |trans|
4
+ trans.language = 'nl'
5
+ trans.name = 'settings'
6
+
7
+ trans.translate do |t|
8
+ t['titles.index'] = 'Instellingen'
9
+
10
+ t['labels.website_name'] = 'Website naam'
11
+ t['labels.website_description'] = 'Website beschrijving'
12
+ t['labels.language'] = 'Taal'
13
+ t['labels.frontend_langauge'] = 'Taal voor bezoekers'
14
+ t['labels.theme'] = 'Thema'
15
+ t['labels.enable_antispam'] = 'Anti-spam inschakelen'
16
+ t['labels.date_format'] = 'Datum formaat'
17
+
18
+ t['descriptions.website_name'] = 'De naam van de website.'
19
+ t['descriptions.website_description'] = 'De beschrijving van de website.'
20
+ t['descriptions.language'] = 'De taal die gebruikt moet worden '\
21
+ 'voor het admin gedeelte.'
22
+ t['descriptions.theme'] = 'Het thema dat bezoekers zullen zien.'
23
+ t['descriptions.enable_antispam'] = 'Waarde die aangeeft of het anti-spam ' \
24
+ 'systeem moet worden gebruikt voor reacties.'
25
+ t['descriptions.frontend_language'] = 'De taal die gebruikt moet worden '\
26
+ 'voor bezoekers.'
27
+ t['descriptions.date_format'] = 'Het formaat van de datum voor het '\
28
+ 'admin gedeelte.'
29
+
30
+ t['tabs.general'] = 'Algemeen'
31
+ t['tabs.security'] = 'Beveiliging'
32
+
33
+ t['buttons.save'] = 'Opslaan'
34
+ t['success.save'] = 'De instellingen zijn opgeslagen.'
35
+ t['errors.save'] = 'De instellingen konden niet worden opgeslagen.'
36
+ t['description'] = 'Pakket voor het beheren van instellingen.'
37
+
38
+ t['permissions.show'] = 'Instelling weergeven'
39
+ t['permissions.edit'] = 'Instelling aanpassen'
40
+ end
41
+ end
@@ -1,11 +1,9 @@
1
- #:nodoc:
2
1
  module Settings
3
2
  #:nodoc:
4
3
  module Model
5
4
  ##
6
5
  # Model that represents a single setting.
7
6
  #
8
- # @author Yorick Peterse
9
7
  # @since 0.1
10
8
  #
11
9
  class Setting < Sequel::Model
@@ -0,0 +1,379 @@
1
+ module Settings
2
+ ##
3
+ # {Settings::Setting} is a class that can be used to register and migrate
4
+ # settings without having to manually insert the data. It provides an API
5
+ # similar to registering packages or themes and takes care of synchronizing
6
+ # data between the database and the cache.
7
+ #
8
+ # ## Adding Settings
9
+ #
10
+ # In order to add a setting you'll first need to ensure there's at least a
11
+ # single setting group available. These groups don't add any extra features
12
+ # or whatsoever but are used to display settings in different tabs in the
13
+ # backend interface. In order to register a new group you'd write the
14
+ # following code:
15
+ #
16
+ # Settings::SettingsGroup.add do |group|
17
+ # group.title = 'My Group'
18
+ # group.name = :my_group
19
+ # end
20
+ #
21
+ # When registering a group you only need to specify a title and a name. The
22
+ # name is used to associate a setting with it's group and thus should always
23
+ # be unique. The title is displayed in the tab for the specific settings
24
+ # group.
25
+ #
26
+ # Once a setting group has been added we can add a setting as following:
27
+ #
28
+ # Settings::Setting.add do |setting|
29
+ # setting.title = 'My Setting'
30
+ # setting.description = 'This is my setting!'
31
+ # setting.name = :my_setting
32
+ # setting.group = :my_group
33
+ # setting.type = 'select'
34
+ # setting.values = ['yorick', 'zen']
35
+ # setting.default = 'yorick'
36
+ # end
37
+ #
38
+ # Note that the values array (or hash) is used to determine the possible
39
+ # values for a field. These values will only be used for elements that only
40
+ # allow a user to choose a single value (e.g. a checkbox). For the type
41
+ # getter/setter you can use any of the following values:
42
+ #
43
+ # * textbox
44
+ # * textarea
45
+ # * radio
46
+ # * checkbox
47
+ # * date
48
+ # * select
49
+ # * select_multiple
50
+ #
51
+ # ## Migrating Settings
52
+ #
53
+ # Once a setting has been added you still have to migrate it. Zen takes care
54
+ # of this so usually you don't need to manually migrate your settings. If
55
+ # you do want to migrate them however you can simple execute the following
56
+ # code:
57
+ #
58
+ # Settings::Setting.migrate
59
+ #
60
+ # ## Removing Settings
61
+ #
62
+ # If you ever need to remove a setting both from the database and the system
63
+ # you can do so as following:
64
+ #
65
+ # Settings::Setting.remove([:name, :name1])
66
+ #
67
+ # You don't have to specify an array of names, you can also specify the name
68
+ # of a single setting to delete.
69
+ #
70
+ # @since 0.2.5
71
+ #
72
+ class Setting
73
+ include ::Zen::Validation
74
+
75
+ # Array containing all possible setting types.
76
+ Types = [
77
+ 'textbox',
78
+ 'textarea',
79
+ 'radio',
80
+ 'checkbox',
81
+ 'date',
82
+ 'select',
83
+ 'select_multiple'
84
+ ]
85
+
86
+ # Hash containing all registered settings.
87
+ REGISTERED = {}
88
+
89
+ # The name of the setting
90
+ attr_reader :name
91
+
92
+ # The title of the setting, displayed in the GUI
93
+ attr_writer :title
94
+
95
+ # A small description about the setting
96
+ attr_writer :description
97
+
98
+ # The name of the settings group this setting belongs to
99
+ attr_reader :group
100
+
101
+ # The type of setting (e.g. textbox)
102
+ attr_accessor :type
103
+
104
+ # The possible values for the setting
105
+ attr_writer :values
106
+
107
+ # The default value of the setting
108
+ attr_accessor :default
109
+
110
+ class << self
111
+ ##
112
+ # Registers a new setting using the specified block.
113
+ #
114
+ # @example
115
+ # Settings::Setting.add do |setting|
116
+ # setting.name = 'example'
117
+ # setting.title = 'Example setting'
118
+ # setting.group = 'example'
119
+ # setting.type = 'select'
120
+ # setting.values = ['yorick', 'chuck']
121
+ # end
122
+ #
123
+ # @since 0.2.5
124
+ #
125
+ def add
126
+ setting = self.new
127
+
128
+ yield setting
129
+
130
+ setting.validate
131
+
132
+ REGISTERED[setting.name] = setting
133
+ end
134
+
135
+ ##
136
+ # Inserts all settings into the database. This method will ignore the
137
+ # settings that have already been inserted into the database.
138
+ #
139
+ # @since 0.2.5
140
+ #
141
+ def migrate
142
+ settings = ::Settings::Model::Setting.all.map { |s| s.name }
143
+
144
+ REGISTERED.each do |name, setting|
145
+ name = name.to_s
146
+
147
+ if !settings.include?(name)
148
+ Zen.database[:settings].insert(:name => name)
149
+ end
150
+ end
151
+ end
152
+
153
+ ##
154
+ # Removes the settings who's names match those specified in the array. The
155
+ # values of these settings will also be removed from the database.
156
+ #
157
+ # @since 0.2.5
158
+ # @param [Array] namese An array with setting names to remove.
159
+ #
160
+ def remove(names)
161
+ if names.class != Array
162
+ names = [names]
163
+ end
164
+
165
+ names.each_with_index do |v, k|
166
+ names[k] = v.to_s
167
+ REGISTERED.delete(v.to_sym)
168
+ end
169
+
170
+ ::Settings::Model::Setting.filter(:name => names).destroy
171
+ end
172
+ end # class << self
173
+
174
+ ##
175
+ # Validates all attributes of this class.
176
+ #
177
+ # @since 0.2.5
178
+ #
179
+ def validate
180
+ validates_presence([:name, :title, :group, :type])
181
+
182
+ # Validate the setting type
183
+ if !Types.include?(type)
184
+ raise(::Zen::ValidationError, "The setting type \"#{type}\" is invalid.")
185
+ end
186
+
187
+ # Check if the setting hasn't been registered yet
188
+ if REGISTERED.key?(name)
189
+ raise(
190
+ ::Zen::ValidationError,
191
+ "The setting #{name} has already been registered"
192
+ )
193
+ end
194
+
195
+ # Validate the group
196
+ if !Settings::SettingsGroup::REGISTERED.key?(group)
197
+ raise(
198
+ ::Zen::ValidationError,
199
+ "The settings group \"#{group}\" doesn't exist."
200
+ )
201
+ end
202
+ end
203
+
204
+ ##
205
+ # Sets the name of the setting and converts it to a symbol.
206
+ #
207
+ # @since 0.3
208
+ # @param [#to_sym] name The name of the setting.
209
+ #
210
+ def name=(name)
211
+ @name = name.to_sym
212
+ end
213
+
214
+ ##
215
+ # Sets the name of the group this setting belongs to.
216
+ #
217
+ # @since 0.3
218
+ # @param [#to_sym] group The name of the settings group.
219
+ #
220
+ def group=(group)
221
+ @group = group.to_sym
222
+ end
223
+
224
+ ##
225
+ # Returns the title of the setting and tries to translate it.
226
+ #
227
+ # @since 0.3
228
+ # @return [String]
229
+ #
230
+ def title
231
+ begin
232
+ return lang(@title)
233
+ rescue
234
+ return @title
235
+ end
236
+ end
237
+
238
+ ##
239
+ # Returns the description of the setting and translates it.
240
+ #
241
+ # @since 13-11-2011
242
+ # @return [String]
243
+ #
244
+ def description
245
+ begin
246
+ return lang(@description)
247
+ rescue
248
+ return @description
249
+ end
250
+ end
251
+
252
+ ##
253
+ # Updates the value of a setting both in the cache and the SQL database.
254
+ #
255
+ # @since 0.2.6.1
256
+ # @param [String] value The value to set the setting to.
257
+ #
258
+ def value=(value)
259
+ value = serialize(value)
260
+
261
+ # First we'll update the SQL database
262
+ ::Settings::Model::Setting[:name => name.to_s].update(:value => value)
263
+
264
+ # Sync the cache
265
+ ::Ramaze::Cache.settings.store(name, value)
266
+ end
267
+
268
+ ##
269
+ # Retrieves the setting. If it exists in the cache the cache's value is
270
+ # used, otherwise it will be retrieved from the SQL database and cached.
271
+ #
272
+ # @since 0.2.6.1
273
+ #
274
+ def value
275
+ val = ::Ramaze::Cache.settings.fetch(name)
276
+
277
+ # Get the setting from the database
278
+ if val.nil?
279
+ setting = ::Settings::Model::Setting[:name => name.to_s]
280
+
281
+ # If the value is also nil we'll use the default value
282
+ if setting.value.nil? or setting.value.empty?
283
+ val = default
284
+ else
285
+ val = setting.value
286
+ end
287
+
288
+ ::Ramaze::Cache.settings.store(name, val)
289
+ end
290
+
291
+ return unserialize(val)
292
+ end
293
+
294
+ ##
295
+ # Retrieves the possible values for the setting. If the value is a Proc or
296
+ # Lambda (or anything else that responds to call()) it will be called and
297
+ # it's return value is used.
298
+ #
299
+ # @since 0.2.8
300
+ # @return [Mixed]
301
+ #
302
+ def values
303
+ if @values.respond_to?(:call)
304
+ return @values.call
305
+ else
306
+ return @values
307
+ end
308
+ end
309
+
310
+ ##
311
+ # Returns the parameters for the BlueForm helper.
312
+ #
313
+ # @since 0.3
314
+ # @return [Array]
315
+ #
316
+ def form_parameters
317
+ return BlueFormParameters.send(type, self)
318
+ end
319
+
320
+ ##
321
+ # Small helper method that makes it a bit easier to check if a certain
322
+ # setting is set to true or false. Because settings are stored as strings
323
+ # with values of "1" or "0" you'd normally have to do the following:
324
+ #
325
+ # get_setting(:allow_registration).value == '1'
326
+ #
327
+ # This method allows you to do the following instead:
328
+ #
329
+ # get_setting(:allow_registration).true?
330
+ #
331
+ # @since 12-11-2011
332
+ # @return [TrueClass|FalseClass]
333
+ #
334
+ def true?
335
+ val = value
336
+
337
+ return val.is_a?(String) && val == '1'
338
+ end
339
+
340
+ private
341
+
342
+ ##
343
+ # Serializes a value using Marshal and packs it so that it can be stored in
344
+ # the database.
345
+ #
346
+ # @since 13-11-2011
347
+ # @param [Mixed] value The value to serialize.
348
+ # @return [String]
349
+ #
350
+ def serialize(value)
351
+ return [Marshal.dump(value)].pack('m')
352
+ end
353
+
354
+ ##
355
+ # Unserializes a value that was serialized using
356
+ # {Settings::Setting#serialize}.
357
+ #
358
+ # @since 13-11-2011
359
+ # @param [String] value The value to unserialize.
360
+ # @return [Mixed]
361
+ #
362
+ def unserialize(value)
363
+ begin
364
+ return Marshal.load(value.unpack('m')[0])
365
+ rescue
366
+ begin
367
+ return Marshal.load(value)
368
+ rescue
369
+ Ramaze::Log.info(
370
+ 'Failed to unpack the setting using Marshal, using the ' \
371
+ 'raw value instead'
372
+ )
373
+
374
+ return value
375
+ end
376
+ end
377
+ end
378
+ end # Setting
379
+ end # Settings