zen 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.gitignore +15 -0
  2. data/.mailmap +2 -0
  3. data/.rvmrc +2 -0
  4. data/.travis.yml +8 -3
  5. data/AUTHORS +1 -2
  6. data/CHANGELOG.md +48 -17
  7. data/README.md +44 -39
  8. data/Rakefile +4 -0
  9. data/bin/zen +5 -30
  10. data/lib/zen.rb +13 -19
  11. data/lib/zen/asset.rb +99 -64
  12. data/lib/zen/bin/create.rb +94 -0
  13. data/lib/zen/bin/runner.rb +118 -0
  14. data/lib/zen/controller/admin_controller.rb +52 -36
  15. data/lib/zen/controller/base_controller.rb +5 -5
  16. data/lib/zen/controller/frontend_controller.rb +7 -7
  17. data/lib/zen/controller/main_controller.rb +12 -10
  18. data/lib/zen/controller/preview.rb +15 -11
  19. data/lib/zen/helper/acl.rb +73 -53
  20. data/lib/zen/helper/blue_form_vendor.rb +689 -0
  21. data/lib/zen/helper/breadcrumb.rb +23 -19
  22. data/lib/zen/helper/message.rb +3 -3
  23. data/lib/zen/helper/theme.rb +18 -13
  24. data/lib/zen/language.rb +62 -58
  25. data/lib/zen/language/en/zen_general.yml +2 -4
  26. data/lib/zen/language/nl/zen_general.yml +2 -4
  27. data/lib/zen/layout/admin.xhtml +3 -12
  28. data/lib/zen/layout/login.xhtml +1 -6
  29. data/lib/zen/model/methods.rb +6 -6
  30. data/lib/zen/model/settings.rb +5 -4
  31. data/lib/zen/package.rb +47 -38
  32. data/lib/zen/package/all.rb +3 -5
  33. data/lib/zen/package/base.rb +7 -7
  34. data/lib/zen/package/categories/lib/categories.rb +8 -3
  35. data/lib/zen/package/categories/lib/categories/controller/categories.rb +81 -55
  36. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -44
  37. data/lib/zen/package/categories/lib/categories/helper/category.rb +88 -0
  38. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +5 -4
  39. data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +5 -4
  40. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +5 -4
  41. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +5 -4
  42. data/lib/zen/package/categories/lib/categories/model/category.rb +15 -13
  43. data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
  44. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +36 -25
  45. data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +49 -56
  46. data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +48 -35
  47. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/form.xhtml +36 -29
  48. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +42 -37
  49. data/lib/zen/package/comments/lib/comments.rb +4 -1
  50. data/lib/zen/package/comments/lib/comments/controller/comments.rb +39 -32
  51. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +45 -26
  52. data/lib/zen/package/comments/lib/comments/helper/comment.rb +35 -0
  53. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +9 -7
  54. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +10 -8
  55. data/lib/zen/package/comments/lib/comments/model/comment.rb +31 -17
  56. data/lib/zen/package/comments/lib/comments/model/comment_status.rb +15 -0
  57. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +27 -18
  58. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +25 -20
  59. data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +61 -54
  60. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +38 -23
  61. data/lib/zen/package/comments/migrations/1308774099_comment_status.rb +60 -0
  62. data/lib/zen/package/custom_fields/lib/custom_fields.rb +33 -7
  63. data/lib/zen/package/custom_fields/lib/custom_fields/blue_form_parameters.rb +209 -0
  64. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +50 -47
  65. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_types.rb +215 -0
  66. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +111 -73
  67. data/lib/zen/package/custom_fields/lib/custom_fields/helper/custom_field.rb +79 -0
  68. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_groups.yml +20 -19
  69. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_field_types.yml +40 -0
  70. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +34 -32
  71. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +5 -4
  72. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_types.yml +40 -0
  73. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +18 -16
  74. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +31 -11
  75. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_method.rb +15 -0
  76. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb +50 -0
  77. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +28 -7
  78. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/form.xhtml +33 -28
  79. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +48 -46
  80. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/form.xhtml +61 -0
  81. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-types/index.xhtml +93 -0
  82. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +105 -99
  83. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +43 -39
  84. data/lib/zen/package/custom_fields/migrations/1295255665_create_schema.rb +47 -16
  85. data/lib/zen/package/custom_fields/migrations/1310659580_custom_field_types.rb +148 -0
  86. data/lib/zen/package/custom_fields/migrations/1311694920_rename_css_class.rb +11 -0
  87. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +40 -35
  88. data/lib/zen/package/menus/lib/menus/controller/menus.rb +47 -43
  89. data/lib/zen/package/menus/lib/menus/helper/{menu_item.rb → menu.rb} +42 -15
  90. data/lib/zen/package/menus/lib/menus/language/en/menu_items.yml +5 -5
  91. data/lib/zen/package/menus/lib/menus/language/en/menus.yml +9 -8
  92. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +8 -8
  93. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +11 -10
  94. data/lib/zen/package/menus/lib/menus/model/menu.rb +5 -5
  95. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +6 -5
  96. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +41 -43
  97. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +59 -63
  98. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +35 -30
  99. data/lib/zen/package/menus/lib/menus/view/admin/menus/form.xhtml +46 -37
  100. data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +37 -37
  101. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +5 -5
  102. data/lib/zen/package/menus/migrations/1308671733_rename_order_column.rb +11 -0
  103. data/lib/zen/package/menus/migrations/1311695030_rename_css_class.rb +17 -0
  104. data/lib/zen/package/sections/lib/sections.rb +18 -11
  105. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +115 -109
  106. data/lib/zen/package/sections/lib/sections/controller/sections.rb +72 -50
  107. data/lib/zen/package/sections/lib/sections/helper/section.rb +53 -0
  108. data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +5 -4
  109. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +5 -4
  110. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +5 -4
  111. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +5 -4
  112. data/lib/zen/package/sections/lib/sections/model/section.rb +17 -9
  113. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +192 -13
  114. data/lib/zen/package/sections/lib/sections/model/section_entry_status.rb +13 -0
  115. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +60 -39
  116. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +14 -11
  117. data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +100 -97
  118. data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +41 -39
  119. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +95 -215
  120. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +48 -40
  121. data/lib/zen/package/sections/migrations/1308672298_use_id_for_default_section.rb +40 -0
  122. data/lib/zen/package/sections/migrations/1308813320_section_entry_statuses.rb +58 -0
  123. data/lib/zen/package/settings/lib/settings/controller/settings.rb +5 -8
  124. data/lib/zen/package/settings/lib/settings/model/setting.rb +2 -37
  125. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +18 -1
  126. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +13 -7
  127. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +2 -1
  128. data/lib/zen/package/users/lib/users.rb +3 -1
  129. data/lib/zen/package/users/lib/users/controller/access_rules.rb +77 -60
  130. data/lib/zen/package/users/lib/users/controller/user_groups.rb +41 -36
  131. data/lib/zen/package/users/lib/users/controller/users.rb +48 -42
  132. data/lib/zen/package/users/lib/users/helper/users.rb +72 -0
  133. data/lib/zen/package/users/lib/users/language/en/access_rules.yml +6 -5
  134. data/lib/zen/package/users/lib/users/language/en/user_groups.yml +5 -4
  135. data/lib/zen/package/users/lib/users/language/en/users.yml +1 -0
  136. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +5 -4
  137. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +5 -4
  138. data/lib/zen/package/users/lib/users/language/nl/users.yml +1 -0
  139. data/lib/zen/package/users/lib/users/model/access_rule.rb +5 -1
  140. data/lib/zen/package/users/lib/users/model/user.rb +17 -10
  141. data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +10 -37
  142. data/lib/zen/package/users/lib/users/public/admin/js/users/lib/access_rules.js +49 -0
  143. data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +105 -96
  144. data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +48 -41
  145. data/lib/zen/package/users/lib/users/view/admin/user-groups/form.xhtml +42 -32
  146. data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +43 -38
  147. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +76 -67
  148. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +43 -41
  149. data/lib/zen/package/users/lib/users/view/admin/users/login.xhtml +12 -9
  150. data/lib/zen/package/users/migrations/1295281013_create_schema.rb +2 -2
  151. data/lib/zen/plugin.rb +56 -50
  152. data/lib/zen/plugin/markup/lib/markup/markup.rb +33 -21
  153. data/lib/zen/public/admin/css/zen/buttons.css +11 -7
  154. data/lib/zen/public/admin/css/zen/datepicker.css +6 -6
  155. data/lib/zen/public/admin/css/zen/forms.css +2 -1
  156. data/lib/zen/public/admin/css/zen/general.css +15 -10
  157. data/lib/zen/public/admin/css/zen/layout.css +51 -20
  158. data/lib/zen/public/admin/css/zen/tables.css +39 -11
  159. data/lib/zen/public/admin/css/zen/tabs.css +6 -4
  160. data/lib/zen/public/admin/css/zen/window.css +11 -11
  161. data/lib/zen/public/{favicon.ico → admin/favicon.ico} +0 -0
  162. data/lib/zen/public/admin/images/zen/icons/asc.png +0 -0
  163. data/lib/zen/public/admin/images/zen/icons/desc.png +0 -0
  164. data/lib/zen/public/admin/js/vendor/datepicker.js +0 -11
  165. data/lib/zen/public/admin/js/{mootools → vendor/mootools}/core.js +0 -1
  166. data/lib/zen/public/admin/js/{mootools → vendor/mootools}/more.js +100 -29
  167. data/lib/zen/public/admin/js/zen/index.js +48 -0
  168. data/lib/zen/public/admin/js/zen/lib/asset.js +111 -0
  169. data/lib/zen/public/admin/js/zen/{editor.js → lib/editor.js} +107 -127
  170. data/lib/zen/public/admin/js/zen/{editor → lib/editor}/markdown.js +7 -9
  171. data/lib/zen/public/admin/js/zen/{editor → lib/editor}/textile.js +7 -9
  172. data/lib/zen/public/admin/js/zen/lib/html_table.js +143 -0
  173. data/lib/zen/public/admin/js/zen/{tabs.js → lib/tabs.js} +40 -37
  174. data/lib/zen/public/admin/js/zen/{window.js → lib/window.js} +24 -20
  175. data/lib/zen/spec/bacon/color_output.rb +39 -0
  176. data/lib/zen/spec/helper.rb +152 -0
  177. data/lib/zen/spec/simplecov.rb +22 -0
  178. data/lib/zen/task/build.rake +20 -43
  179. data/lib/zen/task/clean.rake +2 -6
  180. data/lib/zen/task/db.rake +8 -12
  181. data/lib/zen/task/package.rake +4 -10
  182. data/lib/zen/task/plugin.rake +3 -9
  183. data/lib/zen/task/proto.rake +0 -62
  184. data/lib/zen/task/test.rake +6 -3
  185. data/lib/zen/task/theme.rake +4 -11
  186. data/lib/zen/theme.rb +22 -24
  187. data/lib/zen/validation.rb +34 -27
  188. data/lib/zen/version.rb +2 -8
  189. data/lib/zen/view/head.xhtml +7 -0
  190. data/lib/zen/view/main.xhtml +7 -22
  191. data/{proto/package/migrations → pkg}/.gitkeep +0 -0
  192. data/proto/app/app.rb +1 -0
  193. data/proto/app/config/config.rb +5 -4
  194. data/proto/app/config/database.rb +19 -41
  195. data/proto/app/config/middlewares.rb +32 -29
  196. data/proto/{package/lib/package/view/admin/package/index.xhtml → app/log/database/dev/.gitkeep} +0 -0
  197. data/proto/app/log/database/live/.gitkeep +0 -0
  198. data/spec/Rakefile +26 -0
  199. data/spec/fixtures/zen/asset.rb +18 -0
  200. data/spec/fixtures/zen/helper/acl.rb +39 -0
  201. data/spec/fixtures/zen/helper/message.rb +19 -0
  202. data/spec/fixtures/zen/language/en/spec.yml +10 -0
  203. data/spec/fixtures/zen/language/nl/spec.yml +7 -0
  204. data/spec/fixtures/zen/package.rb +17 -0
  205. data/spec/fixtures/zen/package/comments/controller/comments_form.rb +27 -0
  206. data/spec/fixtures/zen/package/settings/plugin/settings.rb +20 -0
  207. data/spec/fixtures/zen/plugin.rb +7 -0
  208. data/spec/fixtures/zen/theme/404.xhtml +1 -0
  209. data/spec/fixtures/zen/theme/default-section/index.xhtml +1 -0
  210. data/spec/fixtures/zen/theme/helper/404.xhtml +1 -0
  211. data/spec/fixtures/zen/theme/helper/partial.xhtml +1 -0
  212. data/spec/fixtures/zen/theme/helper/wrong_partial.xhtml +1 -0
  213. data/spec/fixtures/zen/theme/partials/partial.xhtml +1 -0
  214. data/spec/fixtures/zen/theme/theme.rb +11 -0
  215. data/spec/fixtures/zen/validation.rb +22 -0
  216. data/spec/helper.rb +41 -0
  217. data/spec/zen/all.rb +5 -0
  218. data/spec/zen/asset.rb +97 -0
  219. data/spec/zen/bin/create.rb +89 -0
  220. data/spec/zen/bin/runner.rb +47 -0
  221. data/spec/zen/controller/admin_controller.rb +26 -0
  222. data/spec/zen/controller/main_controller.rb +81 -0
  223. data/spec/zen/controller/preview.rb +33 -0
  224. data/spec/zen/helper/acl.rb +149 -0
  225. data/spec/zen/helper/breadcrumb.rb +38 -0
  226. data/spec/zen/helper/message.rb +31 -0
  227. data/spec/zen/helper/theme.rb +58 -0
  228. data/spec/zen/language.rb +55 -0
  229. data/spec/zen/package.rb +23 -0
  230. data/spec/zen/package/categories/controller/categories.rb +123 -0
  231. data/spec/zen/package/categories/controller/category_groups.rb +108 -0
  232. data/spec/zen/package/categories/helper/category.rb +75 -0
  233. data/spec/zen/package/categories/plugin/categories.rb +92 -0
  234. data/spec/zen/package/comments/controller/comments.rb +134 -0
  235. data/spec/zen/package/comments/controller/comments_form.rb +343 -0
  236. data/spec/zen/package/comments/helper/comment.rb +47 -0
  237. data/spec/zen/package/comments/plugin/anti_spam.rb +59 -0
  238. data/spec/zen/package/comments/plugin/comments.rb +107 -0
  239. data/spec/zen/package/custom_fields/blue_form_parameters.rb +183 -0
  240. data/spec/zen/package/custom_fields/controller/custom_field_groups.rb +120 -0
  241. data/spec/zen/package/custom_fields/controller/custom_field_types.rb +169 -0
  242. data/spec/zen/package/custom_fields/controller/custom_fields.rb +158 -0
  243. data/spec/zen/package/custom_fields/helper/custom_field.rb +86 -0
  244. data/spec/zen/package/menus/controller/menu_items.rb +110 -0
  245. data/spec/zen/package/menus/controller/menus.rb +110 -0
  246. data/spec/zen/package/menus/helper/menu.rb +75 -0
  247. data/spec/zen/package/menus/plugin/menus.rb +120 -0
  248. data/spec/zen/package/sections/controller/section_entries.rb +201 -0
  249. data/spec/zen/package/sections/controller/sections.rb +116 -0
  250. data/spec/zen/package/sections/helper/section.rb +74 -0
  251. data/spec/zen/package/sections/plugin/section_entries.rb +161 -0
  252. data/spec/zen/package/sections/plugin/sections.rb +75 -0
  253. data/spec/zen/package/settings/controller/settings.rb +36 -0
  254. data/spec/zen/package/settings/plugin/settings.rb +33 -0
  255. data/spec/zen/package/users/controller/access_rules.rb +90 -0
  256. data/spec/zen/package/users/controller/user_groups.rb +101 -0
  257. data/spec/zen/package/users/controller/users.rb +130 -0
  258. data/spec/zen/package/users/helper/users.rb +97 -0
  259. data/spec/zen/plugin.rb +64 -0
  260. data/spec/zen/plugin/helper.rb +11 -0
  261. data/spec/zen/plugin/markup.rb +44 -0
  262. data/spec/zen/theme.rb +41 -0
  263. data/spec/zen/validation.rb +63 -0
  264. data/zen.gemspec +36 -0
  265. metadata +159 -113
  266. data/MANIFEST +0 -266
  267. data/lib/zen/bin/app.rb +0 -40
  268. data/lib/zen/ext/string.rb +0 -185
  269. data/lib/zen/helper/common.rb +0 -106
  270. data/lib/zen/package/categories/lib/categories/view/admin/categories/edit.xhtml +0 -7
  271. data/lib/zen/package/categories/lib/categories/view/admin/categories/new.xhtml +0 -7
  272. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/edit.xhtml +0 -7
  273. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/new.xhtml +0 -7
  274. data/lib/zen/package/comments/lib/comments/view/admin/comments/edit.xhtml +0 -7
  275. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/edit.xhtml +0 -7
  276. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/new.xhtml +0 -7
  277. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/edit.xhtml +0 -7
  278. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/new.xhtml +0 -7
  279. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/edit.xhtml +0 -7
  280. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/new.xhtml +0 -7
  281. data/lib/zen/package/menus/lib/menus/view/admin/menus/edit.xhtml +0 -7
  282. data/lib/zen/package/menus/lib/menus/view/admin/menus/new.xhtml +0 -7
  283. data/lib/zen/package/sections/lib/sections/view/admin/edit.xhtml +0 -7
  284. data/lib/zen/package/sections/lib/sections/view/admin/new.xhtml +0 -7
  285. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/edit.xhtml +0 -7
  286. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/new.xhtml +0 -7
  287. data/lib/zen/package/users/lib/users/view/admin/access-rules/edit.xhtml +0 -7
  288. data/lib/zen/package/users/lib/users/view/admin/access-rules/new.xhtml +0 -7
  289. data/lib/zen/package/users/lib/users/view/admin/user-groups/edit.xhtml +0 -7
  290. data/lib/zen/package/users/lib/users/view/admin/user-groups/new.xhtml +0 -7
  291. data/lib/zen/package/users/lib/users/view/admin/users/edit.xhtml +0 -7
  292. data/lib/zen/package/users/lib/users/view/admin/users/new.xhtml +0 -7
  293. data/lib/zen/plugin/controller.rb +0 -59
  294. data/lib/zen/public/admin/css/zen/notifications.css +0 -84
  295. data/lib/zen/public/admin/images/zen/icons/large/error.png +0 -0
  296. data/lib/zen/public/admin/images/zen/icons/large/notice.png +0 -0
  297. data/lib/zen/public/admin/images/zen/icons/large/success.png +0 -0
  298. data/lib/zen/public/admin/js/zen/core.js +0 -73
  299. data/lib/zen/public/admin/js/zen/init.js +0 -80
  300. data/proto/package/lib/package.rb +0 -21
  301. data/proto/package/lib/package/controller/controllers.rb +0 -50
  302. data/proto/package/lib/package/language/en/languages.yml +0 -4
  303. data/proto/package/lib/package/model/model.rb +0 -12
@@ -3,19 +3,21 @@ module Ramaze
3
3
  #:nodoc:
4
4
  module Helper
5
5
  ##
6
- # This helper provides an easy way of working with the ACL system that ships with Zen.
7
- # Using this helper you can restrict access to methods, view elements and pretty much
8
- # everything else based on the user's permissions.
6
+ # This helper provides an easy way of working with the ACL system that ships
7
+ # with Zen. Using this helper you can restrict access to methods, view
8
+ # elements and pretty much everything else based on the user's permissions.
9
9
  #
10
- # In order to restrict certain actions to only those with the correct permissions you
11
- # can use the method "user_authorized?". This method takes a list of required
12
- # permissions and when the user has the correct permissions it will return true:
10
+ # In order to restrict certain actions to only those with the correct
11
+ # permissions you can use the method "user_authorized?". This method takes
12
+ # a list of required permissions and when the user has the correct
13
+ # permissions it will return true:
13
14
  #
14
15
  # user_authorized?([:read]) # => true
15
16
  #
16
- # The method has 3 parameters: a list of permissions, a boolean that indicates whether
17
- # all of them or just a single one is required and a third argument that can be used
18
- # to manually specify the controller to validate against rather than the current node.
17
+ # The method has 3 parameters: a list of permissions, a boolean that
18
+ # indicates whether all of them or just a single one is required and a third
19
+ # argument that can be used to manually specify the controller to validate
20
+ # against rather than the current node.
19
21
  #
20
22
  # user_authorized?([:read], true 'FoobarController')
21
23
  #
@@ -24,34 +26,42 @@ module Ramaze
24
26
  # @see Users::Controller::AccessRules()
25
27
  #
26
28
  module ACL
27
-
28
29
  ##
29
- # Builds a hash containing the permissions for all controllers. First all group
30
- # based rules will be retrieved. If the user is in a super group he'll gain full
31
- # access. However, if there's a user specific rule it will overwrite the rules set
32
- # for the group. This means that if a group allows something but a user rule doesn't
33
- # the user won't be able to gain access to the resource.
30
+ # Builds a hash containing the permissions for all controllers. First all
31
+ # group based rules will be retrieved. If the user is in a super group
32
+ # he'll gain full access. However, if there's a user specific rule it will
33
+ # overwrite the rules set for the group. This means that if a group allows
34
+ # something but a user rule doesn't the user won't be able to gain access
35
+ # to the resource.
34
36
  #
35
37
  # @author Yorick Peterse
36
38
  # @since 0.1
37
39
  # @return [Hash]
38
40
  #
39
41
  def extension_permissions
40
- if session[:access_rules]
41
- return session[:access_rules]
42
- end
42
+ return session[:access_rules] if session[:access_rules]
43
43
 
44
44
  user = session[:user]
45
45
  user_groups = user.user_groups
46
- @used_rules = {}
47
- available_rules = [:create_access, :read_access, :update_access, :delete_access]
46
+ @__used_rules = {}
47
+ available_rules = [
48
+ :create_access,
49
+ :read_access,
50
+ :update_access,
51
+ :delete_access
52
+ ]
48
53
 
49
54
  # First all group rules should be built
50
55
  user_groups.each do |group|
51
56
  # If it's a super group we'll add all rules
52
57
  if group.super_group === true
53
58
  ::Zen::Package::Controllers.each do |controller|
54
- @used_rules[controller.to_s] = [:create, :read, :update, :delete]
59
+ @__used_rules[controller.to_s] = [
60
+ :create,
61
+ :read,
62
+ :update,
63
+ :delete
64
+ ]
55
65
  end
56
66
  end
57
67
 
@@ -65,38 +75,34 @@ module Ramaze
65
75
  process_permissions(rule, available_rules)
66
76
  end
67
77
 
68
- # Store the rules in the user's session so that they don't have to be re-processed
69
- # every time this method is called.
70
- session[:access_rules] = @used_rules
78
+ # Store the rules in the user's session so that they don't have to be
79
+ # re-processed every time this method is called.
80
+ session[:access_rules] = @__used_rules
71
81
 
72
- return @used_rules
82
+ return @__used_rules
73
83
  end
74
-
84
+
75
85
  ##
76
- # Checks if the user has the specified permissions for the current extension that
77
- # was called. Returns true if this is the case and false otherwise.
86
+ # Checks if the user has the specified permissions for the current
87
+ # extension that was called. Returns true if this is the case and false
88
+ # otherwise.
78
89
  #
79
90
  # @author Yorick Peterse
80
91
  # @param [Array] required Array of permissions that are required.
81
- # @param [Boolean] require_all Boolean that specifies that the user should have
82
- # ALL specified permissios. Setting this to false causes this method to return true
83
- # if any of the permissions are set for the current user.
84
- # @param [String] controller When set this will overwrite the controller name of
85
- # action.node. This is useful when you want to check the permissions of a different
86
- # controller than the current one.
87
- # @return [TrueClass]
92
+ # @param [Boolean] require_all Boolean that specifies that the user
93
+ # should have ALL specified permissios. Setting this to false causes this
94
+ # method to return true if any of the permissions are set for the current
95
+ # user.
96
+ # @param [String] controller When set this will overwrite the controller
97
+ # name of action.node. This is useful when you want to check the
98
+ # permissions of a different controller than the current one.
99
+ # @return [TrueClass/FalseClass]
88
100
  #
89
101
  def user_authorized?(required, require_all = true, controller = nil)
90
- # Get the ACL list
91
- rules = extension_permissions
102
+ rules = extension_permissions
103
+ controller = action.node.to_s if !controller
92
104
 
93
- if !controller
94
- controller = action.node.to_s
95
- end
96
-
97
- if !rules.key?(controller)
98
- return false
99
- end
105
+ return false if !rules.key?(controller)
100
106
 
101
107
  required.each do |req|
102
108
  if require_all === false and rules[controller].include?(req)
@@ -112,12 +118,12 @@ module Ramaze
112
118
  private
113
119
 
114
120
  ##
115
- # Extracts and stores all the permissions from a given rule.
121
+ # Extracts and stores all the permissions from a given rule.
116
122
  #
117
123
  # @author Yorick Peterse
118
124
  # @since 0.2.5
119
- # @param [Users::Model::AccessRule] rule Database record containing the details of
120
- # a single rule.
125
+ # @param [Users::Model::AccessRule] rule Database record containing the
126
+ # details of a single rule.
121
127
  # @param [Array] available_rules All the available rules that can be used.
122
128
  #
123
129
  def process_permissions(rule, available_rules)
@@ -145,18 +151,32 @@ module Ramaze
145
151
 
146
152
  # Add the rules for all the controllers
147
153
  controllers.each do |c|
148
- @used_rules[c] ||= []
154
+ @__used_rules[c] ||= []
149
155
 
150
- if method === :push and @used_rules[c].include?(available_rule)
156
+ if method === :push and @__used_rules[c].include?(available_rule)
151
157
  next
152
158
  end
153
159
 
154
160
  # Add or remove the permission
155
- @used_rules[c].send(method, available_rule)
161
+ @__used_rules[c].send(method, available_rule)
156
162
  end
157
163
  end
158
164
  end
159
165
 
160
- end
161
- end
162
- end
166
+ ##
167
+ # Method that checks if the user has the given permissions. If this isn't
168
+ # the case an error message is displayed and the user won't be able to
169
+ # access the page.
170
+ #
171
+ # @author Yorick Peterse
172
+ # @since 0.2.8
173
+ # @param [Array] *args An array of permissions that are required.
174
+ #
175
+ def require_permissions(*args)
176
+ if !user_authorized?(args)
177
+ respond(lang('zen_general.errors.not_authorized'), 403)
178
+ end
179
+ end
180
+ end # ACL
181
+ end # Helper
182
+ end # Ramaze
@@ -0,0 +1,689 @@
1
+ require 'ramaze'
2
+ require 'ramaze/gestalt'
3
+
4
+ module Ramaze
5
+ module Helper
6
+ ##
7
+ # == Introduction
8
+ #
9
+ # The BlueForm helper tries to be an even better way to build forms
10
+ # programmatically. By using a simple block you can quickly create all the
11
+ # required elements for your form.
12
+ #
13
+ # Since November 2010 the BlueForm helper works different. You can now
14
+ # specify an object as the first parameter of the form_for() method. This
15
+ # object will be used to retrieve the values of each field. This means that
16
+ # you can directly pass a database result object to the form and no longer
17
+ # have to manually specify values. However, you can still specify your own
18
+ # values if you want.
19
+ #
20
+ # Old behaviour:
21
+ #
22
+ # form_for(:method => :post) do |f|
23
+ # f.input_text 'Username', :username, 'Chuck Norris'
24
+ # end
25
+ #
26
+ # New behaviour:
27
+ #
28
+ # # @data is an object that contains an instance variable named "username".
29
+ # # This variable contains the value "Chuck Norris".
30
+ # form_for(@data, :method => :post) do |f|
31
+ # f.input_text 'Username', :username
32
+ # end
33
+ #
34
+ # == Form Data
35
+ #
36
+ # As stated earlier it's possible to pass an object to the form_for()
37
+ # method. What kind of object this is, a database result object or an
38
+ # OpenStruct object doesn't matter as long as the attributes can be accessed
39
+ # outside of the object (this can be done using attr_readers). This makes it
40
+ # extremely easy to directly pass a result object from your favourite ORM.
41
+ # Example:
42
+ #
43
+ # @data = User[1]
44
+ #
45
+ # form_for(@data, :method => :post) do |f|
46
+ # f.input_text 'Username', :username
47
+ # end
48
+ #
49
+ # If you don't want to use an object you can simply set the first parameter
50
+ # to nil.
51
+ #
52
+ # == HTML Output
53
+ #
54
+ # The form helper uses Gestalt, Ramaze's custom HTML builder that works
55
+ # somewhat like Erector. The output is very minimalistic, elements such as
56
+ # legends and fieldsets have to be added manually. Each combination of a
57
+ # label and input element will be wrapped in <p> tags.
58
+ #
59
+ # When using the form helper as a block in your templates it's important to
60
+ # remember that the result is returned and not displayed in the browser
61
+ # directly. When using Etanni this would result in something like the
62
+ # following:
63
+ #
64
+ # #{
65
+ # form_for(@result, :method => :post) do |f| do
66
+ # f.input_text 'Text label', :textname, 'Chunky bacon!'
67
+ # end
68
+ # }
69
+ #
70
+ # @example
71
+ #
72
+ # form_for(@data, :method => :post) do |f|
73
+ # f.input_text 'Username', :username
74
+ # end
75
+ #
76
+ module BlueFormVendor
77
+ ##
78
+ # The form method generates the basic structure of the form. It should be
79
+ # called using a block and it's return value should be manually sent to
80
+ # the browser (since it does not echo the value).
81
+ #
82
+ # @param [Object] form_values Object containing the values for each form
83
+ # field.
84
+ # @param [Hash] options Hash containing any additional form attributes
85
+ # such as the method, action, enctype and so on.
86
+ # @param [Block] block Block containing the elements of the form such as
87
+ # password fields, textareas and so on.
88
+ #
89
+ def form_for(form_values, options = {}, &block)
90
+ form = Form.new(form_values, options)
91
+ form.build(form_errors, &block)
92
+ form
93
+ end
94
+
95
+ ##
96
+ # Manually add a new error to the form_errors key in the flash hash. The
97
+ # first parameter is the name of the form field and the second parameter
98
+ # is the custom message.
99
+ #
100
+ # @param [String] name The name of the form field to which the error
101
+ # belongs.
102
+ # @param [String] message The custom error message to show.
103
+ #
104
+ def form_error(name, message)
105
+ if respond_to?(:flash)
106
+ old = flash[:form_errors] || {}
107
+ flash[:form_errors] = old.merge(name.to_s => message.to_s)
108
+ else
109
+ form_errors[name.to_s] = message.to_s
110
+ end
111
+ end
112
+
113
+ ##
114
+ # Returns the hash containing all existing errors and allows other methods
115
+ # to set new errors by using this method as if it were a hash.
116
+ #
117
+ # @return [Array] All form errors.
118
+ #
119
+ def form_errors
120
+ if respond_to?(:flash)
121
+ flash[:form_errors] ||= {}
122
+ else
123
+ @form_errors ||= {}
124
+ end
125
+ end
126
+
127
+ ##
128
+ # Retrieve all the form errors for the specified model and add them to the
129
+ # flash hash.
130
+ #
131
+ # @param [Object] obj An object of a model that contains form errors.
132
+ #
133
+ def form_errors_from_model(obj)
134
+ if obj.respond_to?(:errors)
135
+ obj.errors.each do |key, value|
136
+ if value.respond_to?(:first)
137
+ value = value.first
138
+ end
139
+
140
+ form_error(key.to_s, value % key)
141
+ end
142
+ end
143
+ end
144
+
145
+ ##
146
+ # Main form class that contains all the required methods to generate form
147
+ # specific tags, such as textareas and select boxes. Do note that this
148
+ # class is not thread-safe so you should modify it only within one thread
149
+ # of execution.
150
+ #
151
+ class Form
152
+ attr_reader :g
153
+ attr_reader :form_values
154
+
155
+ ##
156
+ # Constructor method that generates an instance of the Form class.
157
+ #
158
+ # @param [Object] form_values Object containing the values for each form
159
+ # field.
160
+ # @param [Hash] options A hash containing any additional form attributes.
161
+ # @return [Object] An instance of the Form class.
162
+ #
163
+ def initialize(form_values, options)
164
+ @form_values = form_values
165
+ @form_args = options.dup
166
+ @g = Gestalt.new
167
+ end
168
+
169
+ ##
170
+ # Builds the form by generating the opening/closing tags and executing
171
+ # the methods in the block.
172
+ #
173
+ # @param [Hash] form_errors Hash containing all form errors (if any).
174
+ #
175
+ def build(form_errors = {})
176
+ # Convert all the keys in form_errors to strings and
177
+ # retrieve the correct values in case
178
+ @form_errors = {}
179
+
180
+ form_errors.each do |key, value|
181
+ if value.respond_to?(:first)
182
+ value = value.first
183
+ end
184
+
185
+ @form_errors[key.to_s] = value
186
+ end
187
+
188
+ @g.form(@form_args) do
189
+ if block_given?
190
+ yield self
191
+ end
192
+ end
193
+ end
194
+
195
+ ##
196
+ # Generate a <legend> tag.
197
+ #
198
+ # @param [String] text The text to display inside the legend tag.
199
+ # @example
200
+ #
201
+ # form_for(@data, :method => :post) do |f|
202
+ # f.legend 'Ramaze rocks!'
203
+ # end
204
+ #
205
+ def legend(text)
206
+ @g.legend(text)
207
+ end
208
+
209
+ ##
210
+ # Generate a fieldset tag.
211
+ #
212
+ # @param [Block] &block The form elements to display inside the fieldset.
213
+ # @example
214
+ #
215
+ # form_for(@data, :method => :post) do |f|
216
+ # f.fieldset do
217
+ # f.legend 'Hello, world!'
218
+ # end
219
+ # end
220
+ #
221
+ def fieldset(&block)
222
+ @g.fieldset(&block)
223
+ end
224
+
225
+ ##
226
+ # Generate an input tag with a type of "text" along with a label tag.
227
+ # This method also has the alias "text" so feel free to use that one
228
+ # instead of input_text.
229
+ #
230
+ # @param [String] label The text to display inside the label tag.
231
+ # @param [String Symbol] name The name of the text field.
232
+ # @param [Hash] args Any additional HTML attributes along with their
233
+ # values.
234
+ # @example
235
+ #
236
+ # form_for(@data, :method => :post) do |f|
237
+ # f.input_text 'Username', :username
238
+ # end
239
+ #
240
+ def input_text(label, name, args = {})
241
+ # The ID can come from 2 places, id_for and the args hash
242
+ id = args[:id] ? args[:id] : id_for(name)
243
+ args = args.merge(:type => :text, :name => name, :id => id)
244
+
245
+ if !args[:value] and @form_values.respond_to?(name)
246
+ args[:value] = @form_values.send(name)
247
+ end
248
+
249
+ @g.p do
250
+ label_for(id, label, name)
251
+ @g.input(args)
252
+ end
253
+ end
254
+ alias text input_text
255
+
256
+ ##
257
+ # Generate an input tag with a type of "password" along with a label.
258
+ # Password fields are pretty much the same as text fields except that
259
+ # the content of these fields is replaced with dots. This method has the
260
+ # following alias: "password".
261
+ #
262
+ # @param [String] label The text to display inside the label tag.
263
+ # @param [String Symbol] name The name of the password field.
264
+ # @param [Hash] args Any additional HTML attributes along with their
265
+ # values.
266
+ # @example
267
+ #
268
+ # form_for(@data, :method => :post) do |f|
269
+ # f.input_password 'My password', :password
270
+ # end
271
+ #
272
+ def input_password(label, name, args = {})
273
+ # The ID can come from 2 places, id_for and the args hash
274
+ id = args[:id] ? args[:id] : id_for(name)
275
+ args = args.merge(:type => :password, :name => name, :id => id)
276
+
277
+ if !args[:value] and @form_values.respond_to?(name)
278
+ args[:value] = @form_values.send(name)
279
+ end
280
+
281
+ @g.p do
282
+ label_for(id, label, name)
283
+ @g.input(args)
284
+ end
285
+ end
286
+ alias password input_password
287
+
288
+ ##
289
+ # Generate a submit tag (without a label). A submit tag is a button that
290
+ # once it's clicked will send the form data to the server.
291
+ #
292
+ # @param [String] value The text to display in the button.
293
+ # @param [Hash] args Any additional HTML attributes along with their
294
+ # values.
295
+ # @example
296
+ #
297
+ # form_for(@data, :method => :post) do |f|
298
+ # f.input_submit 'Save'
299
+ # end
300
+ #
301
+ def input_submit(value = nil, args = {})
302
+ args = args.merge(:type => :submit)
303
+ args[:value] = value unless value.nil?
304
+
305
+ @g.p do
306
+ @g.input(args)
307
+ end
308
+ end
309
+ alias submit input_submit
310
+
311
+ ##
312
+ # Generate an input tag with a type of "checkbox".
313
+ #
314
+ # If you want to have multiple checkboxes you can either use an array or
315
+ # a hash. In the case of an array the values will also be used as text
316
+ # for each checkbox. When using a hash the key will be displayed and
317
+ # the value will be the value of the checkbox. Example:
318
+ #
319
+ # @data = Class.new
320
+ # attr_reader :gender_arr
321
+ # attr_reader :gender_hash
322
+ #
323
+ # def initialize
324
+ # @gender_arr = ['male', 'female']
325
+ # @gender_hash = {"Male" => "male", "Female" => "female"}
326
+ # end
327
+ # end.new
328
+ #
329
+ # form_for(@data, :method => :post) do |f|
330
+ # f.input_checkbox "Gender", :gender_arr
331
+ # f.input_checkbox "Gender", :gender_hash
332
+ # end
333
+ #
334
+ # @example
335
+ # form_for(@data, :method => :post) do |f|
336
+ # f.input_checkbox 'Remember me', :remember_user
337
+ # end
338
+ #
339
+ # @param [String] label The text to display inside the label tag.
340
+ # @param [String Symbol] name The name of the checkbox.
341
+ # @param [String/Array] checked String or array that indicates which
342
+ # value(s) should be checked.
343
+ # @param [Hash] args Any additional HTML attributes along with their
344
+ # values.
345
+ # @option args [String/Symbol] :id The value to use for the ID attribute.
346
+ # @option args [Array] :values An array containing the possible values
347
+ # for the checkboxes.
348
+ # @option args [String/Symbol] :span_class The class to use for the
349
+ # <span> element that's wrapped around the checkbox.
350
+ # @option args [TrueClass/FalseClass] :show_value When set to false the
351
+ # value of each checkbox won't be displayed to the right of the
352
+ # checkbox. This option is set to true by default.
353
+ # @option args [TrueClass/FalseClass] :show_label When set to true
354
+ # (default) the label for the checkbox will be displayed. Setting this
355
+ # to false will hide it.
356
+ #
357
+ def input_checkbox(label, name, checked = nil, args = {})
358
+ id = args[:id] ? args[:id] : "#{id_for(name)}_0"
359
+
360
+ # Determine whether or not to show the value of the checkbox
361
+ if args.key?(:show_value)
362
+ show_value = args.delete(:show_value)
363
+ else
364
+ show_value = true
365
+ end
366
+
367
+ # Determine whether or not to show the label
368
+ if args.key?(:show_label)
369
+ show_label = args.delete(:show_label)
370
+ else
371
+ show_label = true
372
+ end
373
+
374
+ # Get the checkbox value from either the args hash or from
375
+ # the form object (as specified in the form_for() method).
376
+ if !args[:values] and @form_values.respond_to?(name)
377
+ args[:values] = @form_values.send(name)
378
+ end
379
+
380
+ # That class for each element wrapper (a span tag) can be customized
381
+ # using :span_class => "a_class".
382
+ if args[:span_class]
383
+ span_class = args[:span_class]
384
+ args.delete(:span_class)
385
+ else
386
+ span_class = "checkbox_wrap"
387
+ end
388
+
389
+ # Get the type from the args hash instead of pre-defining it. Doing so
390
+ # means we can use this method for the input_radio method.
391
+ args[:type] = :checkbox if !args[:type]
392
+
393
+ # Convert the values to an array if it's something we can't use in a loop
394
+ # (e.g. a string).
395
+ if args[:values].class != Hash and args[:values].class != Array
396
+ args[:values] = [args[:values]]
397
+ end
398
+
399
+ # Create a checkbox for each value
400
+ if !args[:values].empty?
401
+ @g.p do
402
+ # Let's create the label and the hidden field
403
+ if show_label === true
404
+ label_for(id, label, name)
405
+ end
406
+
407
+ # Loop through all the values. Each checkbox will have an ID of
408
+ # "form-NAME-INDEX". Each name will be NAME followed by [] to
409
+ # indicate it's an array (since multiple values are possible).
410
+ args[:values].each_with_index do |value, index|
411
+ id = args[:id] ? args[:id] : "#{id_for(name)}_#{index}"
412
+
413
+ if args[:type] == :checkbox
414
+ checkbox_name = "#{name}[]"
415
+ else
416
+ checkbox_name = name
417
+ end
418
+
419
+ # Copy all additional attributes and their values except the
420
+ # values array.
421
+ opts = args.clone
422
+ opts.delete(:values)
423
+
424
+ # Get the value and text to display for each checkbox
425
+ if value.class == Array
426
+ checkbox_text = value[0]
427
+ checkbox_value = value[1]
428
+ else
429
+ checkbox_text = checkbox_value = value
430
+ end
431
+
432
+ # Let's see if the current item is checked
433
+ if checked.class == Array
434
+ if checked.include?(checkbox_value)
435
+ opts[:checked] = 'checked'
436
+ end
437
+ else
438
+ if checkbox_value == checked
439
+ opts[:checked] = 'checked'
440
+ end
441
+ end
442
+
443
+ # And we're done, easy wasn't it?
444
+ opts = opts.merge(
445
+ :name => checkbox_name, :id => id, :value => checkbox_value
446
+ )
447
+
448
+ # Generate the following HTML:
449
+ #
450
+ # <span class="#{span_class}">
451
+ # <input type="checkbox" name="#{checkbox_name}" id="#{id}"
452
+ # value="#{value}" /> #{value}
453
+ # </span>
454
+ #
455
+ @g.span(:class => span_class) do
456
+ @g.input(opts)
457
+ " #{checkbox_text}" if show_value === true
458
+ end
459
+ end
460
+ end
461
+ end
462
+ end
463
+ alias checkbox input_checkbox
464
+
465
+ ##
466
+ # Generate an input tag with a type of "radio".
467
+ #
468
+ # If you want to generate multiple radio buttons you can use an array
469
+ # just like you can with checkboxes. Example:
470
+ #
471
+ # @data = Class.new
472
+ # attr_reader :gender_arr
473
+ # attr_reader :gender_hash
474
+ #
475
+ # def initialize
476
+ # @gender_arr = ['male', 'female']
477
+ # @gender_hash = {"Male" => "male", "Female" => "female"}
478
+ # end
479
+ # end.new
480
+ #
481
+ # form_for(@data, :method => :post) do |f|
482
+ # f.input_radio "Gender", :gender_arr
483
+ # f.input_radio "Gender", :gender_hash
484
+ # end
485
+ #
486
+ # For more information see the input_checkbox() method.
487
+ #
488
+ # @param [String] label The text to display inside the label tag.
489
+ # @param [String Symbol] name The name of the radio button.
490
+ # @param [String] checked String that indicates if (and which) radio
491
+ # button should be checked.
492
+ # @param [Hash] args Any additional HTML attributes along with their
493
+ # values.
494
+ # @see input_checkbox()
495
+ # @example
496
+ # form_for(@data, :method => :post) do |f|
497
+ # f.input_radio 'Gender', :gender
498
+ # end
499
+ #
500
+ def input_radio(label, name, checked = nil, args = {})
501
+ # Force a type of "radio"
502
+ args[:type] = :radio
503
+
504
+ if !args[:span_class]
505
+ args[:span_class] = "radio_wrap"
506
+ end
507
+
508
+ self.input_checkbox(label, name, checked, args)
509
+ end
510
+ alias radio input_radio
511
+
512
+ ##
513
+ # Generate a field for uploading files.
514
+ #
515
+ # @param [String] label The text to display inside the label tag.
516
+ # @param [String Symbol] name The name of the radio tag.
517
+ # @param [Hash] args Any additional HTML attributes along with their
518
+ # values.
519
+ # @example
520
+ #
521
+ # form_for(@data, :method => :post) do |f|
522
+ # f.input_file 'Image', :image
523
+ # end
524
+ #
525
+ def input_file(label, name, args = {})
526
+ id = args[:id] ? args[:id] : id_for(name)
527
+ args = args.merge(:type => :file, :name => name, :id => id)
528
+
529
+ @g.p do
530
+ label_for(id, label, name)
531
+ @g.input(args)
532
+ end
533
+ end
534
+ alias file input_file
535
+
536
+ ##
537
+ # Generate a hidden field. Hidden fields are essentially the same as
538
+ # text fields except that they aren't displayed in the browser.
539
+ #
540
+ # @param [String Symbol] name The name of the hidden field tag.
541
+ # @param [String] value The value of the hidden field
542
+ # @param [Hash] args Any additional HTML attributes along with their
543
+ # values.
544
+ # @example
545
+ #
546
+ # form_for(@data, :method => :post) do |f|
547
+ # f.input_hidden :user_id
548
+ # end
549
+ #
550
+ def input_hidden(name, value = nil, args = {})
551
+ args = args.merge(:type => :hidden, :name => name)
552
+
553
+ if !value and @form_values.respond_to?(name)
554
+ args[:value] = @form_values.send(name)
555
+ else
556
+ args[:value] = value
557
+ end
558
+
559
+ @g.input(args)
560
+ end
561
+ alias hidden input_hidden
562
+
563
+ ##
564
+ # Generate a text area.
565
+ #
566
+ # @param [String] label The text to display inside the label tag.
567
+ # @param [String Symbol] name The name of the textarea.
568
+ # @param [Hash] args Any additional HTML attributes along with their
569
+ # values.
570
+ # @example
571
+ #
572
+ # form_for(@data, :method => :post) do |f|
573
+ # f.textarea 'Description', :description
574
+ # end
575
+ #
576
+ def textarea(label, name, args = {})
577
+ id = args[:id] ? args[:id] : id_for(name)
578
+
579
+ # Get the value of the textarea
580
+ if !args[:value] and @form_values.respond_to?(name)
581
+ value = @form_values.send(name)
582
+ else
583
+ value = args[:value]
584
+ args.delete(:value)
585
+ end
586
+
587
+ args = args.merge(:name => name, :id => id)
588
+
589
+ @g.p do
590
+ label_for(id, label, name)
591
+ @g.textarea(args){ value }
592
+ end
593
+ end
594
+
595
+ ##
596
+ # Generate a select tag along with the option tags and a label.
597
+ #
598
+ # @param [String] label The text to display inside the label tag.
599
+ # @param [String Symbol] name The name of the select tag.
600
+ # @param [Hash] args Hash containing additional HTML attributes.
601
+ # @example
602
+ #
603
+ # form_for(@data, :method => :post) do |f|
604
+ # f.select 'Country', :country_list
605
+ # end
606
+ #
607
+ def select(label, name, args = {})
608
+ id = args[:id] ? args[:id] : id_for(name)
609
+ multiple, size = args.values_at(:multiple, :size)
610
+
611
+ # Get all the values
612
+ if !args[:values] and @form_values.respond_to?(name)
613
+ values = @form_values.send(name)
614
+ else
615
+ values = args[:values]
616
+ args.delete(:values)
617
+ end
618
+
619
+ args[:multiple] = 'multiple' if multiple
620
+ args[:size] = (size || values.count || 1).to_i
621
+ args[:name] = multiple ? "#{name}[]" : name
622
+ args = args.merge(:id => id)
623
+
624
+ # Retrieve the selected value
625
+ has_selected, selected = args.key?(:selected), args[:selected]
626
+ selected = [selected] if !selected.is_a?(Array)
627
+ args.delete(:selected)
628
+
629
+ @g.p do
630
+ label_for(id, label, name)
631
+ @g.select args do
632
+ values.each do |value, o_name|
633
+ o_name ||= value
634
+ o_args = {:value => value}
635
+
636
+ if has_selected and selected.include?(value)
637
+ o_args[:selected] = 'selected'
638
+ end
639
+
640
+ @g.option(o_args){ o_name }
641
+ end
642
+ end
643
+ end
644
+ end
645
+
646
+ ##
647
+ # Method used for converting the results of the BlueForm helper to a
648
+ # string
649
+ #
650
+ # @return [String] The form output
651
+ #
652
+ def to_s
653
+ @g.to_s
654
+ end
655
+
656
+ private
657
+
658
+ ##
659
+ # Generate a label based on the id and value.
660
+ #
661
+ # @param [String] id The ID to which the label belongs.
662
+ # @param [String] value The text to display inside the label tag.
663
+ # @param [String] name The name of the field to which the label belongs.
664
+ #
665
+ def label_for(id, value, name)
666
+ if error = @form_errors.delete(name.to_s)
667
+ @g.label("#{value} ", :for => id){ @g.span(:class => :error){ error } }
668
+ else
669
+ @g.label(value, :for => id)
670
+ end
671
+ end
672
+
673
+ ##
674
+ # Generate a value for an ID tag based on the field's name.
675
+ #
676
+ # @param [String] field_name The name of the field.
677
+ # @return [String] The ID for the specified field name.
678
+ #
679
+ def id_for(field_name)
680
+ if name = @form_args[:name]
681
+ "#{name}_#{field_name}".downcase.gsub(/-/, '_')
682
+ else
683
+ "form_#{field_name}".downcase.gsub(/-/, '_')
684
+ end
685
+ end
686
+ end # Form
687
+ end # BlueForm
688
+ end # Helper
689
+ end # Ramaze