typus 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. data/Gemfile +20 -9
  2. data/Gemfile.lock +93 -65
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +61 -0
  5. data/Rakefile +5 -0
  6. data/app/controllers/admin/account_controller.rb +7 -10
  7. data/app/controllers/admin/base_controller.rb +16 -1
  8. data/app/controllers/admin/resources_controller.rb +270 -159
  9. data/app/controllers/admin/session_controller.rb +8 -9
  10. data/app/helpers/admin/base_helper.rb +13 -28
  11. data/app/helpers/admin/dashboard_helper.rb +4 -10
  12. data/app/helpers/admin/file_preview_helper.rb +70 -0
  13. data/app/helpers/admin/filters_helper.rb +64 -45
  14. data/app/helpers/admin/form_helper.rb +37 -62
  15. data/app/helpers/admin/relationships_helper.rb +63 -78
  16. data/app/helpers/admin/resources_helper.rb +10 -31
  17. data/app/helpers/admin/search_helper.rb +6 -9
  18. data/app/helpers/admin/sidebar_helper.rb +15 -20
  19. data/app/helpers/admin/table_helper.rb +79 -170
  20. data/app/mailers/admin/mailer.rb +1 -1
  21. data/app/views/admin/account/forgot_password.html.erb +2 -2
  22. data/app/views/admin/account/new.html.erb +8 -4
  23. data/app/views/admin/base/user_guide.html.erb +85 -0
  24. data/app/views/admin/dashboard/_sidebar.html.erb +3 -1
  25. data/app/views/admin/dashboard/show.html.erb +2 -2
  26. data/app/views/admin/dashboard/styles.html.erb +2 -2
  27. data/app/views/admin/helpers/_apps.html.erb +5 -4
  28. data/app/views/admin/helpers/_file_preview.html.erb +3 -0
  29. data/app/views/admin/helpers/_header.html.erb +3 -3
  30. data/app/views/admin/helpers/_login_info.html.erb +2 -2
  31. data/app/views/admin/helpers/dashboard/_applications.html.erb +6 -9
  32. data/app/views/admin/helpers/dashboard/_resources.html.erb +2 -3
  33. data/app/views/admin/helpers/filters/_filters.html.erb +1 -1
  34. data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
  35. data/app/views/admin/helpers/resources/_errors.html.erb +10 -0
  36. data/app/views/admin/helpers/search/_search.html.erb +1 -1
  37. data/app/views/admin/helpers/sidebar/_sidebar.html.erb +6 -3
  38. data/app/views/admin/helpers/table/_table.html.erb +17 -5
  39. data/app/views/admin/mailer/reset_password_link.text.erb +2 -2
  40. data/app/views/admin/resources/_form.html.erb +3 -12
  41. data/app/views/admin/resources/edit.html.erb +7 -5
  42. data/app/views/admin/resources/index.html.erb +13 -18
  43. data/app/views/admin/resources/new.html.erb +4 -4
  44. data/app/views/admin/resources/show.html.erb +9 -13
  45. data/app/views/admin/session/new.html.erb +8 -4
  46. data/app/views/admin/templates/_belongs_to.html.erb +1 -1
  47. data/app/views/admin/templates/_boolean.html.erb +2 -2
  48. data/app/views/admin/templates/_date.html.erb +2 -2
  49. data/app/views/admin/templates/_datetime.html.erb +2 -2
  50. data/app/views/admin/templates/_file.html.erb +3 -19
  51. data/app/views/admin/templates/_has_n.html.erb +4 -4
  52. data/app/views/admin/templates/_has_one.html.erb +14 -0
  53. data/app/views/admin/templates/_password.html.erb +2 -2
  54. data/app/views/admin/templates/_profile_sidebar.html.erb +3 -0
  55. data/app/views/admin/templates/_relate_form.html.erb +2 -1
  56. data/app/views/admin/templates/_selector.html.erb +1 -1
  57. data/app/views/admin/templates/_string.html.erb +6 -6
  58. data/app/views/admin/templates/_text.html.erb +11 -4
  59. data/app/views/admin/templates/_time.html.erb +2 -2
  60. data/app/views/admin/templates/_tree.html.erb +1 -1
  61. data/app/views/layouts/admin/base.html.erb +7 -6
  62. data/app/views/layouts/admin/session.html.erb +4 -14
  63. data/config/{available_locales/ca_models.yml → locales/typus.ca.models.yml} +5 -4
  64. data/config/locales/typus.ca.yml +81 -0
  65. data/config/{available_locales/de_models.yml → locales/typus.de.models.yml} +6 -2
  66. data/config/locales/typus.de.yml +80 -0
  67. data/config/locales/typus.el.models.yml +17 -0
  68. data/config/locales/typus.el.yml +82 -0
  69. data/config/{available_locales/es_models.yml → locales/typus.es.models.yml} +9 -4
  70. data/config/locales/typus.es.yml +82 -0
  71. data/config/{available_locales/fr_models.yml → locales/typus.fr.models.yml} +8 -3
  72. data/config/locales/typus.fr.yml +87 -0
  73. data/config/{available_locales/hu_models.yml → locales/typus.hu.models.yml} +6 -2
  74. data/config/locales/typus.hu.yml +80 -0
  75. data/config/{available_locales/it_models.yml → locales/typus.it.models.yml} +7 -4
  76. data/config/locales/typus.it.yml +89 -0
  77. data/config/{available_locales/language_models.yml.template → locales/typus.locale.models.yml.template} +8 -4
  78. data/config/locales/typus.locale.yml.template +81 -0
  79. data/config/{available_locales/pt-BR_models.yml → locales/typus.pt-BR.models.yml} +6 -2
  80. data/config/locales/typus.pt-BR.yml +80 -0
  81. data/config/{available_locales/ru_models.yml → locales/typus.ru.models.yml} +6 -2
  82. data/config/locales/typus.ru.yml +80 -0
  83. data/config/locales/typus.zh-CN.models.yml +17 -0
  84. data/config/locales/typus.zh-CN.yml +79 -0
  85. data/config/routes.rb +11 -7
  86. data/lib/generators/templates/config/initializers/typus.rb +8 -5
  87. data/lib/generators/templates/config/initializers/typus_resources.rb +0 -3
  88. data/lib/generators/templates/config/typus/README +6 -6
  89. data/lib/generators/templates/config/typus/typus.yml +5 -5
  90. data/lib/generators/templates/controller.rb +1 -1
  91. data/lib/generators/templates/migration.rb +1 -0
  92. data/lib/generators/templates/public/admin/javascripts/application.js +0 -4
  93. data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +167 -0
  94. data/lib/generators/templates/public/admin/javascripts/jquery.application.js +16 -0
  95. data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +50 -22
  96. data/lib/generators/templates/public/admin/stylesheets/screen.css +43 -34
  97. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
  98. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +32 -32
  99. data/lib/generators/templates/public/admin/vendor/fancybox/{jquery.fancybox-1.3.1.css → jquery.fancybox-1.3.4.css} +359 -363
  100. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +1156 -0
  101. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
  102. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
  103. data/lib/generators/typus/assets_generator.rb +23 -0
  104. data/lib/generators/typus/controller_generator.rb +29 -0
  105. data/lib/generators/typus/migration_generator.rb +39 -20
  106. data/lib/generators/typus/typus_generator.rb +17 -57
  107. data/lib/generators/typus/views_generator.rb +2 -6
  108. data/lib/support/active_record.rb +8 -20
  109. data/lib/support/fake_user.rb +6 -1
  110. data/lib/support/hash.rb +1 -2
  111. data/lib/support/object.rb +4 -17
  112. data/lib/support/string.rb +34 -3
  113. data/lib/tasks/typus.rake +1 -1
  114. data/lib/typus.rb +60 -48
  115. data/lib/typus/actions.rb +27 -0
  116. data/lib/typus/authentication/base.rb +3 -4
  117. data/lib/typus/authentication/http_basic.rb +1 -1
  118. data/lib/typus/authentication/none.rb +1 -1
  119. data/lib/typus/authentication/session.rb +53 -108
  120. data/lib/typus/configuration.rb +13 -11
  121. data/lib/typus/filters.rb +12 -0
  122. data/lib/typus/format.rb +9 -13
  123. data/lib/typus/i18n.rb +30 -0
  124. data/lib/typus/orm/active_record.rb +97 -194
  125. data/lib/typus/orm/active_record/search.rb +91 -0
  126. data/lib/typus/resources.rb +6 -10
  127. data/lib/typus/user.rb +20 -40
  128. data/lib/typus/version.rb +1 -1
  129. metadata +77 -231
  130. data/CHANGELOG +0 -102
  131. data/README.rdoc +0 -48
  132. data/app/helpers/admin/preview_helper.rb +0 -46
  133. data/app/views/admin/helpers/_preview.html.erb +0 -13
  134. data/app/views/admin/templates/_has_many.html.erb +0 -22
  135. data/config/available_locales/ca.yml +0 -122
  136. data/config/available_locales/de.yml +0 -122
  137. data/config/available_locales/es.yml +0 -122
  138. data/config/available_locales/fr.yml +0 -127
  139. data/config/available_locales/hu.yml +0 -122
  140. data/config/available_locales/it.yml +0 -132
  141. data/config/available_locales/language.yml.template +0 -120
  142. data/config/available_locales/pt-BR.yml +0 -122
  143. data/config/available_locales/ru.yml +0 -122
  144. data/lib/generators/templates/functional_test.rb +0 -10
  145. data/lib/generators/templates/model.rb +0 -8
  146. data/lib/generators/templates/public/admin/images/ui-icons.png +0 -0
  147. data/lib/generators/templates/public/admin/javascripts/jquery-1.4.2.min.js +0 -154
  148. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.js +0 -1077
  149. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  150. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.2.pack.js +0 -13
  151. data/lib/typus/pagination.rb +0 -18
  152. data/test/factories.rb +0 -43
  153. data/test/fixtures/config/broken/application.yml +0 -68
  154. data/test/fixtures/config/broken/application_roles.yml +0 -20
  155. data/test/fixtures/config/broken/empty.yml +0 -0
  156. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  157. data/test/fixtures/config/broken/undefined.yml +0 -3
  158. data/test/fixtures/config/broken/undefined_roles.yml +0 -6
  159. data/test/fixtures/config/default/typus.yml +0 -13
  160. data/test/fixtures/config/default/typus_roles.yml +0 -2
  161. data/test/fixtures/config/empty/empty_01.yml +0 -0
  162. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  163. data/test/fixtures/config/empty/empty_02.yml +0 -0
  164. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  165. data/test/fixtures/config/locales/es.yml +0 -10
  166. data/test/fixtures/config/namespaced/application.yml +0 -5
  167. data/test/fixtures/config/namespaced/application_roles.yml +0 -2
  168. data/test/fixtures/config/ordered/001_roles.yml +0 -2
  169. data/test/fixtures/config/ordered/002_roles.yml +0 -2
  170. data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
  171. data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
  172. data/test/fixtures/config/working/application.yml +0 -73
  173. data/test/fixtures/config/working/application_roles.yml +0 -24
  174. data/test/fixtures/config/working/typus.yml +0 -13
  175. data/test/fixtures/config/working/typus_roles.yml +0 -2
  176. data/test/fixtures/rails_app/Rakefile +0 -7
  177. data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +0 -2
  178. data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +0 -2
  179. data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +0 -2
  180. data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +0 -2
  181. data/test/fixtures/rails_app/app/controllers/admin/pictures_controller.rb +0 -2
  182. data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +0 -2
  183. data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +0 -2
  184. data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +0 -2
  185. data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +0 -2
  186. data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -3
  187. data/test/fixtures/rails_app/app/models/asset.rb +0 -5
  188. data/test/fixtures/rails_app/app/models/category.rb +0 -11
  189. data/test/fixtures/rails_app/app/models/comment.rb +0 -6
  190. data/test/fixtures/rails_app/app/models/custom_user.rb +0 -2
  191. data/test/fixtures/rails_app/app/models/delayed/task.rb +0 -5
  192. data/test/fixtures/rails_app/app/models/page.rb +0 -5
  193. data/test/fixtures/rails_app/app/models/picture.rb +0 -6
  194. data/test/fixtures/rails_app/app/models/post.rb +0 -21
  195. data/test/fixtures/rails_app/app/models/typus_user.rb +0 -8
  196. data/test/fixtures/rails_app/app/models/view.rb +0 -5
  197. data/test/fixtures/rails_app/app/views/admin/categories/_form.html.erb +0 -1
  198. data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +0 -1
  199. data/test/fixtures/rails_app/app/views/admin/mailer/reset_password_link.text.erb +0 -6
  200. data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +0 -1
  201. data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +0 -1
  202. data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +0 -1
  203. data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +0 -1
  204. data/test/fixtures/rails_app/app/views/admin/posts/_sidebar.html.erb +0 -1
  205. data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +0 -1
  206. data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +0 -1
  207. data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +0 -1
  208. data/test/fixtures/rails_app/config.ru +0 -4
  209. data/test/fixtures/rails_app/config/application.rb +0 -53
  210. data/test/fixtures/rails_app/config/boot.rb +0 -13
  211. data/test/fixtures/rails_app/config/database.yml +0 -14
  212. data/test/fixtures/rails_app/config/environment.rb +0 -5
  213. data/test/fixtures/rails_app/config/environments/test.rb +0 -34
  214. data/test/fixtures/rails_app/config/initializers/secret_token.rb +0 -7
  215. data/test/fixtures/rails_app/config/initializers/session_store.rb +0 -8
  216. data/test/fixtures/rails_app/config/initializers/typus.rb +0 -6
  217. data/test/fixtures/rails_app/config/routes.rb +0 -5
  218. data/test/fixtures/rails_app/config/typus/application.yml +0 -79
  219. data/test/fixtures/rails_app/config/typus/application_roles.yml +0 -25
  220. data/test/fixtures/rails_app/config/typus/typus.yml +0 -12
  221. data/test/fixtures/rails_app/config/typus/typus_roles.yml +0 -2
  222. data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
  223. data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +0 -2
  224. data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +0 -2
  225. data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +0 -2
  226. data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +0 -2
  227. data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +0 -2
  228. data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +0 -2
  229. data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +0 -2
  230. data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +0 -2
  231. data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +0 -2
  232. data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +0 -2
  233. data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +0 -2
  234. data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +0 -2
  235. data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +0 -2
  236. data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +0 -2
  237. data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +0 -2
  238. data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +0 -2
  239. data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +0 -2
  240. data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +0 -2
  241. data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +0 -2
  242. data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +0 -2
  243. data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +0 -2
  244. data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +0 -2
  245. data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +0 -2
  246. data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +0 -2
  247. data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +0 -2
  248. data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +0 -2
  249. data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +0 -2
  250. data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +0 -2
  251. data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +0 -2
  252. data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +0 -2
  253. data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +0 -2
  254. data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +0 -2
  255. data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +0 -2
  256. data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +0 -2
  257. data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +0 -2
  258. data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +0 -2
  259. data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +0 -2
  260. data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +0 -2
  261. data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +0 -2
  262. data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +0 -2
  263. data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +0 -2
  264. data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +0 -2
  265. data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +0 -2
  266. data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +0 -2
  267. data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +0 -2
  268. data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +0 -2
  269. data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +0 -2
  270. data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +0 -2
  271. data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +0 -2
  272. data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +0 -2
  273. data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +0 -2
  274. data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +0 -2
  275. data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +0 -2
  276. data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +0 -2
  277. data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +0 -2
  278. data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +0 -2
  279. data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +0 -2
  280. data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +0 -2
  281. data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +0 -2
  282. data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +0 -2
  283. data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +0 -2
  284. data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +0 -2
  285. data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +0 -2
  286. data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +0 -2
  287. data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +0 -2
  288. data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +0 -2
  289. data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +0 -2
  290. data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +0 -2
  291. data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +0 -2
  292. data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +0 -2
  293. data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +0 -2
  294. data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +0 -2
  295. data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +0 -2
  296. data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +0 -2
  297. data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +0 -2
  298. data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +0 -2
  299. data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +0 -2
  300. data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +0 -2
  301. data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +0 -2
  302. data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +0 -2
  303. data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +0 -2
  304. data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +0 -2
  305. data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +0 -2
  306. data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +0 -2
  307. data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +0 -2
  308. data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +0 -2
  309. data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +0 -2
  310. data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +0 -2
  311. data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +0 -2
  312. data/test/functional/admin/account_controller_test.rb +0 -90
  313. data/test/functional/admin/assets_controller_test.rb +0 -55
  314. data/test/functional/admin/categories_controller_test.rb +0 -62
  315. data/test/functional/admin/comments_controller_test.rb +0 -21
  316. data/test/functional/admin/dashboard_controller_test.rb +0 -138
  317. data/test/functional/admin/posts_controller_test.rb +0 -548
  318. data/test/functional/admin/session_controller_test.rb +0 -85
  319. data/test/functional/admin/status_controller_test.rb +0 -46
  320. data/test/functional/admin/typus_users_controller_test.rb +0 -159
  321. data/test/helpers/admin/base_helper_test.rb +0 -67
  322. data/test/helpers/admin/dashboard_helper_test.rb +0 -19
  323. data/test/helpers/admin/form_helper_test.rb +0 -117
  324. data/test/helpers/admin/resources_helper_test.rb +0 -64
  325. data/test/helpers/admin/sidebar_helper_test.rb +0 -274
  326. data/test/helpers/admin/table_helper_test.rb +0 -219
  327. data/test/integration/login_test.rb +0 -13
  328. data/test/integration_test_helper.rb +0 -21
  329. data/test/lib/support/active_record_test.rb +0 -86
  330. data/test/lib/support/array_test.rb +0 -11
  331. data/test/lib/support/hash_test.rb +0 -11
  332. data/test/lib/support/string_test.rb +0 -39
  333. data/test/lib/typus/active_record_test.rb +0 -451
  334. data/test/lib/typus/configuration_test.rb +0 -52
  335. data/test/lib/typus/resource_test.rb +0 -17
  336. data/test/lib/typus/routes_test.rb +0 -29
  337. data/test/lib/typus_test.rb +0 -107
  338. data/test/schema.rb +0 -100
  339. data/test/test_helper.rb +0 -16
  340. data/test/unit/admin/mailer_test.rb +0 -32
  341. data/test/unit/typus_user_roles_test.rb +0 -105
  342. data/test/unit/typus_user_test.rb +0 -142
  343. data/typus.gemspec +0 -25
@@ -9,13 +9,14 @@ module Typus
9
9
  files = (application + plugins).reject { |f| f.include?("_roles.yml") }
10
10
 
11
11
  @@config = {}
12
+
12
13
  files.each do |file|
13
14
  if data = YAML::load_file(file)
14
15
  @@config.merge!(data)
15
16
  end
16
17
  end
17
18
 
18
- return @@config
19
+ @@config
19
20
  end
20
21
 
21
22
  mattr_accessor :config
@@ -26,26 +27,27 @@ module Typus
26
27
  plugins = Dir[File.join("vendor", "plugins", "*", "config", "typus", "*_roles.yml").to_s]
27
28
  files = (application + plugins).sort
28
29
 
29
- @@roles = { Typus.master_role => {} }
30
+ @@roles = {}
30
31
 
31
32
  files.each do |file|
32
- data = YAML::load_file(file)
33
- next unless data
34
- data.each do |key, value|
35
- next unless value
36
- begin
37
- @@roles[key].merge!(value)
38
- rescue
39
- @@roles[key] = value
33
+ if data = YAML::load_file(file)
34
+ data.compact.each do |key, value|
35
+ @@roles[key] ? @@roles[key].merge!(value) : (@@roles[key] = value)
40
36
  end
41
37
  end
42
38
  end
43
39
 
44
- return @@roles.compact
40
+ @@roles
45
41
  end
46
42
 
47
43
  mattr_accessor :roles
48
44
 
45
+ def self.models_constantized!
46
+ @@models_constantized = config.map { |i| i.first }.inject({}) { |result, model| result[model] = model.constantize; result }
47
+ end
48
+
49
+ mattr_accessor :models_constantized
50
+
49
51
  end
50
52
 
51
53
  end
@@ -0,0 +1,12 @@
1
+ module Typus
2
+
3
+ module Filters
4
+
5
+ def add_predefined_filter(filter, action, scope)
6
+ @predefined_filters ||= [["All", "index", "unscoped"]]
7
+ @predefined_filters << [filter, action, scope]
8
+ end
9
+
10
+ end
11
+
12
+ end
data/lib/typus/format.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  if RUBY_VERSION >= '1.9'
2
2
  require 'csv'
3
3
  FasterCSV = CSV
4
+ else
5
+ require 'fastercsv'
4
6
  end
5
7
 
6
8
  module Typus
@@ -10,15 +12,14 @@ module Typus
10
12
  protected
11
13
 
12
14
  def generate_html
13
- items_count = @resource.count(:joins => @joins, :conditions => @conditions)
14
15
  items_per_page = @resource.typus_options_for(:per_page)
15
- @items = data.paginate(:per_page => items_per_page, :page => params[:page])
16
+ @items = @items.paginate(:per_page => items_per_page, :page => params[:page])
16
17
  end
17
18
 
18
19
  #--
19
- # TODO: Find in batches only works properly if it's used on
20
- # models, not controllers, so in this action does nothing.
21
- # We should find a way to be able to process data.
20
+ # TODO: Find in batches only works properly if it's used on models, not
21
+ # controllers, so in this action does nothing. We should find a way
22
+ # to be able to process large amounts of data.
22
23
  #++
23
24
  def generate_csv
24
25
  fields = @resource.typus_fields_for(:csv)
@@ -27,7 +28,7 @@ module Typus
27
28
 
28
29
  options = { :conditions => @conditions, :batch_size => 1000 }
29
30
 
30
- FasterCSV.open(filename, 'w', :col_sep => ';') do |csv|
31
+ ::FasterCSV.open(filename, 'w', :col_sep => ';') do |csv|
31
32
  csv << fields.keys
32
33
  @resource.find_in_batches(options) do |records|
33
34
  records.each do |record|
@@ -58,15 +59,10 @@ module Typus
58
59
  end
59
60
 
60
61
  def export(format)
61
- fields = @resource.typus_fields_for(format).collect { |i| i.first }
62
+ fields = @resource.typus_fields_for(format).map { |i| i.first }
62
63
  methods = fields - @resource.column_names
63
64
  except = @resource.column_names - fields
64
- render format => data.send("to_#{format}", :methods => methods, :except => except)
65
- end
66
-
67
- def data
68
- eager_loading = @resource.reflect_on_all_associations(:belongs_to).map { |i| i.name }
69
- @resource.joins(@joins).where(@conditions).order(@order).includes(eager_loading)
65
+ render format => @items.send("to_#{format}", :methods => methods, :except => except)
70
66
  end
71
67
 
72
68
  end
data/lib/typus/i18n.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Typus
2
+
3
+ module I18n
4
+
5
+ class << self
6
+
7
+ ##
8
+ # Instead of having to translate strings and defining a default value:
9
+ #
10
+ # Typus::I18n.t("Hello World!", :default => 'Hello World!')
11
+ #
12
+ # We define this method to define the value only once:
13
+ #
14
+ # Typus::I18n.t("Hello World!")
15
+ #
16
+ # Note that interpolation still works:
17
+ #
18
+ # Typus::I18n.t("Hello %{world}!", :world => @world)
19
+ #
20
+ def t(msg, *args)
21
+ options = args.extract_options!
22
+ options[:default] = msg
23
+ ::I18n.t(msg, options)
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -6,147 +6,130 @@ module Typus
6
6
 
7
7
  # Model fields as an <tt>ActiveSupport::OrderedHash</tt>.
8
8
  def model_fields
9
- hash = ActiveSupport::OrderedHash.new
10
- columns.map { |u| hash[u.name.to_sym] = u.type.to_sym }
11
- return hash
9
+ ActiveSupport::OrderedHash.new.tap do |hash|
10
+ columns.map { |u| hash[u.name.to_sym] = u.type.to_sym }
11
+ end
12
12
  end
13
13
 
14
14
  # Model relationships as an <tt>ActiveSupport::OrderedHash</tt>.
15
15
  def model_relationships
16
- hash = ActiveSupport::OrderedHash.new
17
- reflect_on_all_associations.map { |i| hash[i.name] = i.macro }
18
- return hash
16
+ ActiveSupport::OrderedHash.new.tap do |hash|
17
+ reflect_on_all_associations.map { |i| hash[i.name] = i.macro }
18
+ end
19
19
  end
20
20
 
21
21
  # Model description for admin panel.
22
22
  def typus_description
23
- Typus::Configuration.config[self.name]['description']
23
+ read_model_config['description']
24
24
  end
25
25
 
26
26
  # Form and list fields
27
27
  def typus_fields_for(filter)
28
+ ActiveSupport::OrderedHash.new.tap do |fields_with_type|
29
+ data = read_model_config['fields']
30
+ fields = data[filter.to_s] || data['default'] || ""
28
31
 
29
- fields_with_type = ActiveSupport::OrderedHash.new
30
-
31
- begin
32
- fields = Typus::Configuration.config[name]['fields'][filter.to_s]
33
- fields = fields.extract_settings.collect { |f| f.to_sym }
34
- rescue
35
- return [] if filter == 'default'
36
- filter = 'default'
37
- retry
38
- end
39
-
40
- begin
41
-
42
- fields.each do |field|
43
-
44
- attribute_type = model_fields[field]
32
+ virtual_fields = instance_methods - model_fields.keys.map { |i| i.to_s }
45
33
 
34
+ fields.extract_settings.map { |f| f.to_sym }.each do |field|
46
35
  if reflect_on_association(field)
47
- attribute_type = reflect_on_association(field).macro
36
+ fields_with_type[field.to_s] = reflect_on_association(field).macro
37
+ next
48
38
  end
49
39
 
50
40
  if typus_field_options_for(:selectors).include?(field)
51
- attribute_type = :selector
41
+ fields_with_type[field.to_s] = :selector
42
+ next
52
43
  end
53
44
 
54
- # Custom field_type depending on the attribute name.
55
- case field.to_s
56
- when 'parent', 'parent_id' then attribute_type = :tree
57
- when /password/ then attribute_type = :password
58
- when 'position' then attribute_type = :position
59
- when /\./ then attribute_type = :transversal
45
+ dragonfly = respond_to?(:dragonfly_apps_for_attributes) && dragonfly_apps_for_attributes.try(:has_key?, field)
46
+ paperclip = respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
47
+
48
+ if dragonfly || paperclip
49
+ fields_with_type[field.to_s] = :file
50
+ next
60
51
  end
61
52
 
62
- if respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
63
- attribute_type = :file
53
+ if virtual_fields.include?(field.to_s)
54
+ fields_with_type[field.to_s] = :virtual
64
55
  end
65
56
 
66
- # And finally insert the field and the attribute_type
67
- # into the fields_with_type ordered hash.
68
- fields_with_type[field.to_s] = attribute_type
57
+ fields_with_type[field.to_s] = case field.to_s
58
+ when 'parent', 'parent_id' then :tree
59
+ when /password/ then :password
60
+ when 'position' then :position
61
+ when /\./ then :transversal
62
+ else
63
+ if fields_with_type[field.to_s]
64
+ fields_with_type[field.to_s]
65
+ else
66
+ model_fields[field]
67
+ end
68
+ end
69
69
 
70
70
  end
71
-
72
- rescue
73
- fields = Typus::Configuration.config[name]['fields']['default'].extract_settings
74
- retry
75
71
  end
76
-
77
- return fields_with_type
78
-
79
72
  end
80
73
 
81
74
  def typus_filters
82
- fields_with_type = ActiveSupport::OrderedHash.new
83
-
84
- data = Typus::Configuration.config[name]['filters']
85
- return [] unless data
86
- fields = data.extract_settings.collect { |i| i.to_sym }
87
-
88
- fields.each do |field|
89
- attribute_type = model_fields[field.to_sym]
90
- if reflect_on_association(field.to_sym)
91
- attribute_type = reflect_on_association(field.to_sym).macro
75
+ ActiveSupport::OrderedHash.new.tap do |fields_with_type|
76
+ if data = read_model_config['filters']
77
+ data.extract_settings.map { |i| i.to_sym }.each do |field|
78
+ attribute_type = model_fields[field.to_sym]
79
+ if reflect_on_association(field.to_sym)
80
+ attribute_type = reflect_on_association(field.to_sym).macro
81
+ end
82
+ fields_with_type[field.to_s] = attribute_type
83
+ end
92
84
  end
93
- fields_with_type[field.to_s] = attribute_type
94
85
  end
95
-
96
- return fields_with_type
97
86
  end
98
87
 
99
88
  # Extended actions for this model on Typus.
100
89
  def typus_actions_on(filter)
101
- Typus::Configuration.config[name]['actions'][filter.to_s].extract_settings
102
- rescue
103
- []
90
+ actions = read_model_config['actions']
91
+ actions && actions[filter.to_s] ? actions[filter.to_s].extract_settings : []
104
92
  end
105
93
 
106
94
  # Used for +search+, +relationships+
107
95
  def typus_defaults_for(filter)
108
- data = Typus::Configuration.config[name][filter.to_s]
109
- return data.try(:extract_settings) || []
96
+ read_model_config[filter.to_s].try(:extract_settings) || []
110
97
  end
111
98
 
112
99
  def typus_search_fields
113
- data = typus_defaults_for(:search)
114
-
115
- search = {}
116
-
117
- data.each do |field|
118
- if field.starts_with?("=")
119
- field.slice!(0)
120
- search[field] = "="
121
- elsif field.starts_with?("^")
122
- field.slice!(0)
123
- search[field] = "^"
124
- else
125
- search[field] = "@"
100
+ Hash.new.tap do |search|
101
+ typus_defaults_for(:search).each do |field|
102
+ if field.starts_with?("=")
103
+ field.slice!(0)
104
+ search[field] = "="
105
+ elsif field.starts_with?("^")
106
+ field.slice!(0)
107
+ search[field] = "^"
108
+ else
109
+ search[field] = "@"
110
+ end
126
111
  end
127
112
  end
128
-
129
- return search
130
113
  end
131
114
 
132
115
  def typus_application
133
- Typus::Configuration.config[name]["application"] || "Unknown"
116
+ read_model_config['application'] || 'Unknown'
134
117
  end
135
118
 
136
119
  def typus_field_options_for(filter)
137
- Typus::Configuration.config[name]['fields']['options'][filter.to_s].extract_settings.collect { |i| i.to_sym }
138
- rescue
139
- []
120
+ options = read_model_config['fields']['options']
121
+ options && options[filter.to_s] ? options[filter.to_s].extract_settings.map { |i| i.to_sym } : []
140
122
  end
141
123
 
142
124
  #--
143
- # Options are defined for all resources on the initializer:
125
+ # With Typus::Resources we some application defaults.
144
126
  #
145
127
  # Typus::Resources.setup do |config|
146
128
  # config.per_page = 15
147
129
  # end
148
130
  #
149
- # But sometimes we need to define theme by model:
131
+ # If for any reason we need a better default for an specific resource we
132
+ # we override it on `application.yaml`.
150
133
  #
151
134
  # Post:
152
135
  # ...
@@ -154,17 +137,17 @@ module Typus
154
137
  # per_page: 15
155
138
  #++
156
139
  def typus_options_for(filter)
157
- data = Typus::Configuration.config[name]
140
+ options = read_model_config['options']
158
141
 
159
- unless data['options'].nil?
160
- value = data['options'][filter.to_s] unless data['options'][filter.to_s].nil?
142
+ unless options.nil? || options[filter.to_s].nil?
143
+ options[filter.to_s]
144
+ else
145
+ Typus::Resources.send(filter)
161
146
  end
162
-
163
- value || Typus::Resources.send(filter)
164
147
  end
165
148
 
166
149
  def typus_export_formats
167
- Typus::Configuration.config[name]['export'].try(:extract_settings) || []
150
+ read_model_config['export'].try(:extract_settings) || []
168
151
  end
169
152
 
170
153
  def typus_order_by
@@ -185,20 +168,27 @@ module Typus
185
168
  #
186
169
  #++
187
170
  def typus_boolean(attribute = :default)
188
- boolean = Typus::Configuration.config[name]['fields']['options']['booleans'][attribute.to_s]
189
- boolean = boolean.extract_settings
171
+ options = read_model_config['fields']['options']
172
+
173
+ boolean = if options && options['booleans'] && boolean = options['booleans'][attribute.to_s]
174
+ boolean.is_a?(String) ? boolean.extract_settings : boolean
175
+ else
176
+ ["True", "False"]
177
+ end
178
+
190
179
  { boolean.first => "true", boolean.last => "false" }
191
- rescue
192
- { "True" => "true", "False" => "false" }
193
180
  end
194
181
 
195
182
  #--
196
183
  # Custom date formats.
197
184
  #++
198
185
  def typus_date_format(attribute = :default)
199
- Typus::Configuration.config[name]['fields']['options']['date_formats'][attribute.to_s].to_sym
200
- rescue
201
- :db
186
+ options = read_model_config['fields']['options']
187
+ if options && options['date_formats'] && options['date_formats'][attribute.to_s]
188
+ options['date_formats'][attribute.to_s].to_sym
189
+ else
190
+ :default
191
+ end
202
192
  end
203
193
 
204
194
  #--
@@ -214,113 +204,24 @@ module Typus
214
204
  # Templates are stored on <tt>app/views/admin/templates</tt>.
215
205
  #++
216
206
  def typus_template(attribute)
217
- Typus::Configuration.config[name]['fields']['options']['templates'][attribute.to_s]
218
- rescue
219
- nil
220
- end
221
-
222
- #--
223
- # Sidebar filters:
224
- #
225
- # - Booleans: true, false
226
- # - Datetime: today, last_few_days, last_7_days, last_30_days
227
- # - Integer & String: *_id and "selectors" (p.ej. category_id)
228
- #++
229
- def build_conditions(params)
230
-
231
- adapter = ActiveRecord::Base.configurations[Rails.env]['adapter']
232
-
233
- conditions, joins = merge_conditions, []
234
-
235
- query_params = params.dup
236
- %w(action controller).each { |param| query_params.delete(param) }
237
-
238
- # Remove from params those with empty string.
239
- query_params.delete_if { |k, v| v.empty? }
240
-
241
- # If a search is performed.
242
- if query_params[:search]
243
- query = ActiveRecord::Base.connection.quote_string(query_params[:search].downcase)
244
- search = []
245
- typus_search_fields.each do |key, value|
246
- _query = case value
247
- when "=" then query
248
- when "^" then "#{query}%"
249
- when "@" then "%#{query}%"
250
- end
251
- key = "LOWER(TEXT(#{key}))" if adapter == 'postgresql'
252
- search << "#{key} LIKE '#{_query}'"
253
- end
254
- conditions = merge_conditions(conditions, search.join(" OR "))
255
- end
256
-
257
- query_params.each do |key, value|
258
-
259
- filter_type = model_fields[key.to_sym] || model_relationships[key.to_sym]
260
-
261
- case filter_type
262
- when :boolean
263
- condition = { key => (value == 'true') ? true : false }
264
- conditions = merge_conditions(conditions, condition)
265
- when :datetime
266
- interval = case value
267
- when 'today' then Time.zone.now.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
268
- when 'last_few_days' then 3.days.ago.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
269
- when 'last_7_days' then 6.days.ago.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
270
- when 'last_30_days' then Time.zone.now.beginning_of_day.prev_month..Time.zone.now.beginning_of_day.tomorrow
271
- end
272
- condition = ["#{key} BETWEEN ? AND ?", interval.first.to_s(:db), interval.last.to_s(:db)]
273
- conditions = merge_conditions(conditions, condition)
274
- when :date
275
- if value.kind_of?(Hash)
276
- date_format = Date::DATE_FORMATS[typus_date_format(key)]
277
-
278
- begin
279
- unless value["from"].blank?
280
- date_from = Date.strptime(value["from"], date_format)
281
- conditions = merge_conditions(conditions, ["#{key} >= ?", date_from])
282
- end
283
-
284
- unless value["to"].blank?
285
- date_to = Date.strptime(value["to"], date_format)
286
- conditions = merge_conditions(conditions, ["#{key} <= ?", date_to])
287
- end
288
- rescue
289
- end
290
- else
291
- # TODO: Improve and test filters.
292
- interval = case value
293
- when 'today' then nil
294
- when 'last_few_days' then 3.days.ago.to_date..Date.tomorrow
295
- when 'last_7_days' then 6.days.ago.beginning_of_day..Date.tomorrow
296
- when 'last_30_days' then (Date.today << 1)..Date.tomorrow
297
- end
298
- if interval
299
- condition = ["#{key} BETWEEN ? AND ?", interval.first, interval.last]
300
- elsif value == 'today'
301
- condition = ["#{key} = ?", Date.today]
302
- end
303
- conditions = merge_conditions(conditions, condition)
304
- end
305
- when :integer, :string
306
- condition = { key => value }
307
- conditions = merge_conditions(conditions, condition)
308
- when :has_and_belongs_to_many
309
- condition = { key => { :id => value } }
310
- conditions = merge_conditions(conditions, condition)
311
- joins << key.to_sym
312
- end
313
-
207
+ options = read_model_config['fields']['options']
208
+ if options && options['templates'] && options['templates'][attribute.to_s]
209
+ options['templates'][attribute.to_s]
314
210
  end
211
+ end
315
212
 
316
- return conditions, joins
317
-
213
+ def adapter
214
+ @adapter ||= ActiveRecord::Base.configurations[Rails.env]['adapter']
318
215
  end
319
216
 
320
217
  def typus_user_id?
321
218
  columns.map { |u| u.name }.include?(Typus.user_fk)
322
219
  end
323
220
 
221
+ def read_model_config
222
+ Typus::Configuration.config[name] or raise "No typus configuration specified for #{name}"
223
+ end
224
+
324
225
  end
325
226
 
326
227
  module InstanceMethods
@@ -336,6 +237,8 @@ module Typus
336
237
  end
337
238
 
338
239
  if defined?(ActiveRecord)
240
+ require 'typus/orm/active_record/search'
339
241
  ActiveRecord::Base.extend Typus::Orm::ClassMethods
242
+ ActiveRecord::Base.extend Typus::Orm::ClassMethods::Search
340
243
  ActiveRecord::Base.send :include, Typus::Orm::InstanceMethods
341
244
  end