jacobat-refinerycms 0.9.6.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (547) hide show
  1. data/.gems +8 -0
  2. data/.gitignore +23 -0
  3. data/.yardopts +31 -0
  4. data/Gemfile +12 -0
  5. data/Rakefile +70 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/admin/base_controller.rb +8 -0
  8. data/app/controllers/application.rb +3 -0
  9. data/app/controllers/application_controller.rb +7 -0
  10. data/app/helpers/application_helper.rb +7 -0
  11. data/bin/refinery +84 -0
  12. data/bin/refinery-override +76 -0
  13. data/bin/refinery-update-core +92 -0
  14. data/config/amazon_s3.yml.example +18 -0
  15. data/config/application.rb +88 -0
  16. data/config/boot.rb +110 -0
  17. data/config/database.yml.example +20 -0
  18. data/config/environment.rb +5 -0
  19. data/config/environments/development.rb +26 -0
  20. data/config/environments/production.rb +26 -0
  21. data/config/environments/test.rb +22 -0
  22. data/config/initializers/inflections.rb +10 -0
  23. data/config/initializers/mime_types.rb +5 -0
  24. data/config/preinitializer.rb +27 -0
  25. data/config/rackspace_cloudfiles.yml.example +14 -0
  26. data/config/routes.rb +20 -0
  27. data/contributors.md +20 -0
  28. data/db/migrate/20091029034951_remove_blurb_from_news_items.rb +9 -0
  29. data/db/migrate/20091109012126_add_missing_indexes.rb +25 -0
  30. data/db/migrate/20091130040711_add_down_for_maintenance_page.rb +15 -0
  31. data/db/migrate/20091207033335_add_superuser_to_users.rb +12 -0
  32. data/db/migrate/20100114092849_add_themes_table.rb +19 -0
  33. data/db/migrate/20100127004649_add_reset_code_to_users.rb +9 -0
  34. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +13 -0
  35. data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +13 -0
  36. data/db/migrate/20100223211536_remove_themes_table.rb +17 -0
  37. data/db/schema.rb +150 -0
  38. data/db/seeds.rb +121 -0
  39. data/doc/.yardoc/checksums +0 -0
  40. data/doc/.yardoc/objects/root.dat +0 -0
  41. data/doc/.yardoc/proxy_types +0 -0
  42. data/lib/refinery_initializer.rb +23 -0
  43. data/license.md +21 -0
  44. data/public/.htaccess +40 -0
  45. data/public/404.html +29 -0
  46. data/public/422.html +30 -0
  47. data/public/500.html +29 -0
  48. data/public/favicon.ico +0 -0
  49. data/public/images/refinery/add.png +0 -0
  50. data/public/images/refinery/admin_bg.png +0 -0
  51. data/public/images/refinery/ajax-loader.gif +0 -0
  52. data/public/images/refinery/branch-end.gif +0 -0
  53. data/public/images/refinery/branch-start.gif +0 -0
  54. data/public/images/refinery/branch.gif +0 -0
  55. data/public/images/refinery/header_background.png +0 -0
  56. data/public/images/refinery/hover-gradient.jpg +0 -0
  57. data/public/images/refinery/icons/accept.png +0 -0
  58. data/public/images/refinery/icons/add.png +0 -0
  59. data/public/images/refinery/icons/application_edit.png +0 -0
  60. data/public/images/refinery/icons/application_go.png +0 -0
  61. data/public/images/refinery/icons/arrow_left.png +0 -0
  62. data/public/images/refinery/icons/arrow_switch.png +0 -0
  63. data/public/images/refinery/icons/arrow_up.png +0 -0
  64. data/public/images/refinery/icons/cancel.png +0 -0
  65. data/public/images/refinery/icons/cog_add.png +0 -0
  66. data/public/images/refinery/icons/cog_edit.png +0 -0
  67. data/public/images/refinery/icons/cross.png +0 -0
  68. data/public/images/refinery/icons/delete.png +0 -0
  69. data/public/images/refinery/icons/edit.png +0 -0
  70. data/public/images/refinery/icons/email_edit.png +0 -0
  71. data/public/images/refinery/icons/email_go.png +0 -0
  72. data/public/images/refinery/icons/email_open.png +0 -0
  73. data/public/images/refinery/icons/eye.png +0 -0
  74. data/public/images/refinery/icons/image_add.png +0 -0
  75. data/public/images/refinery/icons/image_edit.png +0 -0
  76. data/public/images/refinery/icons/layout_add.png +0 -0
  77. data/public/images/refinery/icons/layout_edit.png +0 -0
  78. data/public/images/refinery/icons/page_add.png +0 -0
  79. data/public/images/refinery/icons/page_edit.png +0 -0
  80. data/public/images/refinery/icons/page_white_edit.png +0 -0
  81. data/public/images/refinery/icons/page_white_put.png +0 -0
  82. data/public/images/refinery/icons/star.png +0 -0
  83. data/public/images/refinery/icons/tick.png +0 -0
  84. data/public/images/refinery/icons/user_add.png +0 -0
  85. data/public/images/refinery/icons/user_comment.png +0 -0
  86. data/public/images/refinery/icons/user_edit.png +0 -0
  87. data/public/images/refinery/logo-large.png +0 -0
  88. data/public/images/refinery/logo-medium.png +0 -0
  89. data/public/images/refinery/logo-small-medium.png +0 -0
  90. data/public/images/refinery/logo-small.png +0 -0
  91. data/public/images/refinery/logo.png +0 -0
  92. data/public/images/refinery/nav-3-background.gif +0 -0
  93. data/public/images/refinery/page_bg.png +0 -0
  94. data/public/images/refinery/resolve_digital_footer_logo.png +0 -0
  95. data/public/images/thickbox/cross.png +0 -0
  96. data/public/images/thickbox/loadingAnimation.gif +0 -0
  97. data/public/images/thickbox/macFFBgHack.png +0 -0
  98. data/public/images/wymeditor/skins/refinery/blockquote.png +0 -0
  99. data/public/images/wymeditor/skins/refinery/center.png +0 -0
  100. data/public/images/wymeditor/skins/refinery/css.png +0 -0
  101. data/public/images/wymeditor/skins/refinery/h1.png +0 -0
  102. data/public/images/wymeditor/skins/refinery/h2.png +0 -0
  103. data/public/images/wymeditor/skins/refinery/h3.png +0 -0
  104. data/public/images/wymeditor/skins/refinery/h4.png +0 -0
  105. data/public/images/wymeditor/skins/refinery/h5.png +0 -0
  106. data/public/images/wymeditor/skins/refinery/h6.png +0 -0
  107. data/public/images/wymeditor/skins/refinery/icons.png +0 -0
  108. data/public/images/wymeditor/skins/refinery/iframe/lbl-blockquote.png +0 -0
  109. data/public/images/wymeditor/skins/refinery/iframe/lbl-h1.png +0 -0
  110. data/public/images/wymeditor/skins/refinery/iframe/lbl-h2.png +0 -0
  111. data/public/images/wymeditor/skins/refinery/iframe/lbl-h3.png +0 -0
  112. data/public/images/wymeditor/skins/refinery/iframe/lbl-h4.png +0 -0
  113. data/public/images/wymeditor/skins/refinery/iframe/lbl-h5.png +0 -0
  114. data/public/images/wymeditor/skins/refinery/iframe/lbl-h6.png +0 -0
  115. data/public/images/wymeditor/skins/refinery/iframe/lbl-p.png +0 -0
  116. data/public/images/wymeditor/skins/refinery/iframe/lbl-pre.png +0 -0
  117. data/public/images/wymeditor/skins/refinery/justify.png +0 -0
  118. data/public/images/wymeditor/skins/refinery/left.png +0 -0
  119. data/public/images/wymeditor/skins/refinery/paragraph.png +0 -0
  120. data/public/images/wymeditor/skins/refinery/right.png +0 -0
  121. data/public/images/wymeditor/skins/wymeditor_icon.png +0 -0
  122. data/public/javascripts/admin.js +5 -0
  123. data/public/javascripts/application.js +1 -0
  124. data/public/javascripts/jquery/GPL-LICENSE.txt +278 -0
  125. data/public/javascripts/jquery/MIT-LICENSE.txt +20 -0
  126. data/public/javascripts/jquery-ui-1.8rc1.min.js +375 -0
  127. data/public/javascripts/jquery.js +6078 -0
  128. data/public/javascripts/refinery/admin.js +705 -0
  129. data/public/javascripts/refinery/boot_wym.js +154 -0
  130. data/public/javascripts/thickbox.js +350 -0
  131. data/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +4975 -0
  132. data/public/javascripts/wymeditor/lang/ca.js +45 -0
  133. data/public/javascripts/wymeditor/lang/cs.js +45 -0
  134. data/public/javascripts/wymeditor/lang/de.js +45 -0
  135. data/public/javascripts/wymeditor/lang/en.js +48 -0
  136. data/public/javascripts/wymeditor/lang/es.js +45 -0
  137. data/public/javascripts/wymeditor/lang/fa.js +46 -0
  138. data/public/javascripts/wymeditor/lang/fr.js +45 -0
  139. data/public/javascripts/wymeditor/lang/he.js +45 -0
  140. data/public/javascripts/wymeditor/lang/hu.js +45 -0
  141. data/public/javascripts/wymeditor/lang/it.js +45 -0
  142. data/public/javascripts/wymeditor/lang/nb.js +45 -0
  143. data/public/javascripts/wymeditor/lang/nl.js +45 -0
  144. data/public/javascripts/wymeditor/lang/nn.js +45 -0
  145. data/public/javascripts/wymeditor/lang/pl.js +45 -0
  146. data/public/javascripts/wymeditor/lang/pt-br.js +45 -0
  147. data/public/javascripts/wymeditor/lang/pt.js +45 -0
  148. data/public/javascripts/wymeditor/lang/ru.js +45 -0
  149. data/public/javascripts/wymeditor/lang/sv.js +45 -0
  150. data/public/javascripts/wymeditor/lang/tr.js +45 -0
  151. data/public/javascripts/wymeditor/lang/zh_cn.js +47 -0
  152. data/public/javascripts/wymeditor/skins/refinery/skin.js +40 -0
  153. data/public/robots.txt +2 -0
  154. data/public/stylesheets/application.css +5 -0
  155. data/public/stylesheets/formatting.css +5 -0
  156. data/public/stylesheets/home.css +5 -0
  157. data/public/stylesheets/ie6.css +0 -0
  158. data/public/stylesheets/ie7.css +0 -0
  159. data/public/stylesheets/refinery/application.css +45 -0
  160. data/public/stylesheets/refinery/formatting.css +53 -0
  161. data/public/stylesheets/refinery/home.css +0 -0
  162. data/public/stylesheets/refinery/refinery.css +1233 -0
  163. data/public/stylesheets/refinery/theme.css +36 -0
  164. data/public/stylesheets/refinery/thickbox.css +165 -0
  165. data/public/stylesheets/refinery/tooltips.css +38 -0
  166. data/public/stylesheets/theme.css +1 -0
  167. data/public/stylesheets/wymeditor/skins/refinery/skin.css +218 -0
  168. data/public/stylesheets/wymeditor/skins/refinery/wymiframe.css +92 -0
  169. data/public/wymeditor/GPL-license.txt +278 -0
  170. data/public/wymeditor/MIT-license.txt +20 -0
  171. data/public/wymeditor/README +35 -0
  172. data/readme.md +181 -0
  173. data/script/about +3 -0
  174. data/script/console +3 -0
  175. data/script/dbconsole +3 -0
  176. data/script/destroy +3 -0
  177. data/script/generate +3 -0
  178. data/script/performance/benchmarker +3 -0
  179. data/script/performance/profiler +3 -0
  180. data/script/performance/request +3 -0
  181. data/script/plugin +3 -0
  182. data/script/process/inspector +3 -0
  183. data/script/process/reaper +3 -0
  184. data/script/process/spawner +3 -0
  185. data/script/runner +3 -0
  186. data/script/server +3 -0
  187. data/test/files/The world!.gif +0 -0
  188. data/test/files/car-wallpapers19.jpg +0 -0
  189. data/test/files/teng.pdf +0 -0
  190. data/test/fixtures/images.yml +14 -0
  191. data/test/fixtures/inquiries.yml +22 -0
  192. data/test/fixtures/news_items.yml +14 -0
  193. data/test/fixtures/page_parts.yml +9 -0
  194. data/test/fixtures/pages.yml +94 -0
  195. data/test/fixtures/refinery_settings.yml +3 -0
  196. data/test/fixtures/resources.yml +4 -0
  197. data/test/fixtures/users.yml +16 -0
  198. data/test/functional/dashboard_controller_test.rb +24 -0
  199. data/test/performance/browsing_test.rb +9 -0
  200. data/test/test_helper.rb +43 -0
  201. data/test/unit/image_test.rb +27 -0
  202. data/test/unit/inquiry_test.rb +41 -0
  203. data/test/unit/news_items_test.rb +33 -0
  204. data/test/unit/page_part_test.rb +19 -0
  205. data/test/unit/page_test.rb +133 -0
  206. data/test/unit/refinery_setting_test.rb +57 -0
  207. data/test/unit/resource_test.rb +33 -0
  208. data/themes/demolicious/LICENSE +21 -0
  209. data/themes/demolicious/README +1 -0
  210. data/themes/demolicious/images/footer_background.png +0 -0
  211. data/themes/demolicious/images/header_background.png +0 -0
  212. data/themes/demolicious/stylesheets/application.css +94 -0
  213. data/themes/demolicious/stylesheets/formatting.css +36 -0
  214. data/themes/demolicious/stylesheets/home.css +8 -0
  215. data/themes/demolicious/stylesheets/ie6.css +0 -0
  216. data/themes/demolicious/stylesheets/ie7.css +0 -0
  217. data/themes/demolicious/views/layouts/application.html.erb +20 -0
  218. data/themes/demolicious/views/pages/home.html.erb +1 -0
  219. data/themes/demolicious/views/pages/show.html.erb +1 -0
  220. data/themes/hemingway/LICENSE +7 -0
  221. data/themes/hemingway/README +3 -0
  222. data/themes/hemingway/images/archives.gif +0 -0
  223. data/themes/hemingway/images/footer_black.gif +0 -0
  224. data/themes/hemingway/images/kyle-header.jpg +0 -0
  225. data/themes/hemingway/images/readon_black.gif +0 -0
  226. data/themes/hemingway/images/search.gif +0 -0
  227. data/themes/hemingway/images/spinner.gif +0 -0
  228. data/themes/hemingway/images/trackback_pingback.gif +0 -0
  229. data/themes/hemingway/stylesheets/application.css +713 -0
  230. data/themes/hemingway/stylesheets/formatting.css +1 -0
  231. data/themes/hemingway/stylesheets/home.css +1 -0
  232. data/themes/hemingway/views/layouts/application.html.erb +55 -0
  233. data/todo.md +23 -0
  234. data/vendor/cache/aasm-2.1.3.gem +0 -0
  235. data/vendor/cache/actionmailer-2.3.5.gem +0 -0
  236. data/vendor/cache/actionpack-2.3.5.gem +0 -0
  237. data/vendor/cache/activerecord-2.3.5.gem +0 -0
  238. data/vendor/cache/activeresource-2.3.5.gem +0 -0
  239. data/vendor/cache/activesupport-2.3.5.gem +0 -0
  240. data/vendor/cache/friendly_id-2.3.1.gem +0 -0
  241. data/vendor/cache/hpricot-0.8.2.gem +0 -0
  242. data/vendor/cache/rack-1.0.1.gem +0 -0
  243. data/vendor/cache/rails-2.3.5.gem +0 -0
  244. data/vendor/cache/rake-0.8.7.gem +0 -0
  245. data/vendor/cache/rubyzip-0.9.1.gem +0 -0
  246. data/vendor/cache/slim_scrooge-1.0.3.gem +0 -0
  247. data/vendor/cache/will_paginate-2.3.11.gem +0 -0
  248. data/vendor/plugins/acts_as_indexed/CHANGELOG +74 -0
  249. data/vendor/plugins/acts_as_indexed/MIT-LICENSE +20 -0
  250. data/vendor/plugins/acts_as_indexed/README.rdoc +114 -0
  251. data/vendor/plugins/acts_as_indexed/Rakefile +35 -0
  252. data/vendor/plugins/acts_as_indexed/init.rb +2 -0
  253. data/vendor/plugins/acts_as_indexed/lib/acts_as_indexed.rb +224 -0
  254. data/vendor/plugins/acts_as_indexed/lib/search_atom.rb +107 -0
  255. data/vendor/plugins/acts_as_indexed/lib/search_index.rb +329 -0
  256. data/vendor/plugins/acts_as_indexed/lib/will_paginate_search.rb +29 -0
  257. data/vendor/plugins/acts_as_indexed/test/abstract_unit.rb +47 -0
  258. data/vendor/plugins/acts_as_indexed/test/acts_as_indexed_test.rb +102 -0
  259. data/vendor/plugins/acts_as_indexed/test/database.yml +10 -0
  260. data/vendor/plugins/acts_as_indexed/test/fixtures/post.rb +5 -0
  261. data/vendor/plugins/acts_as_indexed/test/fixtures/posts.yml +31 -0
  262. data/vendor/plugins/acts_as_indexed/test/schema.rb +6 -0
  263. data/vendor/plugins/acts_as_tree/README +26 -0
  264. data/vendor/plugins/acts_as_tree/Rakefile +22 -0
  265. data/vendor/plugins/acts_as_tree/init.rb +1 -0
  266. data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +141 -0
  267. data/vendor/plugins/acts_as_tree/test/abstract_unit.rb +0 -0
  268. data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
  269. data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
  270. data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
  271. data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
  272. data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
  273. data/vendor/plugins/attachment_fu/CHANGELOG +35 -0
  274. data/vendor/plugins/attachment_fu/LICENSE +20 -0
  275. data/vendor/plugins/attachment_fu/README +193 -0
  276. data/vendor/plugins/attachment_fu/Rakefile +22 -0
  277. data/vendor/plugins/attachment_fu/amazon_s3.yml.tpl +17 -0
  278. data/vendor/plugins/attachment_fu/init.rb +16 -0
  279. data/vendor/plugins/attachment_fu/install.rb +7 -0
  280. data/vendor/plugins/attachment_fu/lib/geometry.rb +93 -0
  281. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb +211 -0
  282. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb +39 -0
  283. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +126 -0
  284. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb +394 -0
  285. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/core_image_processor.rb +59 -0
  286. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/gd2_processor.rb +54 -0
  287. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +61 -0
  288. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +132 -0
  289. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +57 -0
  290. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb +514 -0
  291. data/vendor/plugins/attachment_fu/rackspace_cloudfiles.yml.tpl +14 -0
  292. data/vendor/plugins/attachment_fu/test/backends/db_file_test.rb +16 -0
  293. data/vendor/plugins/attachment_fu/test/backends/file_system_test.rb +143 -0
  294. data/vendor/plugins/attachment_fu/test/backends/remote/cloudfiles_test.rb +102 -0
  295. data/vendor/plugins/attachment_fu/test/backends/remote/s3_test.rb +119 -0
  296. data/vendor/plugins/attachment_fu/test/base_attachment_tests.rb +77 -0
  297. data/vendor/plugins/attachment_fu/test/basic_test.rb +70 -0
  298. data/vendor/plugins/attachment_fu/test/database.yml +18 -0
  299. data/vendor/plugins/attachment_fu/test/extra_attachment_test.rb +67 -0
  300. data/vendor/plugins/attachment_fu/test/fixtures/attachment.rb +226 -0
  301. data/vendor/plugins/attachment_fu/test/fixtures/files/fake/rails.png +0 -0
  302. data/vendor/plugins/attachment_fu/test/fixtures/files/foo.txt +1 -0
  303. data/vendor/plugins/attachment_fu/test/fixtures/files/rails.png +0 -0
  304. data/vendor/plugins/attachment_fu/test/geometry_test.rb +108 -0
  305. data/vendor/plugins/attachment_fu/test/processors/core_image_test.rb +37 -0
  306. data/vendor/plugins/attachment_fu/test/processors/gd2_test.rb +31 -0
  307. data/vendor/plugins/attachment_fu/test/processors/image_science_test.rb +31 -0
  308. data/vendor/plugins/attachment_fu/test/processors/mini_magick_test.rb +103 -0
  309. data/vendor/plugins/attachment_fu/test/processors/rmagick_test.rb +255 -0
  310. data/vendor/plugins/attachment_fu/test/schema.rb +134 -0
  311. data/vendor/plugins/attachment_fu/test/test_helper.rb +150 -0
  312. data/vendor/plugins/attachment_fu/test/validation_test.rb +55 -0
  313. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/color.rb +27 -0
  314. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/effects.rb +31 -0
  315. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/perspective.rb +25 -0
  316. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/quality.rb +25 -0
  317. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/scale.rb +47 -0
  318. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/watermark.rb +32 -0
  319. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/processor.rb +123 -0
  320. data/vendor/plugins/authentication/README +0 -0
  321. data/vendor/plugins/authentication/Rakefile +0 -0
  322. data/vendor/plugins/authentication/app/controllers/admin/users_controller.rb +67 -0
  323. data/vendor/plugins/authentication/app/controllers/sessions_controller.rb +36 -0
  324. data/vendor/plugins/authentication/app/controllers/users_controller.rb +101 -0
  325. data/vendor/plugins/authentication/app/helpers/sessions_helper.rb +2 -0
  326. data/vendor/plugins/authentication/app/helpers/users_helper.rb +2 -0
  327. data/vendor/plugins/authentication/app/models/user.rb +154 -0
  328. data/vendor/plugins/authentication/app/models/user_mailer.rb +18 -0
  329. data/vendor/plugins/authentication/app/models/user_plugin.rb +5 -0
  330. data/vendor/plugins/authentication/app/views/admin/users/_form.html.erb +38 -0
  331. data/vendor/plugins/authentication/app/views/admin/users/edit.html.erb +1 -0
  332. data/vendor/plugins/authentication/app/views/admin/users/index.html.erb +40 -0
  333. data/vendor/plugins/authentication/app/views/admin/users/new.html.erb +1 -0
  334. data/vendor/plugins/authentication/app/views/sessions/new.html.erb +24 -0
  335. data/vendor/plugins/authentication/app/views/user_mailer/reset_notification.html.erb +6 -0
  336. data/vendor/plugins/authentication/app/views/users/forgot.html.erb +13 -0
  337. data/vendor/plugins/authentication/app/views/users/new.html.erb +28 -0
  338. data/vendor/plugins/authentication/app/views/users/reset.html.erb +18 -0
  339. data/vendor/plugins/authentication/authentication.md +15 -0
  340. data/vendor/plugins/authentication/config/routes.rb +15 -0
  341. data/vendor/plugins/authentication/lib/authenticated_system.rb +115 -0
  342. data/vendor/plugins/authentication/lib/authenticated_test_helper.rb +10 -0
  343. data/vendor/plugins/authentication/rails/init.rb +13 -0
  344. data/vendor/plugins/authentication/test/fixtures/users.yml +19 -0
  345. data/vendor/plugins/authentication/test/functional/admin/base_controller_test.rb +8 -0
  346. data/vendor/plugins/authentication/test/functional/admin/dashboard_controller_test.rb +8 -0
  347. data/vendor/plugins/authentication/test/functional/admin/pages_controller_test.rb +8 -0
  348. data/vendor/plugins/authentication/test/functional/sessions_controller_test.rb +85 -0
  349. data/vendor/plugins/authentication/test/functional/users_controller_test.rb +99 -0
  350. data/vendor/plugins/authentication/test/test_helper.rb +38 -0
  351. data/vendor/plugins/authentication/test/unit/user_mailer_test.rb +31 -0
  352. data/vendor/plugins/authentication/test/unit/user_test.rb +164 -0
  353. data/vendor/plugins/dashboard/app/controllers/admin/dashboard_controller.rb +28 -0
  354. data/vendor/plugins/dashboard/app/helpers/admin/dashboard_helper.rb +19 -0
  355. data/vendor/plugins/dashboard/app/views/admin/dashboard/_recent_activity.html.erb +14 -0
  356. data/vendor/plugins/dashboard/app/views/admin/dashboard/index.html.erb +31 -0
  357. data/vendor/plugins/dashboard/config/routes.rb +5 -0
  358. data/vendor/plugins/dashboard/dashboard.md +22 -0
  359. data/vendor/plugins/dashboard/rails/init.rb +6 -0
  360. data/vendor/plugins/images/app/controllers/admin/images_controller.rb +98 -0
  361. data/vendor/plugins/images/app/helpers/admin/images_helper.rb +23 -0
  362. data/vendor/plugins/images/app/models/image.rb +57 -0
  363. data/vendor/plugins/images/app/views/admin/images/_form.html.erb +31 -0
  364. data/vendor/plugins/images/app/views/admin/images/_grid_view.html.erb +16 -0
  365. data/vendor/plugins/images/app/views/admin/images/_list_view.html.erb +12 -0
  366. data/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb +16 -0
  367. data/vendor/plugins/images/app/views/admin/images/edit.html.erb +1 -0
  368. data/vendor/plugins/images/app/views/admin/images/index.html.erb +42 -0
  369. data/vendor/plugins/images/app/views/admin/images/insert.html.erb +50 -0
  370. data/vendor/plugins/images/app/views/admin/images/new.html.erb +1 -0
  371. data/vendor/plugins/images/config/routes.rb +5 -0
  372. data/vendor/plugins/images/images.md +53 -0
  373. data/vendor/plugins/images/lib/tasks/images.rake +45 -0
  374. data/vendor/plugins/images/rails/init.rb +14 -0
  375. data/vendor/plugins/inquiries/app/controllers/admin/inquiries_controller.rb +29 -0
  376. data/vendor/plugins/inquiries/app/controllers/admin/inquiry_settings_controller.rb +16 -0
  377. data/vendor/plugins/inquiries/app/controllers/inquiries_controller.rb +41 -0
  378. data/vendor/plugins/inquiries/app/helpers/inquiries_helper.rb +13 -0
  379. data/vendor/plugins/inquiries/app/models/inquiry.rb +16 -0
  380. data/vendor/plugins/inquiries/app/models/inquiry_mailer.rb +20 -0
  381. data/vendor/plugins/inquiries/app/models/inquiry_setting.rb +11 -0
  382. data/vendor/plugins/inquiries/app/views/admin/inquiries/_inquiry.html.erb +20 -0
  383. data/vendor/plugins/inquiries/app/views/admin/inquiries/index.html.erb +43 -0
  384. data/vendor/plugins/inquiries/app/views/admin/inquiries/show.html.erb +62 -0
  385. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/_confirmation_email_form.html.erb +46 -0
  386. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/_notification_recipients_form.html.erb +18 -0
  387. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/edit.html.erb +5 -0
  388. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/index.html.erb +31 -0
  389. data/vendor/plugins/inquiries/app/views/inquiries/new.html.erb +31 -0
  390. data/vendor/plugins/inquiries/app/views/inquiries/thank_you.html.erb +1 -0
  391. data/vendor/plugins/inquiries/app/views/inquiry_mailer/confirmation.html.erb +1 -0
  392. data/vendor/plugins/inquiries/app/views/inquiry_mailer/notification.html.erb +18 -0
  393. data/vendor/plugins/inquiries/config/routes.rb +8 -0
  394. data/vendor/plugins/inquiries/inquiries.md +31 -0
  395. data/vendor/plugins/inquiries/rails/init.rb +13 -0
  396. data/vendor/plugins/news/app/controllers/admin/news_items_controller.rb +5 -0
  397. data/vendor/plugins/news/app/controllers/news_items_controller.rb +20 -0
  398. data/vendor/plugins/news/app/models/news_item.rb +22 -0
  399. data/vendor/plugins/news/app/views/admin/news_items/_form.html.erb +19 -0
  400. data/vendor/plugins/news/app/views/admin/news_items/_news_item.html.erb +15 -0
  401. data/vendor/plugins/news/app/views/admin/news_items/edit.html.erb +1 -0
  402. data/vendor/plugins/news/app/views/admin/news_items/index.html.erb +31 -0
  403. data/vendor/plugins/news/app/views/admin/news_items/new.html.erb +1 -0
  404. data/vendor/plugins/news/app/views/news_items/_recent_posts.html.erb +8 -0
  405. data/vendor/plugins/news/app/views/news_items/index.html.erb +17 -0
  406. data/vendor/plugins/news/app/views/news_items/index.rss.builder +26 -0
  407. data/vendor/plugins/news/app/views/news_items/show.html.erb +13 -0
  408. data/vendor/plugins/news/config/routes.rb +7 -0
  409. data/vendor/plugins/news/news.md +20 -0
  410. data/vendor/plugins/news/rails/init.rb +11 -0
  411. data/vendor/plugins/pages/app/controllers/admin/page_dialogs_controller.rb +49 -0
  412. data/vendor/plugins/pages/app/controllers/admin/page_parts_controller.rb +20 -0
  413. data/vendor/plugins/pages/app/controllers/admin/pages_controller.rb +18 -0
  414. data/vendor/plugins/pages/app/controllers/pages_controller.rb +22 -0
  415. data/vendor/plugins/pages/app/helpers/pages_helper.rb +2 -0
  416. data/vendor/plugins/pages/app/models/page.rb +162 -0
  417. data/vendor/plugins/pages/app/models/page_part.rb +10 -0
  418. data/vendor/plugins/pages/app/presenters/page_presenter.rb +3 -0
  419. data/vendor/plugins/pages/app/views/admin/page_dialogs/_page_link.html.erb +5 -0
  420. data/vendor/plugins/pages/app/views/admin/page_dialogs/link_to.html.erb +149 -0
  421. data/vendor/plugins/pages/app/views/admin/pages/_form.html.erb +140 -0
  422. data/vendor/plugins/pages/app/views/admin/pages/_list.html.erb +29 -0
  423. data/vendor/plugins/pages/app/views/admin/pages/_page_part_field.html.erb +4 -0
  424. data/vendor/plugins/pages/app/views/admin/pages/_sortable_list.html.erb +4 -0
  425. data/vendor/plugins/pages/app/views/admin/pages/edit.html.erb +1 -0
  426. data/vendor/plugins/pages/app/views/admin/pages/index.html.erb +41 -0
  427. data/vendor/plugins/pages/app/views/admin/pages/new.html.erb +1 -0
  428. data/vendor/plugins/pages/app/views/pages/home.html.erb +1 -0
  429. data/vendor/plugins/pages/app/views/pages/show.html.erb +1 -0
  430. data/vendor/plugins/pages/config/routes.rb +11 -0
  431. data/vendor/plugins/pages/pages.md +146 -0
  432. data/vendor/plugins/pages/rails/init.rb +13 -0
  433. data/vendor/plugins/rails_indexes/MIT-LICENSE +20 -0
  434. data/vendor/plugins/rails_indexes/README.textile +46 -0
  435. data/vendor/plugins/rails_indexes/Rakefile +23 -0
  436. data/vendor/plugins/rails_indexes/lib/indexer.rb +305 -0
  437. data/vendor/plugins/rails_indexes/tasks/indexer.rake +18 -0
  438. data/vendor/plugins/rails_indexes/test/fixtures/app/controllers/users_controller.rb +8 -0
  439. data/vendor/plugins/rails_indexes/test/fixtures/app/models/address.rb +5 -0
  440. data/vendor/plugins/rails_indexes/test/fixtures/app/models/company.rb +11 -0
  441. data/vendor/plugins/rails_indexes/test/fixtures/app/models/country.rb +4 -0
  442. data/vendor/plugins/rails_indexes/test/fixtures/app/models/freelancer.rb +3 -0
  443. data/vendor/plugins/rails_indexes/test/fixtures/app/models/gift.rb +10 -0
  444. data/vendor/plugins/rails_indexes/test/fixtures/app/models/god.rb +3 -0
  445. data/vendor/plugins/rails_indexes/test/fixtures/app/models/user.rb +17 -0
  446. data/vendor/plugins/rails_indexes/test/fixtures/app/sweepers/user_sweeper.rb +9 -0
  447. data/vendor/plugins/rails_indexes/test/fixtures/schema.rb +46 -0
  448. data/vendor/plugins/rails_indexes/test/rails_indexes_test.rb +83 -0
  449. data/vendor/plugins/rails_indexes/test/test_helper.rb +30 -0
  450. data/vendor/plugins/refinery/app/controllers/admin/refinery_core_controller.rb +14 -0
  451. data/vendor/plugins/refinery/app/views/admin/_head.html.erb +11 -0
  452. data/vendor/plugins/refinery/app/views/admin/_menu.html.erb +23 -0
  453. data/vendor/plugins/refinery/app/views/layouts/admin.html.erb +34 -0
  454. data/vendor/plugins/refinery/app/views/layouts/application.html.erb +20 -0
  455. data/vendor/plugins/refinery/app/views/shared/_content_page.html.erb +36 -0
  456. data/vendor/plugins/refinery/app/views/shared/_footer.html.erb +5 -0
  457. data/vendor/plugins/refinery/app/views/shared/_google_analytics.html.erb +13 -0
  458. data/vendor/plugins/refinery/app/views/shared/_head.html.erb +16 -0
  459. data/vendor/plugins/refinery/app/views/shared/_header.html.erb +4 -0
  460. data/vendor/plugins/refinery/app/views/shared/_ie6check.html.erb +11 -0
  461. data/vendor/plugins/refinery/app/views/shared/_menu.html.erb +8 -0
  462. data/vendor/plugins/refinery/app/views/shared/_menu_branch.html.erb +23 -0
  463. data/vendor/plugins/refinery/app/views/shared/_message.html.erb +5 -0
  464. data/vendor/plugins/refinery/app/views/shared/_submenu.html.erb +5 -0
  465. data/vendor/plugins/refinery/app/views/shared/_submenu_branch.html.erb +10 -0
  466. data/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb +4 -0
  467. data/vendor/plugins/refinery/app/views/shared/admin/_error_messages_for.html.erb +2 -0
  468. data/vendor/plugins/refinery/app/views/shared/admin/_form_actions.html.erb +13 -0
  469. data/vendor/plugins/refinery/app/views/shared/admin/_head_before_javascript_libraries.html.erb +0 -0
  470. data/vendor/plugins/refinery/app/views/shared/admin/_image_picker.html.erb +48 -0
  471. data/vendor/plugins/refinery/app/views/shared/admin/_make_sortable.html.erb +10 -0
  472. data/vendor/plugins/refinery/app/views/shared/admin/_resource_picker.html.erb +57 -0
  473. data/vendor/plugins/refinery/app/views/shared/admin/_search.html.erb +5 -0
  474. data/vendor/plugins/refinery/app/views/shared/admin/_sortable_list.html.erb +9 -0
  475. data/vendor/plugins/refinery/app/views/welcome.html.erb +13 -0
  476. data/vendor/plugins/refinery/app/views/wymiframe.html.erb +8 -0
  477. data/vendor/plugins/refinery/config/routes.rb +10 -0
  478. data/vendor/plugins/refinery/crud.md +197 -0
  479. data/vendor/plugins/refinery/lib/crud.rb +222 -0
  480. data/vendor/plugins/refinery/lib/generators/refinery/README +29 -0
  481. data/vendor/plugins/refinery/lib/generators/refinery/Rakefile +12 -0
  482. data/vendor/plugins/refinery/lib/generators/refinery/USAGE +2 -0
  483. data/vendor/plugins/refinery/lib/generators/refinery/install.rb +2 -0
  484. data/vendor/plugins/refinery/lib/generators/refinery/refinery_generator.rb +65 -0
  485. data/vendor/plugins/refinery/lib/generators/refinery/templates/config/routes.rb +7 -0
  486. data/vendor/plugins/refinery/lib/generators/refinery/templates/controller.rb +5 -0
  487. data/vendor/plugins/refinery/lib/generators/refinery/templates/migration.rb +44 -0
  488. data/vendor/plugins/refinery/lib/generators/refinery/templates/model.rb +9 -0
  489. data/vendor/plugins/refinery/lib/generators/refinery/templates/public_controller.rb +30 -0
  490. data/vendor/plugins/refinery/lib/generators/refinery/templates/rails/init.rb +10 -0
  491. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_form.html.erb +14 -0
  492. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_singular_name.html.erb +15 -0
  493. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_sortable_list.html.erb +2 -0
  494. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/edit.html.erb +1 -0
  495. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/index.html.erb +42 -0
  496. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/new.html.erb +1 -0
  497. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/index.html.erb +11 -0
  498. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/show.html.erb +25 -0
  499. data/vendor/plugins/refinery/lib/refinery/activity.rb +37 -0
  500. data/vendor/plugins/refinery/lib/refinery/admin_base_controller.rb +56 -0
  501. data/vendor/plugins/refinery/lib/refinery/application_controller.rb +80 -0
  502. data/vendor/plugins/refinery/lib/refinery/application_helper.rb +112 -0
  503. data/vendor/plugins/refinery/lib/refinery/attachment_fu_patch.rb +16 -0
  504. data/vendor/plugins/refinery/lib/refinery/base_presenter.rb +27 -0
  505. data/vendor/plugins/refinery/lib/refinery/form_helpers.rb +28 -0
  506. data/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb +110 -0
  507. data/vendor/plugins/refinery/lib/refinery/initializer.rb +80 -0
  508. data/vendor/plugins/refinery/lib/refinery/link_renderer.rb +45 -0
  509. data/vendor/plugins/refinery/lib/refinery/plugin.rb +47 -0
  510. data/vendor/plugins/refinery/lib/refinery/plugins.rb +53 -0
  511. data/vendor/plugins/refinery/lib/refinery.rb +11 -0
  512. data/vendor/plugins/refinery/lib/tasks/doc.rake +29 -0
  513. data/vendor/plugins/refinery/lib/tasks/refinery.rake +34 -0
  514. data/vendor/plugins/refinery/lib/tasks/yard.rake +32 -0
  515. data/vendor/plugins/refinery/plugins.md +205 -0
  516. data/vendor/plugins/refinery/rails/init.rb +14 -0
  517. data/vendor/plugins/refinery_dialogs/app/controllers/admin/dialogs_controller.rb +26 -0
  518. data/vendor/plugins/refinery_dialogs/app/views/admin/dialogs/show.html.erb +20 -0
  519. data/vendor/plugins/refinery_dialogs/app/views/layouts/admin_dialog.html.erb +24 -0
  520. data/vendor/plugins/refinery_dialogs/config/routes.rb +5 -0
  521. data/vendor/plugins/refinery_dialogs/rails/init.rb +7 -0
  522. data/vendor/plugins/refinery_settings/app/controllers/admin/refinery_settings_controller.rb +5 -0
  523. data/vendor/plugins/refinery_settings/app/models/refinery_setting.rb +88 -0
  524. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_form.html.erb +17 -0
  525. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_refinery_setting.html.erb +12 -0
  526. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/edit.html.erb +4 -0
  527. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/index.html.erb +27 -0
  528. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/new.html.erb +1 -0
  529. data/vendor/plugins/refinery_settings/config/routes.rb +5 -0
  530. data/vendor/plugins/refinery_settings/rails/init.rb +13 -0
  531. data/vendor/plugins/refinery_settings/settings.md +55 -0
  532. data/vendor/plugins/resources/app/controllers/admin/resources_controller.rb +94 -0
  533. data/vendor/plugins/resources/app/models/resource.rb +55 -0
  534. data/vendor/plugins/resources/app/views/admin/resources/_form.html.erb +33 -0
  535. data/vendor/plugins/resources/app/views/admin/resources/_resource.html.erb +14 -0
  536. data/vendor/plugins/resources/app/views/admin/resources/edit.html.erb +1 -0
  537. data/vendor/plugins/resources/app/views/admin/resources/index.html.erb +41 -0
  538. data/vendor/plugins/resources/app/views/admin/resources/insert.html.erb +67 -0
  539. data/vendor/plugins/resources/app/views/admin/resources/new.html.erb +1 -0
  540. data/vendor/plugins/resources/config/routes.rb +9 -0
  541. data/vendor/plugins/resources/rails/init.rb +12 -0
  542. data/vendor/plugins/resources/resources.md +9 -0
  543. data/vendor/plugins/themes/app/helpers/themes_helper.rb +25 -0
  544. data/vendor/plugins/themes/lib/theme_server.rb +30 -0
  545. data/vendor/plugins/themes/rails/init.rb +24 -0
  546. data/vendor/plugins/themes/themes.md +113 -0
  547. metadata +625 -0
@@ -0,0 +1,59 @@
1
+ require 'red_artisan/core_image/processor'
2
+
3
+ module Technoweenie # :nodoc:
4
+ module AttachmentFu # :nodoc:
5
+ module Processors
6
+ module CoreImageProcessor
7
+ def self.included(base)
8
+ base.send :extend, ClassMethods
9
+ base.alias_method_chain :process_attachment, :processing
10
+ end
11
+
12
+ module ClassMethods
13
+ def with_image(file, &block)
14
+ block.call OSX::CIImage.from(file)
15
+ end
16
+ end
17
+
18
+ protected
19
+ def process_attachment_with_processing
20
+ return unless process_attachment_without_processing
21
+ with_image do |img|
22
+ self.width = img.extent.size.width if respond_to?(:width)
23
+ self.height = img.extent.size.height if respond_to?(:height)
24
+ resize_image_or_thumbnail! img
25
+ callback_with_args :after_resize, img
26
+ end if image?
27
+ end
28
+
29
+ # Performs the actual resizing operation for a thumbnail
30
+ def resize_image(img, size)
31
+ processor = ::RedArtisan::CoreImage::Processor.new(img)
32
+ size = size.first if size.is_a?(Array) && size.length == 1
33
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
34
+ if size.is_a?(Fixnum)
35
+ processor.fit(size)
36
+ else
37
+ processor.resize(size[0], size[1])
38
+ end
39
+ else
40
+ new_size = [img.extent.size.width, img.extent.size.height] / size.to_s
41
+ processor.resize(new_size[0], new_size[1])
42
+ end
43
+
44
+ processor.render do |result|
45
+ self.width = result.extent.size.width if respond_to?(:width)
46
+ self.height = result.extent.size.height if respond_to?(:height)
47
+
48
+ # Get a new temp_path for the image before saving
49
+ temp_paths.unshift Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
50
+ result.save self.temp_path, OSX::NSJPEGFileType
51
+ self.size = File.size(self.temp_path)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'gd2'
3
+ module Technoweenie # :nodoc:
4
+ module AttachmentFu # :nodoc:
5
+ module Processors
6
+ module Gd2Processor
7
+ def self.included(base)
8
+ base.send :extend, ClassMethods
9
+ base.alias_method_chain :process_attachment, :processing
10
+ end
11
+
12
+ module ClassMethods
13
+ # Yields a block containing a GD2 Image for the given binary data.
14
+ def with_image(file, &block)
15
+ im = GD2::Image.import(file)
16
+ block.call(im)
17
+ end
18
+ end
19
+
20
+ protected
21
+ def process_attachment_with_processing
22
+ return unless process_attachment_without_processing && image?
23
+ with_image do |img|
24
+ resize_image_or_thumbnail! img
25
+ self.width = img.width
26
+ self.height = img.height
27
+ callback_with_args :after_resize, img
28
+ end
29
+ end
30
+
31
+ # Performs the actual resizing operation for a thumbnail
32
+ def resize_image(img, size)
33
+ size = size.first if size.is_a?(Array) && size.length == 1
34
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
35
+ if size.is_a?(Fixnum)
36
+ # Borrowed from image science's #thumbnail method and adapted
37
+ # for this.
38
+ scale = size.to_f / (img.width > img.height ? img.width.to_f : img.height.to_f)
39
+ img.resize!((img.width * scale).round(1), (img.height * scale).round(1), false)
40
+ else
41
+ img.resize!(size.first, size.last, false)
42
+ end
43
+ else
44
+ w, h = [img.width, img.height] / size.to_s
45
+ img.resize!(w, h, false)
46
+ end
47
+ temp_paths.unshift random_tempfile_filename
48
+ self.size = img.export(self.temp_path)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,61 @@
1
+ require 'image_science'
2
+ module Technoweenie # :nodoc:
3
+ module AttachmentFu # :nodoc:
4
+ module Processors
5
+ module ImageScienceProcessor
6
+ def self.included(base)
7
+ base.send :extend, ClassMethods
8
+ base.alias_method_chain :process_attachment, :processing
9
+ end
10
+
11
+ module ClassMethods
12
+ # Yields a block containing an Image Science image for the given binary data.
13
+ def with_image(file, &block)
14
+ ::ImageScience.with_image file, &block
15
+ end
16
+ end
17
+
18
+ protected
19
+ def process_attachment_with_processing
20
+ return unless process_attachment_without_processing && image?
21
+ with_image do |img|
22
+ self.width = img.width if respond_to?(:width)
23
+ self.height = img.height if respond_to?(:height)
24
+ resize_image_or_thumbnail! img
25
+ end
26
+ end
27
+
28
+ # Performs the actual resizing operation for a thumbnail
29
+ def resize_image(img, size)
30
+ # create a dummy temp file to write to
31
+ # ImageScience doesn't handle all gifs properly, so it converts them to
32
+ # pngs for thumbnails. It has something to do with trying to save gifs
33
+ # with a larger palette than 256 colors, which is all the gif format
34
+ # supports.
35
+ filename.sub! /gif$/, 'png'
36
+ content_type.sub!(/gif$/, 'png')
37
+ temp_paths.unshift write_to_temp_file(filename)
38
+ grab_dimensions = lambda do |img|
39
+ self.width = img.width if respond_to?(:width)
40
+ self.height = img.height if respond_to?(:height)
41
+ img.save self.temp_path
42
+ self.size = File.size(self.temp_path)
43
+ callback_with_args :after_resize, img
44
+ end
45
+
46
+ size = size.first if size.is_a?(Array) && size.length == 1
47
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
48
+ if size.is_a?(Fixnum)
49
+ img.thumbnail(size, &grab_dimensions)
50
+ else
51
+ img.resize(size[0], size[1], &grab_dimensions)
52
+ end
53
+ else
54
+ new_size = [img.width, img.height] / size.to_s
55
+ img.resize(new_size[0], new_size[1], &grab_dimensions)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,132 @@
1
+ require 'mini_magick'
2
+ module Technoweenie # :nodoc:
3
+ module AttachmentFu # :nodoc:
4
+ module Processors
5
+ module MiniMagickProcessor
6
+ def self.included(base)
7
+ base.send :extend, ClassMethods
8
+ base.alias_method_chain :process_attachment, :processing
9
+ end
10
+
11
+ module ClassMethods
12
+ # Yields a block containing an MiniMagick Image for the given binary data.
13
+ def with_image(file, &block)
14
+ begin
15
+ binary_data = file.is_a?(MiniMagick::Image) ? file : MiniMagick::Image.from_file(file) unless !Object.const_defined?(:MiniMagick)
16
+ rescue
17
+ # Log the failure to load the image.
18
+ logger.debug("Exception working with image: #{$!}")
19
+ binary_data = nil
20
+ end
21
+ block.call binary_data if block && binary_data
22
+ ensure
23
+ !binary_data.nil?
24
+ end
25
+ end
26
+
27
+ protected
28
+ def process_attachment_with_processing
29
+ return unless process_attachment_without_processing
30
+ with_image do |img|
31
+ resize_image_or_thumbnail! img
32
+ self.width = img[:width] if respond_to?(:width)
33
+ self.height = img[:height] if respond_to?(:height)
34
+ callback_with_args :after_resize, img
35
+ end if image?
36
+ end
37
+
38
+ # Performs the actual resizing operation for a thumbnail
39
+ def resize_image(img, size)
40
+ size = size.first if size.is_a?(Array) && size.length == 1
41
+ img.combine_options do |commands|
42
+ commands.strip unless attachment_options[:keep_profile]
43
+
44
+ # gif are not handled correct, this is a hack, but it seems to work.
45
+ if img.output =~ / GIF /
46
+ img.format("png")
47
+ end
48
+
49
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
50
+ if size.is_a?(Fixnum)
51
+ size = [size, size]
52
+ commands.resize(size.join('x'))
53
+ else
54
+ commands.resize(size.join('x') + '!')
55
+ end
56
+ # extend to thumbnail size
57
+ elsif size.is_a?(String) and size =~ /e$/
58
+ size = size.gsub(/e/, '')
59
+ commands.resize(size.to_s + '>')
60
+ commands.background('#ffffff')
61
+ commands.gravity('center')
62
+ commands.extent(size)
63
+ # crop thumbnail, the smart way
64
+ elsif size.is_a?(String) and size =~ /c$/
65
+ size = size.gsub(/c/, '')
66
+
67
+ # calculate sizes and aspect ratio
68
+ thumb_width, thumb_height = size.split("x")
69
+ thumb_width = thumb_width.to_f
70
+ thumb_height = thumb_height.to_f
71
+
72
+ thumb_aspect = thumb_width.to_f / thumb_height.to_f
73
+ image_width, image_height = img[:width].to_f, img[:height].to_f
74
+ image_aspect = image_width / image_height
75
+
76
+ # only crop if image is not smaller in both dimensions
77
+ unless image_width < thumb_width and image_height < thumb_height
78
+ command = calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
79
+
80
+ # crop image
81
+ commands.extract(command)
82
+ end
83
+
84
+ # don not resize if image is not as height or width then thumbnail
85
+ if image_width < thumb_width or image_height < thumb_height
86
+ commands.background('#ffffff')
87
+ commands.gravity('center')
88
+ commands.extent(size)
89
+ # resize image
90
+ else
91
+ commands.resize("#{size.to_s}")
92
+ end
93
+ # crop end
94
+ else
95
+ commands.resize(size.to_s)
96
+ end
97
+ end
98
+ temp_paths.unshift img
99
+ end
100
+
101
+ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
102
+ # only crop if image is not smaller in both dimensions
103
+
104
+ # special cases, image smaller in one dimension then thumbsize
105
+ if image_width < thumb_width
106
+ offset = (image_height / 2) - (thumb_height / 2)
107
+ command = "#{image_width}x#{thumb_height}+0+#{offset}"
108
+ elsif image_height < thumb_height
109
+ offset = (image_width / 2) - (thumb_width / 2)
110
+ command = "#{thumb_width}x#{image_height}+#{offset}+0"
111
+
112
+ # normal thumbnail generation
113
+ # calculate height and offset y, width is fixed
114
+ elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
115
+ height = image_width / thumb_aspect
116
+ offset = (image_height / 2) - (height / 2)
117
+ command = "#{image_width}x#{height}+0+#{offset}"
118
+ # calculate width and offset x, height is fixed
119
+ else
120
+ width = image_height * thumb_aspect
121
+ offset = (image_width / 2) - (width / 2)
122
+ command = "#{width}x#{image_height}+#{offset}+0"
123
+ end
124
+ # crop image
125
+ command
126
+ end
127
+
128
+
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,57 @@
1
+ require 'RMagick'
2
+ module Technoweenie # :nodoc:
3
+ module AttachmentFu # :nodoc:
4
+ module Processors
5
+ module RmagickProcessor
6
+ def self.included(base)
7
+ base.send :extend, ClassMethods
8
+ base.alias_method_chain :process_attachment, :processing
9
+ end
10
+
11
+ module ClassMethods
12
+ # Yields a block containing an RMagick Image for the given binary data.
13
+ def with_image(file, &block)
14
+ begin
15
+ binary_data = file.is_a?(Magick::Image) ? file : Magick::Image.read(file).first unless !Object.const_defined?(:Magick)
16
+ rescue
17
+ # Log the failure to load the image. This should match ::Magick::ImageMagickError
18
+ # but that would cause acts_as_attachment to require rmagick.
19
+ logger.debug("Exception working with image: #{$!}")
20
+ binary_data = nil
21
+ end
22
+ block.call binary_data if block && binary_data
23
+ ensure
24
+ !binary_data.nil?
25
+ end
26
+ end
27
+
28
+ protected
29
+ def process_attachment_with_processing
30
+ return unless process_attachment_without_processing
31
+ with_image do |img|
32
+ resize_image_or_thumbnail! img
33
+ self.width = img.columns if respond_to?(:width)
34
+ self.height = img.rows if respond_to?(:height)
35
+ callback_with_args :after_resize, img
36
+ end if image?
37
+ end
38
+
39
+ # Performs the actual resizing operation for a thumbnail
40
+ def resize_image(img, size)
41
+ size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
42
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
43
+ size = [size, size] if size.is_a?(Fixnum)
44
+ img.thumbnail!(*size)
45
+ elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
46
+ dimensions = size[1..size.size].split("x")
47
+ img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
48
+ else
49
+ img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
50
+ end
51
+ img.strip! unless attachment_options[:keep_profile]
52
+ temp_paths.unshift write_to_temp_file(img.to_blob)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,514 @@
1
+ module Technoweenie # :nodoc:
2
+ module AttachmentFu # :nodoc:
3
+ @@default_processors = %w(ImageScience Rmagick MiniMagick Gd2 CoreImage)
4
+ @@tempfile_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
5
+ @@content_types = [
6
+ 'image/jpeg',
7
+ 'image/pjpeg',
8
+ 'image/jpg',
9
+ 'image/gif',
10
+ 'image/png',
11
+ 'image/x-png',
12
+ 'image/jpg',
13
+ 'image/x-ms-bmp',
14
+ 'image/bmp',
15
+ 'image/x-bmp',
16
+ 'image/x-bitmap',
17
+ 'image/x-xbitmap',
18
+ 'image/x-win-bitmap',
19
+ 'image/x-windows-bmp',
20
+ 'image/ms-bmp',
21
+ 'application/bmp',
22
+ 'application/x-bmp',
23
+ 'application/x-win-bitmap',
24
+ 'application/preview',
25
+ 'image/jp_',
26
+ 'application/jpg',
27
+ 'application/x-jpg',
28
+ 'image/pipeg',
29
+ 'image/vnd.swiftview-jpeg',
30
+ 'image/x-xbitmap',
31
+ 'application/png',
32
+ 'application/x-png',
33
+ 'image/gi_',
34
+ 'image/x-citrix-pjpeg'
35
+ ]
36
+ mattr_reader :content_types, :tempfile_path, :default_processors
37
+ mattr_writer :tempfile_path
38
+
39
+ class ThumbnailError < StandardError; end
40
+ class AttachmentError < StandardError; end
41
+
42
+ module ActMethods
43
+ # Options:
44
+ # * <tt>:content_type</tt> - Allowed content types. Allows all by default. Use :image to allow all standard image types.
45
+ # * <tt>:min_size</tt> - Minimum size allowed. 1 byte is the default.
46
+ # * <tt>:max_size</tt> - Maximum size allowed. 1.megabyte is the default.
47
+ # * <tt>:size</tt> - Range of sizes allowed. (1..1.megabyte) is the default. This overrides the :min_size and :max_size options.
48
+ # * <tt>:resize_to</tt> - Used by RMagick to resize images. Pass either an array of width/height, or a geometry string.
49
+ # * <tt>:thumbnails</tt> - Specifies a set of thumbnails to generate. This accepts a hash of filename suffixes and RMagick resizing options.
50
+ # * <tt>:thumbnail_class</tt> - Set what class to use for thumbnails. This attachment class is used by default.
51
+ # * <tt>:path_prefix</tt> - path to store the uploaded files. Uses public/#{table_name} by default for the filesystem, and just #{table_name}
52
+ # for the S3 backend. Setting this sets the :storage to :file_system.
53
+
54
+ # * <tt>:storage</tt> - Use :file_system to specify the attachment data is stored with the file system. Defaults to :db_system.
55
+ # * <tt>:cloundfront</tt> - Set to true if you are using S3 storage and want to serve the files through CloudFront. You will need to
56
+ # set a distribution domain in the amazon_s3.yml config file. Defaults to false
57
+ # * <tt>:bucket_key</tt> - Use this to specify a different bucket key other than :bucket_name in the amazon_s3.yml file. This allows you to use
58
+ # different buckets for different models. An example setting would be :image_bucket and the you would need to define the name of the corresponding
59
+ # bucket in the amazon_s3.yml file.
60
+
61
+ # * <tt>:keep_profile</tt> By default image EXIF data will be stripped to minimize image size. For small thumbnails this proivides important savings. Picture quality is not affected. Set to false if you want to keep the image profile as is. ImageScience will allways keep EXIF data.
62
+ #
63
+ # Examples:
64
+ # has_attachment :max_size => 1.kilobyte
65
+ # has_attachment :size => 1.megabyte..2.megabytes
66
+ # has_attachment :content_type => 'application/pdf'
67
+ # has_attachment :content_type => ['application/pdf', 'application/msword', 'text/plain']
68
+ # has_attachment :content_type => :image, :resize_to => [50,50]
69
+ # has_attachment :content_type => ['application/pdf', :image], :resize_to => 'x50'
70
+ # has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
71
+ # has_attachment :storage => :file_system, :path_prefix => 'public/files'
72
+ # has_attachment :storage => :file_system, :path_prefix => 'public/files',
73
+ # :content_type => :image, :resize_to => [50,50]
74
+ # has_attachment :storage => :file_system, :path_prefix => 'public/files',
75
+ # :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
76
+ # has_attachment :storage => :s3
77
+ def has_attachment(options = {})
78
+ # this allows you to redefine the acts' options for each subclass, however
79
+ options[:min_size] ||= 1
80
+ options[:max_size] ||= 1.megabyte
81
+ options[:size] ||= (options[:min_size]..options[:max_size])
82
+ options[:thumbnails] ||= {}
83
+ options[:thumbnail_class] ||= self
84
+ options[:s3_access] ||= :public_read
85
+ options[:cloudfront] ||= false
86
+ options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
87
+
88
+ unless options[:thumbnails].is_a?(Hash)
89
+ raise ArgumentError, ":thumbnails option should be a hash: e.g. :thumbnails => { :foo => '50x50' }"
90
+ end
91
+
92
+ extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods)
93
+ include InstanceMethods unless included_modules.include?(InstanceMethods)
94
+
95
+ parent_options = attachment_options || {}
96
+ # doing these shenanigans so that #attachment_options is available to processors and backends
97
+ self.attachment_options = options
98
+
99
+ attr_accessor :thumbnail_resize_options
100
+
101
+ attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
102
+ attachment_options[:storage] ||= parent_options[:storage]
103
+ attachment_options[:path_prefix] ||= attachment_options[:file_system_path]
104
+ if attachment_options[:path_prefix].nil?
105
+ attachment_options[:path_prefix] = case attachment_options[:storage]
106
+ when :s3 then table_name
107
+ when :cloud_files then table_name
108
+ else File.join("public", table_name)
109
+ end
110
+ end
111
+ attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
112
+
113
+ association_options = { :foreign_key => 'parent_id' }
114
+ if attachment_options[:association_options]
115
+ association_options.merge!(attachment_options[:association_options])
116
+ end
117
+ with_options(association_options) do |m|
118
+ m.has_many :thumbnails, :class_name => "::#{attachment_options[:thumbnail_class]}"
119
+ m.belongs_to :parent, :class_name => "::#{base_class}" unless options[:thumbnails].empty?
120
+ end
121
+
122
+ storage_mod = Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
123
+ include storage_mod unless included_modules.include?(storage_mod)
124
+
125
+ case attachment_options[:processor]
126
+ when :none, nil
127
+ processors = Technoweenie::AttachmentFu.default_processors.dup
128
+ begin
129
+ if processors.any?
130
+ attachment_options[:processor] = processors.first
131
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
132
+ include processor_mod unless included_modules.include?(processor_mod)
133
+ end
134
+ rescue Object, Exception
135
+ raise unless load_related_exception?($!)
136
+
137
+ processors.shift
138
+ retry
139
+ end
140
+ else
141
+ begin
142
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
143
+ include processor_mod unless included_modules.include?(processor_mod)
144
+ rescue Object, Exception
145
+ raise unless load_related_exception?($!)
146
+
147
+ puts "Problems loading #{options[:processor]}Processor: #{$!}"
148
+ end
149
+ end unless parent_options[:processor] # Don't let child override processor
150
+ end
151
+
152
+ def load_related_exception?(e) #:nodoc: implementation specific
153
+ case
154
+ when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError"
155
+ # We can't rescue CompilationError directly, as it is part of the RubyInline library.
156
+ # We must instead rescue RuntimeError, and check the class' name.
157
+ true
158
+ else
159
+ false
160
+ end
161
+ end
162
+ private :load_related_exception?
163
+ end
164
+
165
+ module ClassMethods
166
+ delegate :content_types, :to => Technoweenie::AttachmentFu
167
+
168
+ # Performs common validations for attachment models.
169
+ def validates_as_attachment
170
+ validates_presence_of :size, :content_type, :filename
171
+ validate :attachment_attributes_valid?
172
+ end
173
+
174
+ # Returns true or false if the given content type is recognized as an image.
175
+ def image?(content_type)
176
+ content_types.include?(content_type)
177
+ end
178
+
179
+ def self.extended(base)
180
+ base.class_inheritable_accessor :attachment_options
181
+ base.before_destroy :destroy_thumbnails
182
+ base.before_validation :set_size_from_temp_path
183
+ base.after_save :after_process_attachment
184
+ base.after_destroy :destroy_file
185
+ base.after_validation :process_attachment
186
+ if defined?(::ActiveSupport::Callbacks)
187
+ base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
188
+ end
189
+ end
190
+
191
+ unless defined?(::ActiveSupport::Callbacks)
192
+ # Callback after an image has been resized.
193
+ #
194
+ # class Foo < ActiveRecord::Base
195
+ # acts_as_attachment
196
+ # after_resize do |record, img|
197
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
198
+ # end
199
+ # end
200
+ def after_resize(&block)
201
+ write_inheritable_array(:after_resize, [block])
202
+ end
203
+
204
+ # Callback after an attachment has been saved either to the file system or the DB.
205
+ # Only called if the file has been changed, not necessarily if the record is updated.
206
+ #
207
+ # class Foo < ActiveRecord::Base
208
+ # acts_as_attachment
209
+ # after_attachment_saved do |record|
210
+ # ...
211
+ # end
212
+ # end
213
+ def after_attachment_saved(&block)
214
+ write_inheritable_array(:after_attachment_saved, [block])
215
+ end
216
+
217
+ # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
218
+ #
219
+ # class Foo < ActiveRecord::Base
220
+ # acts_as_attachment
221
+ # before_thumbnail_saved do |thumbnail|
222
+ # record = thumbnail.parent
223
+ # ...
224
+ # end
225
+ # end
226
+ def before_thumbnail_saved(&block)
227
+ write_inheritable_array(:before_thumbnail_saved, [block])
228
+ end
229
+ end
230
+
231
+ # Get the thumbnail class, which is the current attachment class by default.
232
+ # Configure this with the :thumbnail_class option.
233
+ def thumbnail_class
234
+ attachment_options[:thumbnail_class] = attachment_options[:thumbnail_class].constantize unless attachment_options[:thumbnail_class].is_a?(Class)
235
+ attachment_options[:thumbnail_class]
236
+ end
237
+
238
+ # Copies the given file path to a new tempfile, returning the closed tempfile.
239
+ def copy_to_temp_file(file, temp_base_name)
240
+ returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
241
+ tmp.close
242
+ FileUtils.cp file, tmp.path
243
+ end
244
+ end
245
+
246
+ # Writes the given data to a new tempfile, returning the closed tempfile.
247
+ def write_to_temp_file(data, temp_base_name)
248
+ returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
249
+ tmp.binmode
250
+ tmp.write data
251
+ tmp.close
252
+ end
253
+ end
254
+ end
255
+
256
+ module InstanceMethods
257
+ def self.included(base)
258
+ base.define_callbacks *[:after_resize, :after_attachment_saved, :before_thumbnail_saved] if base.respond_to?(:define_callbacks)
259
+ end
260
+
261
+ # Checks whether the attachment's content type is an image content type
262
+ def image?
263
+ self.class.image?(content_type)
264
+ end
265
+
266
+ # Returns true/false if an attachment is thumbnailable. A thumbnailable attachment has an image content type and the parent_id attribute.
267
+ def thumbnailable?
268
+ image? && respond_to?(:parent_id) && parent_id.nil?
269
+ end
270
+
271
+ # Returns the class used to create new thumbnails for this attachment.
272
+ def thumbnail_class
273
+ self.class.thumbnail_class
274
+ end
275
+
276
+ # Gets the thumbnail name for a filename. 'foo.jpg' becomes 'foo_thumbnail.jpg'
277
+ def thumbnail_name_for(thumbnail = nil)
278
+ return filename if thumbnail.blank?
279
+ ext = nil
280
+ basename = filename.gsub /\.\w+$/ do |s|
281
+ ext = s; ''
282
+ end
283
+ # ImageScience doesn't create gif thumbnails, only pngs
284
+ ext.sub!(/gif$/, 'png') if attachment_options[:processor] == "ImageScience"
285
+ "#{basename}_#{thumbnail}#{ext}"
286
+ end
287
+
288
+ # Creates or updates the thumbnail for the current attachment.
289
+ def create_or_update_thumbnail(temp_file, file_name_suffix, *size)
290
+ thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
291
+ returning find_or_initialize_thumbnail(file_name_suffix) do |thumb|
292
+ thumb.temp_paths.unshift temp_file
293
+ thumb.send(:'attributes=', {
294
+ :content_type => content_type,
295
+ :filename => thumbnail_name_for(file_name_suffix),
296
+ :thumbnail_resize_options => size
297
+ }, false)
298
+ callback_with_args :before_thumbnail_saved, thumb
299
+ thumb.save!
300
+ end
301
+ end
302
+
303
+ # Sets the content type.
304
+ def content_type=(new_type)
305
+ write_attribute :content_type, new_type.to_s.strip
306
+ end
307
+
308
+ # Sanitizes a filename.
309
+ def filename=(new_name)
310
+ write_attribute :filename, sanitize_filename(new_name)
311
+ end
312
+
313
+ # Returns the width/height in a suitable format for the image_tag helper: (100x100)
314
+ def image_size
315
+ [width.to_s, height.to_s] * 'x'
316
+ end
317
+
318
+ # Returns true if the attachment data will be written to the storage system on the next save
319
+ def save_attachment?
320
+ File.file?(temp_path.to_s)
321
+ end
322
+
323
+ # nil placeholder in case this field is used in a form.
324
+ def uploaded_data() nil; end
325
+
326
+ # This method handles the uploaded file object. If you set the field name to uploaded_data, you don't need
327
+ # any special code in your controller.
328
+ #
329
+ # <% form_for :attachment, :html => { :multipart => true } do |f| -%>
330
+ # <p><%= f.file_field :uploaded_data %></p>
331
+ # <p><%= submit_tag :Save %>
332
+ # <% end -%>
333
+ #
334
+ # @attachment = Attachment.create! params[:attachment]
335
+ #
336
+ # TODO: Allow it to work with Merb tempfiles too.
337
+ def uploaded_data=(file_data)
338
+ if file_data.respond_to?(:content_type)
339
+ return nil if file_data.size == 0
340
+ self.content_type = file_data.content_type
341
+ self.filename = file_data.original_filename if respond_to?(:filename)
342
+ else
343
+ return nil if file_data.blank? || file_data['size'] == 0
344
+ self.content_type = file_data['content_type']
345
+ self.filename = file_data['filename']
346
+ file_data = file_data['tempfile']
347
+ end
348
+ if file_data.is_a?(StringIO)
349
+ file_data.rewind
350
+ set_temp_data file_data.read
351
+ else
352
+ self.temp_paths.unshift file_data
353
+ end
354
+ end
355
+
356
+ # Gets the latest temp path from the collection of temp paths. While working with an attachment,
357
+ # multiple Tempfile objects may be created for various processing purposes (resizing, for example).
358
+ # An array of all the tempfile objects is stored so that the Tempfile instance is held on to until
359
+ # it's not needed anymore. The collection is cleared after saving the attachment.
360
+ def temp_path
361
+ p = temp_paths.first
362
+ p.respond_to?(:path) ? p.path : p.to_s
363
+ end
364
+
365
+ # Gets an array of the currently used temp paths. Defaults to a copy of #full_filename.
366
+ def temp_paths
367
+ @temp_paths ||= (new_record? || !respond_to?(:full_filename) || !File.exist?(full_filename) ?
368
+ [] : [copy_to_temp_file(full_filename)])
369
+ end
370
+
371
+ # Gets the data from the latest temp file. This will read the file into memory.
372
+ def temp_data
373
+ save_attachment? ? File.read(temp_path) : nil
374
+ end
375
+
376
+ # Writes the given data to a Tempfile and adds it to the collection of temp files.
377
+ def set_temp_data(data)
378
+ temp_paths.unshift write_to_temp_file data unless data.nil?
379
+ end
380
+
381
+ # Copies the given file to a randomly named Tempfile.
382
+ def copy_to_temp_file(file)
383
+ self.class.copy_to_temp_file file, random_tempfile_filename
384
+ end
385
+
386
+ # Writes the given file to a randomly named Tempfile.
387
+ def write_to_temp_file(data)
388
+ self.class.write_to_temp_file data, random_tempfile_filename
389
+ end
390
+
391
+ # Stub for creating a temp file from the attachment data. This should be defined in the backend module.
392
+ def create_temp_file() end
393
+
394
+ # Allows you to work with a processed representation (RMagick, ImageScience, etc) of the attachment in a block.
395
+ #
396
+ # @attachment.with_image do |img|
397
+ # self.data = img.thumbnail(100, 100).to_blob
398
+ # end
399
+ #
400
+ def with_image(&block)
401
+ self.class.with_image(temp_path, &block)
402
+ end
403
+
404
+ protected
405
+ # Generates a unique filename for a Tempfile.
406
+ def random_tempfile_filename
407
+ "#{rand Time.now.to_i}#{filename || 'attachment'}"
408
+ end
409
+
410
+ def sanitize_filename(filename)
411
+ return unless filename
412
+ returning filename.strip do |name|
413
+ # NOTE: File.basename doesn't work right with Windows paths on Unix
414
+ # get only the filename, not the whole path
415
+ name.gsub! /^.*(\\|\/)/, ''
416
+
417
+ # Finally, replace all non alphanumeric, underscore or periods with underscore
418
+ name.gsub! /[^A-Za-z0-9\.\-]/, '_'
419
+ end
420
+ end
421
+
422
+ # before_validation callback.
423
+ def set_size_from_temp_path
424
+ self.size = File.size(temp_path) if save_attachment?
425
+ end
426
+
427
+ # validates the size and content_type attributes according to the current model's options
428
+ def attachment_attributes_valid?
429
+ [:size, :content_type].each do |attr_name|
430
+ enum = attachment_options[attr_name]
431
+ if Object.const_defined?(:I18n) # Rails >= 2.2
432
+ errors.add attr_name, I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) unless enum.nil? || enum.include?(send(attr_name))
433
+ else
434
+ errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
435
+ end
436
+ end
437
+ end
438
+
439
+ # Initializes a new thumbnail with the given suffix.
440
+ def find_or_initialize_thumbnail(file_name_suffix)
441
+ respond_to?(:parent_id) ?
442
+ thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
443
+ thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
444
+ end
445
+
446
+ # Stub for a #process_attachment method in a processor
447
+ def process_attachment
448
+ @saved_attachment = save_attachment?
449
+ end
450
+
451
+ # Cleans up after processing. Thumbnails are created, the attachment is stored to the backend, and the temp_paths are cleared.
452
+ def after_process_attachment
453
+ if @saved_attachment
454
+ if respond_to?(:process_attachment_with_processing) && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
455
+ temp_file = temp_path || create_temp_file
456
+ attachment_options[:thumbnails].each { |suffix, size| create_or_update_thumbnail(temp_file, suffix, *size) }
457
+ end
458
+ save_to_storage
459
+ @temp_paths.clear
460
+ @saved_attachment = nil
461
+ callback :after_attachment_saved
462
+ end
463
+ end
464
+
465
+ # Resizes the given processed img object with either the attachment resize options or the thumbnail resize options.
466
+ def resize_image_or_thumbnail!(img)
467
+ if (!respond_to?(:parent_id) || parent_id.nil?) && attachment_options[:resize_to] # parent image
468
+ resize_image(img, attachment_options[:resize_to])
469
+ elsif thumbnail_resize_options # thumbnail
470
+ resize_image(img, thumbnail_resize_options)
471
+ end
472
+ end
473
+
474
+ # Yanked from ActiveRecord::Callbacks, modified so I can pass args to the callbacks besides self.
475
+ # Only accept blocks, however
476
+ if ActiveSupport.const_defined?(:Callbacks)
477
+ # Rails 2.1 and beyond!
478
+ def callback_with_args(method, arg = self)
479
+ notify(method)
480
+
481
+ result = run_callbacks(method, { :object => arg }) { |result, object| result == false }
482
+
483
+ if result != false && respond_to_without_attributes?(method)
484
+ result = send(method)
485
+ end
486
+
487
+ result
488
+ end
489
+
490
+ def run_callbacks(kind, options = {}, &block)
491
+ options.reverse_merge!( :object => self )
492
+ self.class.send("#{kind}_callback_chain").run(options[:object], options, &block)
493
+ end
494
+ else
495
+ # Rails 2.0
496
+ def callback_with_args(method, arg = self)
497
+ notify(method)
498
+
499
+ result = nil
500
+ callbacks_for(method).each do |callback|
501
+ result = callback.call(self, arg)
502
+ return false if result == false
503
+ end
504
+ result
505
+ end
506
+ end
507
+
508
+ # Removes the thumbnails for the attachment, if it has any
509
+ def destroy_thumbnails
510
+ self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
511
+ end
512
+ end
513
+ end
514
+ end