radiant-paperclipped-extension 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.gitmodules +3 -0
  2. data/HELP_admin.markdown +69 -0
  3. data/LICENSE +21 -0
  4. data/README.md +137 -0
  5. data/Rakefile +110 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/admin/assets_controller.rb +124 -0
  8. data/app/helpers/admin/assets_helper.rb +5 -0
  9. data/app/models/asset.rb +279 -0
  10. data/app/models/asset_page_tags.rb +101 -0
  11. data/app/models/asset_tags.rb +272 -0
  12. data/app/models/old_page_attachment.rb +26 -0
  13. data/app/models/page_attachment.rb +8 -0
  14. data/app/views/admin/assets/_asset.html.haml +19 -0
  15. data/app/views/admin/assets/_asset_table.html.haml +49 -0
  16. data/app/views/admin/assets/_assets_bucket.html.haml +8 -0
  17. data/app/views/admin/assets/_assets_container.html.haml +72 -0
  18. data/app/views/admin/assets/_bucket.html.haml +11 -0
  19. data/app/views/admin/assets/_bucket_asset.html.haml +9 -0
  20. data/app/views/admin/assets/_errors.html.haml +3 -0
  21. data/app/views/admin/assets/_form.html.haml +20 -0
  22. data/app/views/admin/assets/_page_assets.html.haml +12 -0
  23. data/app/views/admin/assets/_search_results.html.haml +17 -0
  24. data/app/views/admin/assets/_show_bucket_link.html.haml +4 -0
  25. data/app/views/admin/assets/_upload_to_page.html.haml +16 -0
  26. data/app/views/admin/assets/edit.html.haml +53 -0
  27. data/app/views/admin/assets/index.html.haml +43 -0
  28. data/app/views/admin/assets/new.html.haml +27 -0
  29. data/app/views/admin/assets/remove.html.haml +21 -0
  30. data/app/views/admin/bucket/_iframe.html.haml +1 -0
  31. data/config/locales/en.yml +60 -0
  32. data/config/locales/nl.yml +60 -0
  33. data/config/locales/pl.yml +60 -0
  34. data/config/routes.rb +20 -0
  35. data/db/migrate/001_create_assets.rb +12 -0
  36. data/db/migrate/002_create_paperclip_attributes.rb +13 -0
  37. data/db/migrate/003_create_user_observer.rb +13 -0
  38. data/db/migrate/004_create_page_attachments.rb +19 -0
  39. data/db/migrate/005_rename_users.rb +13 -0
  40. data/db/migrate/006_add_default_configs.rb +29 -0
  41. data/db/migrate/007_add_default_content_types.rb +29 -0
  42. data/db/migrate/20090316132151_disable_file_types.rb +20 -0
  43. data/lib/assets_admin_ui.rb +38 -0
  44. data/lib/mime_type_ext.rb +7 -0
  45. data/lib/tasks/assets_extension_tasks.rake +123 -0
  46. data/lib/tasks/paperclip_tasks.rake +79 -0
  47. data/lib/url_additions.rb +10 -0
  48. data/paperclipped_extension.rb +56 -0
  49. data/psds/file_type_icons.psd +0 -0
  50. data/psds/file_type_icons_.psd +0 -0
  51. data/public/images/assets/_page_assets.html.haml +26 -0
  52. data/public/images/assets/add-to-bucket.png +0 -0
  53. data/public/images/assets/add.png +0 -0
  54. data/public/images/assets/audio_icon.png +0 -0
  55. data/public/images/assets/audio_thumbnail.png +0 -0
  56. data/public/images/assets/delete.png +0 -0
  57. data/public/images/assets/doc_icon.png +0 -0
  58. data/public/images/assets/doc_thumbnail.png +0 -0
  59. data/public/images/assets/edit.png +0 -0
  60. data/public/images/assets/movie_icon.png +0 -0
  61. data/public/images/assets/movie_thumbnail.png +0 -0
  62. data/public/images/assets/new-asset.png +0 -0
  63. data/public/images/assets/page_edit.png +0 -0
  64. data/public/images/assets/pdf_icon.png +0 -0
  65. data/public/images/assets/pdf_thumbnail.png +0 -0
  66. data/public/images/assets/reorder_assets.png +0 -0
  67. data/public/javascripts/admin/assets.js +173 -0
  68. data/public/stylesheets/admin/assets.css +163 -0
  69. data/spec/controllers/admin/assets_controller_spec.rb +10 -0
  70. data/spec/models/asset_spec.rb +68 -0
  71. data/spec/spec.opts +6 -0
  72. data/spec/spec_helper.rb +27 -0
  73. data/vendor/plugins/acts_as_list/README +23 -0
  74. data/vendor/plugins/acts_as_list/init.rb +3 -0
  75. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  76. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  77. data/vendor/plugins/paperclip/LICENSE +26 -0
  78. data/vendor/plugins/paperclip/README.rdoc +179 -0
  79. data/vendor/plugins/paperclip/Rakefile +76 -0
  80. data/vendor/plugins/paperclip/cucumber/paperclip_steps.rb +6 -0
  81. data/vendor/plugins/paperclip/generators/paperclip/USAGE +5 -0
  82. data/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb +27 -0
  83. data/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  84. data/vendor/plugins/paperclip/init.rb +1 -0
  85. data/vendor/plugins/paperclip/lib/generators/paperclip/USAGE +8 -0
  86. data/vendor/plugins/paperclip/lib/generators/paperclip/paperclip_generator.rb +31 -0
  87. data/vendor/plugins/paperclip/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  88. data/vendor/plugins/paperclip/lib/paperclip.rb +397 -0
  89. data/vendor/plugins/paperclip/lib/paperclip/attachment.rb +326 -0
  90. data/vendor/plugins/paperclip/lib/paperclip/callback_compatability.rb +61 -0
  91. data/vendor/plugins/paperclip/lib/paperclip/geometry.rb +115 -0
  92. data/vendor/plugins/paperclip/lib/paperclip/interpolations.rb +108 -0
  93. data/vendor/plugins/paperclip/lib/paperclip/iostream.rb +59 -0
  94. data/vendor/plugins/paperclip/lib/paperclip/matchers.rb +33 -0
  95. data/vendor/plugins/paperclip/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  96. data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +74 -0
  97. data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  98. data/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  99. data/vendor/plugins/paperclip/lib/paperclip/processor.rb +49 -0
  100. data/vendor/plugins/paperclip/lib/paperclip/railtie.rb +24 -0
  101. data/vendor/plugins/paperclip/lib/paperclip/storage.rb +247 -0
  102. data/vendor/plugins/paperclip/lib/paperclip/style.rb +90 -0
  103. data/vendor/plugins/paperclip/lib/paperclip/thumbnail.rb +78 -0
  104. data/vendor/plugins/paperclip/lib/paperclip/upfile.rb +52 -0
  105. data/vendor/plugins/paperclip/lib/paperclip/version.rb +3 -0
  106. data/vendor/plugins/paperclip/lib/tasks/paperclip.rake +79 -0
  107. data/vendor/plugins/paperclip/paperclip.gemspec +34 -0
  108. data/vendor/plugins/paperclip/rails/init.rb +2 -0
  109. data/vendor/plugins/paperclip/shoulda_macros/paperclip.rb +119 -0
  110. data/vendor/plugins/paperclip/test/.gitignore +1 -0
  111. data/vendor/plugins/paperclip/test/attachment_test.rb +758 -0
  112. data/vendor/plugins/paperclip/test/database.yml +4 -0
  113. data/vendor/plugins/paperclip/test/fixtures/12k.png +0 -0
  114. data/vendor/plugins/paperclip/test/fixtures/50x50.png +0 -0
  115. data/vendor/plugins/paperclip/test/fixtures/5k.png +0 -0
  116. data/vendor/plugins/paperclip/test/fixtures/bad.png +1 -0
  117. data/vendor/plugins/paperclip/test/fixtures/s3.yml +8 -0
  118. data/vendor/plugins/paperclip/test/fixtures/text.txt +0 -0
  119. data/vendor/plugins/paperclip/test/fixtures/twopage.pdf +0 -0
  120. data/vendor/plugins/paperclip/test/geometry_test.rb +177 -0
  121. data/vendor/plugins/paperclip/test/helper.rb +148 -0
  122. data/vendor/plugins/paperclip/test/integration_test.rb +483 -0
  123. data/vendor/plugins/paperclip/test/interpolations_test.rb +124 -0
  124. data/vendor/plugins/paperclip/test/iostream_test.rb +78 -0
  125. data/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb +24 -0
  126. data/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb +37 -0
  127. data/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  128. data/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  129. data/vendor/plugins/paperclip/test/paperclip_test.rb +317 -0
  130. data/vendor/plugins/paperclip/test/processor_test.rb +10 -0
  131. data/vendor/plugins/paperclip/test/storage_test.rb +343 -0
  132. data/vendor/plugins/paperclip/test/style_test.rb +141 -0
  133. data/vendor/plugins/paperclip/test/thumbnail_test.rb +227 -0
  134. data/vendor/plugins/paperclip/test/upfile_test.rb +36 -0
  135. data/vendor/plugins/responds_to_parent/MIT-LICENSE +20 -0
  136. data/vendor/plugins/responds_to_parent/README +42 -0
  137. data/vendor/plugins/responds_to_parent/Rakefile +22 -0
  138. data/vendor/plugins/responds_to_parent/init.rb +2 -0
  139. data/vendor/plugins/responds_to_parent/lib/parent_selector_assertion.rb +144 -0
  140. data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +46 -0
  141. data/vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb +318 -0
  142. data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +115 -0
  143. metadata +226 -0
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/plugins/imagespec"]
2
+ path = vendor/plugins/imagespec
3
+ url = git://github.com/andersonbrandon/ruby-imagespec.git
@@ -0,0 +1,69 @@
1
+ Paperclipped
2
+ ---
3
+
4
+ Paperclip is a new file management plugin from Thoughtbot which has a few advantages over attachment_fu: it doesn't use RMagick, which uses a lot of RAM and is a bit of overkill for just making thumbnails. Instead it directly uses ImageMagick, making it much easier to install.
5
+
6
+
7
+ ###Installation
8
+
9
+ To install paperclipped, just run
10
+
11
+ rake production db:migrate:extensions
12
+ rake production radiant:extensions:paperclipped:update
13
+
14
+ This runs the database migrations and installs the javascripts, images and css.
15
+
16
+ ###Configuration
17
+
18
+ If you install the Setting Extension (highly recommended), you can also easily adjust both the sizes of any additional thumbnails and which thumbnails are displayed in the image edit view. The default is the original file, but any image size can be used by giving in the name of that size.
19
+
20
+ The configuration settings also enable a list of the allowed file types, maximum file size and should you need it, the path to your installation of Image Magick (this should not be needed, but I sometimes had a problem when using mod_rails).
21
+
22
+ ###Using Paperclipped
23
+
24
+ Once installed, you get a new Tab with the entire assets library, a Bucket à la Mephisto (though only the concept is stolen) and a search. You can also easily attach assets to any page and directly upload them to a page.
25
+
26
+ ###Asset Tags
27
+
28
+ There are a veriety of new tags. The basic tag is the <r:assets /> tag, which can be used either alone or as a double tag. This tag requires the "title" attribute, which references the asset. If you use the drag and drop from the asset bucket, this title will be added for you.
29
+
30
+ The *&lt;r:assets /&gt;* tag can be combined with other tags for a variety of uses:
31
+
32
+ <r:assets:image title="foo" /> will return <img src="/path/to/foo" alt="foo" />
33
+ <r:assets:link title="foo" /> will return <a href="/path/to/foo">foo</a>
34
+
35
+ You could also use:
36
+
37
+ <r:assets:link title="foo" text="This is the link to foo" /> will return <a href="/path/to/foo">This is the link to foo</a>
38
+
39
+ or
40
+
41
+ <rassets:link title="foo">This is another link</r:link>
42
+
43
+ Asset links are also available, such as content_type, file_size, and url.
44
+
45
+ Another important tag is the *&lt;r:assets:each&gt;...&lt;/r:assets:each&gt;*. If a page has attached assets, the assets:each tag will cycle through each asset. You can then use an image, link or url tag to display or connect your assets.
46
+
47
+ Thumbnails are automatically geneerated for images when the images are uploaded. By default, two sizes are made for use within the extension itself. These are "icon" 42px by 42px and "thumbnail" which is fit into 100px, maintaining its aspect ratio.
48
+
49
+ ###Migrating from the page_attachments extension
50
+
51
+ If you're moving from page_attachments to paperclipped, here's how to migrate smoothly;
52
+
53
+ First, remove or disable the page_attachments extension, and install the paperclipped extension.
54
+ For example:
55
+
56
+ rake ray:dis name=page_attachments
57
+ rake ray:assets
58
+
59
+ or
60
+
61
+ rm -rf vendor/extensions/page_attachments
62
+ script/extension install paperclipped
63
+
64
+ The migration has now copied your original page_attachments table to old_page_attachments.
65
+
66
+ rake radiant:extensions:paperclipped:migrate_from_page_attachments
67
+
68
+ This rake task will create paperclipped-style attachments for all OldPageAttachments. It will also ask you if you want to clean up the old table and thumbnails in /public/page_attachments.
69
+ Done!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ == MIT License
2
+
3
+ Copyright (c) 2008-2010, Keith Bingman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,137 @@
1
+ Paperclipped
2
+ ---
3
+
4
+ ## IMPORTANT!
5
+
6
+ This version of Paperclipped now requires Radiant 0.9.0 or higher. Just in case, the previous version is still around, on a branch marked Radiant-0.8
7
+
8
+ Let me know if this works and if you run into any issues.
9
+
10
+
11
+ ###Installation
12
+
13
+ To install paperclipped, just run
14
+
15
+ rake production db:migrate:extensions
16
+ rake production radiant:extensions:paperclipped:update
17
+
18
+ This runs the database migrations and installs the javascripts, images and css.
19
+
20
+ ###Configuration
21
+
22
+ If you install the Settings Extension (highly recommended), you can also easily adjust both the sizes of any additional thumbnails and which thumbnails are displayed in the image edit view. The default is the original file, but any image size can be used by giving in the name of that size.
23
+
24
+ If you do install the Settings Extension you should be sure to add a config.extensions line to your environment.rb file:
25
+
26
+ config.extensions = [ :settings, :all ]
27
+
28
+ Also the Settings Extension migration should be run before Paperclipped's migration.
29
+
30
+ The configuration settings also enable a list of the allowed file types, maximum file size and should you need it, the path to your installation of Image Magick (this should not be needed, but I sometimes had a problem when using mod_rails).
31
+
32
+ Paperclipped will integrate with the Styles'n'Scripts extension. For that to work, you'll need to load that extension before paperclipped:
33
+
34
+ config.extensions = [ :sns, :all ]
35
+
36
+ ###Using Paperclipped
37
+
38
+ Once installed, you get a new Tab with the entire assets library, a Bucket à la Mephisto (though only the concept is stolen) and a search. You can also easily attach assets to any page and directly upload them to a page.
39
+
40
+ ###Asset Tags
41
+
42
+ There are a veriety of new tags. The basic tag is the <code><r:assets /></code> tag, which can be used either alone or as a double tag. This tag requires the "title" attribute, which references the asset. If you use the drag and drop from the asset bucket, this title will be added for you.
43
+
44
+ The <code><r:assets /></code> tag can be combined with other tags for a variety of uses:
45
+
46
+ <r:assets:image title="foo" /> will return <img src="/path/to/foo" alt="foo" />
47
+
48
+ <r:assets:link title="foo" /> will return <a href="/path/to/foo">foo</a>
49
+
50
+ You could also use:
51
+
52
+ <r:assets:link title="foo" text="This is the link to foo" /> will return <a href="/path/to/foo">This is the link to foo</a>
53
+
54
+ or
55
+
56
+ <r:assets:link title="foo">This is another link</r:link>
57
+
58
+ Asset links are also available, such as content_type, file_size, and url.
59
+
60
+ Another important tag is the <code><r:assets:each>...</r:assets:each></code>. If a page has attached assets, the assets:each tag will cycle through each asset. You can then use an image, link or url tag to display or connect your assets. Usage:
61
+
62
+ <r:assets:each [limit=0] [offset=0] [order="asc|desc"] [by="position|title|..."] [extensions="png|pdf|doc"]>
63
+ ...
64
+ </r:assets:each>
65
+
66
+ `<r:assets:each>` parameters:
67
+
68
+ * `limit` and `offset` let you specify a range of assets;
69
+ * `order` and `by` lets you control sorting;
70
+ * `extensions` allows you to filter assets by file extensions; you can specify multiple extensions separated by `|`.
71
+
72
+ <code><pre>`<r:if_assets [min_count="0"]>` and `<r:unless_assets [min_count="0"]>`
73
+ </code></pre>
74
+
75
+ conditional tags let you optionally render content based on the existance of tags. They accept the same options as `<r:assets:each>`.
76
+
77
+ Thumbnails are automatically generated for images when the images are uploaded. By default, two sizes are made for use within the extension itself. These are "icon" 42px by 42px and "thumbnail" which is fit into 100px, maintaining its aspect ratio.
78
+
79
+ You can access sizes of image assets for various versions with the tags `<r:assets:width [size="original"]/>` and `<r:assets:height [size="original"]/>`.
80
+
81
+ Also, for vertical centering of images, you have the handy `<r:assets:top_padding container="<container height>" [size="icon"]/>` tag. Working example:
82
+
83
+
84
+ <ul>
85
+ <r:assets:each>
86
+ <li style="height:140px">
87
+ <img style="padding-top:<r:top_padding size='category' container='140' />px"
88
+ src="<r:url />" alt="<r:title />" />
89
+ </li>
90
+ </r:assets:each>
91
+ </ul>
92
+
93
+
94
+ ###Using Amazon s3
95
+ First, be sure you have the aws\-s3 gem installed.
96
+
97
+ <pre><code>gem install aws-s3</code></pre>
98
+
99
+ Everything works as before, but now if you want to add S3 support, you simply set the storage setting to "s3".
100
+
101
+ <pre><code>Radiant::Config[assets.storage] = "s3"</code></pre>
102
+
103
+ Then add 3 new settings with your Amazon credentials, either in the console or with the [Settings](http://github.com/Squeegy/radiant-settings/tree/master) extension:
104
+
105
+ <pre><code>Radiant::Config[assets.s3.bucket] = "my_supercool_bucket"
106
+ Radiant::Config[assets.s3.key] = "123456"
107
+ Radiant::Config[assets.s3.secret] = "123456789ABCDEF"
108
+ </code></pre>
109
+
110
+ and finally the path you want to use within your bucket, which uses the same notation as the Paperclip plugin.
111
+
112
+ <pre><code>Radiant::Config[assets.path] = :class/:id/:basename_:style.:extension
113
+ </code></pre>
114
+
115
+ The path setting, along with a new <code>url</code> setting can be used with the file system to customize both the path and url of your assets.
116
+
117
+
118
+ ### Migrating from the page_attachments extension
119
+
120
+ If you're moving from page_attachments to paperclipped, here's how to migrate smoothly:
121
+
122
+ First, remove or disable the page_attachments extension, and install the paperclipped extension.
123
+ For example:
124
+
125
+ <pre><code>rake ray:dis name=page_attachments
126
+ rake ray:assets
127
+ </code></pre>
128
+
129
+
130
+ The migration has now copied your original `page_attachments` table to `old_page_attachments`.
131
+
132
+ <pre><code>rake radiant:extensions:paperclipped:migrate_from_page_attachments
133
+ </code></pre>
134
+
135
+ This rake task will create paperclipped-style attachments for all `OldPageAttachments`. It will also ask you if you want to clean up the old table and thumbnails in `/public/page_attachments`.
136
+
137
+ Done!
@@ -0,0 +1,110 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-paperclipped-extension"
5
+ gem.summary = %Q{Paperclipped extension for Radiant CMS}
6
+ gem.description = %Q{Assets extension based on the lightweight Paperclip plugin.}
7
+ gem.email = "benny@gorilla-webdesign.be"
8
+ gem.homepage = "https://github.com/jomz/paperclipped"
9
+ gem.authors = ["Keith Bingman"]
10
+ gem.add_dependency 'radiant', ">=0.9.1"
11
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package copy_move as a gem."
15
+ end
16
+ # I think this is the one that should be moved to the extension Rakefile template
17
+
18
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
19
+ # Check to see if the rspec plugin is installed first and require
20
+ # it if it is. If not, use the gem version.
21
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'config', 'boot')
22
+ require 'rake'
23
+ require 'rake/rdoctask'
24
+
25
+ rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../radiant/vendor/plugins/rspec/lib')
26
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
27
+ require 'spec/rake/spectask'
28
+ # require 'spec/translator'
29
+
30
+ extension_root = File.expand_path(File.dirname(__FILE__))
31
+
32
+ task :default => :spec
33
+ task :stats => "spec:statsetup"
34
+
35
+ desc "Run all specs in spec directory"
36
+ Spec::Rake::SpecTask.new(:spec) do |t|
37
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ end
40
+
41
+ namespace :spec do
42
+ desc "Run all specs in spec directory with RCov"
43
+ Spec::Rake::SpecTask.new(:rcov) do |t|
44
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
45
+ t.spec_files = FileList['spec/**/*_spec.rb']
46
+ t.rcov = true
47
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
48
+ end
49
+
50
+ desc "Print Specdoc for all specs"
51
+ Spec::Rake::SpecTask.new(:doc) do |t|
52
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
53
+ t.spec_files = FileList['spec/**/*_spec.rb']
54
+ end
55
+
56
+ [:models, :controllers, :views, :helpers].each do |sub|
57
+ desc "Run the specs under spec/#{sub}"
58
+ Spec::Rake::SpecTask.new(sub) do |t|
59
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
60
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
61
+ end
62
+ end
63
+
64
+ # Hopefully no one has written their extensions in pre-0.9 style
65
+ # desc "Translate specs from pre-0.9 to 0.9 style"
66
+ # task :translate do
67
+ # translator = ::Spec::Translator.new
68
+ # dir = RAILS_ROOT + '/spec'
69
+ # translator.translate(dir, dir)
70
+ # end
71
+
72
+ # Setup specs for stats
73
+ task :statsetup do
74
+ require 'code_statistics'
75
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
76
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
77
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
78
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
79
+ ::CodeStatistics::TEST_TYPES << "Model specs"
80
+ ::CodeStatistics::TEST_TYPES << "View specs"
81
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
82
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
83
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
84
+ end
85
+
86
+ namespace :db do
87
+ namespace :fixtures do
88
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
89
+ task :load => :environment do
90
+ require 'active_record/fixtures'
91
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
92
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
93
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ desc 'Generate documentation for the assets extension.'
101
+ Rake::RDocTask.new(:rdoc) do |rdoc|
102
+ rdoc.rdoc_dir = 'rdoc'
103
+ rdoc.title = 'PaperclippedExtension'
104
+ rdoc.options << '--line-numbers' << '--inline-source'
105
+ rdoc.rdoc_files.include('README')
106
+ rdoc.rdoc_files.include('lib/**/*.rb')
107
+ end
108
+
109
+ # Load any custom rakefiles for extension
110
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.1
@@ -0,0 +1,124 @@
1
+ class Admin::AssetsController < Admin::ResourceController
2
+ paginate_models
3
+ skip_before_filter :verify_authenticity_token, :only => :create
4
+
5
+ def index
6
+ @assets = Asset.search(params[:search], params[:filter], params[:p])
7
+ @page = Page.find(params[:asset_page]) if params[:asset_page]
8
+
9
+ respond_to do |format|
10
+ format.html { render }
11
+ format.js {
12
+ @template_name = 'index'
13
+ if !@page.nil?
14
+ render :partial => 'admin/assets/search_results.html.haml', :layout => false
15
+ else
16
+ render :partial => 'admin/assets/asset_table.html.haml', :locals => { :assets => @assets }, :layout => false
17
+ end
18
+ }
19
+ end
20
+ end
21
+
22
+ def create
23
+ @asset = Asset.new(params[:asset])
24
+ if @asset.save
25
+ if params[:page]
26
+ @page = Page.find(params[:page])
27
+ @asset.pages << @page
28
+ end
29
+
30
+ respond_to do |format|
31
+ format.html {
32
+ flash[:notice] = "Asset successfully uploaded."
33
+ redirect_to(@page ? edit_admin_page_path(@page) : (params[:continue] ? edit_admin_asset_path(@asset) : admin_assets_path))
34
+ }
35
+ format.js {
36
+ responds_to_parent do
37
+ render :update do |page|
38
+ @attachment = PageAttachment.find(:first, :conditions => { :page_id => @page.id, :asset_id => @asset.id })
39
+ page.call('Asset.ChooseTabByName', 'page-attachments')
40
+ page.insert_html :bottom, "attachments", :partial => 'admin/assets/asset', :locals => {:attachment => @attachment }
41
+ page.call('Asset.AddAsset', "attachment_#{@attachment.id}") # we ought to reinitialise the sortable attachments too
42
+ page.visual_effect :highlight, "attachment_#{@attachment.id}"
43
+ page.call('Asset.ResetForm')
44
+ end
45
+ end
46
+ }
47
+ end
48
+ else
49
+ render :action => 'new'
50
+ end
51
+ end
52
+
53
+
54
+ # Refreshes the paperclip thumbnails
55
+ def refresh
56
+ unless params[:id]
57
+ @assets = Asset.find(:all)
58
+ @assets.each do |asset|
59
+ asset.asset.reprocess!
60
+ end
61
+ flash[:notice] = "Thumbnails successfully refreshed."
62
+ redirect_to admin_assets_path
63
+ else
64
+ @asset = Asset.find(params[:id])
65
+ @asset.asset.reprocess!
66
+ flash[:notice] = "Thumbnail successfully refreshed."
67
+ redirect_to edit_admin_asset_path(@asset)
68
+ end
69
+ end
70
+
71
+
72
+ # Bucket related actions. These may need to be spun out into a seperate controller
73
+ # update?
74
+ def add_bucket
75
+ @asset = Asset.find(params[:id])
76
+ if (session[:bucket] ||= {}).key?(@asset.asset.url)
77
+ render :nothing => true and return
78
+ end
79
+ asset_type = @asset.image? ? 'image' : 'link'
80
+ session[:bucket][@asset.asset.url] = { :thumbnail => @asset.thumbnail(:thumbnail), :id => @asset.id, :title => @asset.title, :type => asset_type }
81
+
82
+ render :update do |page|
83
+ page[:bucket_list].replace_html "#{render :partial => 'bucket'}"
84
+ end
85
+ end
86
+
87
+ def clear_bucket
88
+ session[:bucket] = nil
89
+ render :update do |page|
90
+ page[:bucket_list].replace_html '<li><p class="note"><em>Your bucket is empty.</em></p></li>'
91
+ end
92
+ end
93
+
94
+ # Attaches an asset to the current page
95
+ def attach_asset
96
+ @asset = Asset.find(params[:asset])
97
+ @page = Page.find(params[:page])
98
+ @page.assets << @asset unless @page.assets.include?(@asset)
99
+ clear_model_cache
100
+ render :partial => 'page_assets', :locals => { :page => @page }
101
+ # render :update do |page|
102
+ # page[:attachments].replace_html "#{render :partial => 'page_assets', :locals => {:page => @page}}"
103
+ # end
104
+ end
105
+
106
+ # Removes asset from the current page
107
+ def remove_asset
108
+ @asset = Asset.find(params[:asset])
109
+ @page = Page.find(params[:page])
110
+ @page.assets.delete(@asset)
111
+ clear_model_cache
112
+ render :nothing => true
113
+ end
114
+
115
+ def reorder
116
+ params[:attachments].each_with_index do |id,idx|
117
+ page_attachment = PageAttachment.find(id)
118
+ page_attachment.position = idx+1
119
+ page_attachment.save
120
+ end
121
+ clear_model_cache
122
+ render :nothing => true
123
+ end
124
+ end