effective_assets 0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +341 -72
  4. data/app/assets/javascripts/effective/snippets/effective_asset.js.coffee +53 -0
  5. data/app/assets/javascripts/effective_assets.js +4 -0
  6. data/app/assets/javascripts/effective_assets/asset_box.js.coffee +36 -0
  7. data/app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee +49 -0
  8. data/app/assets/javascripts/effective_assets/asset_box_drag_and_drop.js.coffee +2 -0
  9. data/app/assets/javascripts/effective_assets/asset_box_filtering.js.coffee +16 -0
  10. data/app/assets/javascripts/effective_assets/asset_box_sorting.js.coffee +8 -0
  11. data/app/assets/javascripts/effective_assets/jquery_ui_sortable.js +813 -585
  12. data/app/assets/javascripts/effective_assets/s3_uploader.js.coffee +268 -0
  13. data/app/assets/javascripts/effective_assets_iframe.js.coffee +28 -0
  14. data/app/assets/stylesheets/active_admin/effective_assets.css.scss +57 -0
  15. data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +54 -175
  16. data/app/assets/stylesheets/effective_assets/_iframe_bootstrap.scss +1714 -0
  17. data/app/assets/stylesheets/effective_assets/_input_bootstrap.scss +508 -0
  18. data/app/assets/stylesheets/effective_assets_iframe.css.scss +23 -0
  19. data/app/controllers/effective/assets_controller.rb +41 -0
  20. data/app/controllers/effective/s3_uploads_controller.rb +58 -74
  21. data/app/helpers/effective_assets_helper.rb +30 -14
  22. data/app/helpers/effective_assets_s3_helper.rb +69 -0
  23. data/app/models/concerns/acts_as_asset_box.rb +75 -11
  24. data/app/models/effective/access_denied.rb +17 -0
  25. data/app/models/effective/asset.rb +130 -93
  26. data/app/models/effective/attachment.rb +2 -7
  27. data/app/models/effective/delayed_job.rb +33 -78
  28. data/app/models/effective/snippets/effective_asset.rb +19 -0
  29. data/app/models/effective/user_uploads.rb +19 -0
  30. data/app/models/inputs/asset_box.rb +154 -0
  31. data/app/models/inputs/asset_box_form_input.rb +7 -0
  32. data/app/models/inputs/asset_box_formtastic_input.rb +9 -0
  33. data/app/models/inputs/asset_box_input.rb +13 -82
  34. data/app/models/inputs/asset_box_simple_form_input.rb +7 -0
  35. data/app/uploaders/effective_assets_uploader.rb +14 -2
  36. data/app/uploaders/{asset_uploader.rb → test_asset_uploader.rb} +1 -1
  37. data/app/views/active_admin/effective_assets/_edit.html.haml +3 -3
  38. data/app/views/active_admin/effective_assets/_new.html.haml +2 -1
  39. data/app/views/asset_box_input/_attachment_as_list.html.haml +17 -0
  40. data/app/views/asset_box_input/_attachment_as_table.html.haml +32 -0
  41. data/app/views/asset_box_input/_attachment_as_thumbnail.html.haml +20 -0
  42. data/app/views/asset_box_input/_dialog.html.haml +18 -0
  43. data/app/views/asset_box_input/_progress_bar_template.html.haml +8 -0
  44. data/app/views/asset_box_input/_uploader.html.haml +21 -115
  45. data/app/views/effective/assets/iframe.html.haml +17 -0
  46. data/app/views/effective/snippets/_effective_asset.html.haml +8 -0
  47. data/config/routes.rb +8 -2
  48. data/db/migrate/01_create_effective_assets.rb.erb +3 -0
  49. data/lib/effective_assets.rb +34 -3
  50. data/lib/effective_assets/engine.rb +11 -8
  51. data/lib/effective_assets/version.rb +1 -1
  52. data/lib/generators/templates/asset_uploader.rb +35 -0
  53. data/lib/generators/templates/effective_assets.rb +31 -4
  54. data/lib/tasks/effective_assets_tasks.rake +115 -4
  55. data/spec/internal/config/database.yml +3 -0
  56. data/spec/internal/config/initializers/effective_assets.rb +18 -0
  57. data/spec/internal/config/routes.rb +3 -0
  58. data/spec/internal/db/combustion_test.sqlite +0 -0
  59. data/spec/internal/db/schema.rb +52 -0
  60. data/spec/internal/log/test.log +793 -0
  61. data/spec/{dummy → internal}/public/favicon.ico +0 -0
  62. data/spec/internal/public/sprites.png +0 -0
  63. data/spec/models/asset_spec.rb +119 -35
  64. data/spec/spec_helper.rb +9 -3
  65. metadata +95 -234
  66. data/app/assets/images/effective_assets/s3_down_button.gif +0 -0
  67. data/app/assets/images/effective_assets/s3_over_button.gif +0 -0
  68. data/app/assets/images/effective_assets/s3_up_button.gif +0 -0
  69. data/app/assets/images/effective_assets/s3_upload.swf +0 -0
  70. data/app/assets/javascripts/effective_assets/asset_box_input.js.coffee +0 -71
  71. data/app/assets/javascripts/effective_assets/asset_box_uploader.js +0 -122
  72. data/app/assets/javascripts/effective_assets/asset_box_uploader_customization.js +0 -166
  73. data/app/controllers/effective/attachments_controller.rb +0 -14
  74. data/app/views/asset_box_input/_attachment_fields.html.haml +0 -14
  75. data/spec/dummy/README.rdoc +0 -261
  76. data/spec/dummy/Rakefile +0 -7
  77. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  78. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  79. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  80. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  81. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  82. data/spec/dummy/config.ru +0 -4
  83. data/spec/dummy/config/application.rb +0 -65
  84. data/spec/dummy/config/boot.rb +0 -10
  85. data/spec/dummy/config/database.yml +0 -25
  86. data/spec/dummy/config/environment.rb +0 -5
  87. data/spec/dummy/config/environments/development.rb +0 -37
  88. data/spec/dummy/config/environments/production.rb +0 -67
  89. data/spec/dummy/config/environments/test.rb +0 -37
  90. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  91. data/spec/dummy/config/initializers/inflections.rb +0 -15
  92. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  93. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  94. data/spec/dummy/config/initializers/session_store.rb +0 -8
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  96. data/spec/dummy/config/locales/en.yml +0 -5
  97. data/spec/dummy/config/routes.rb +0 -58
  98. data/spec/dummy/db/development.sqlite3 +0 -0
  99. data/spec/dummy/db/schema.rb +0 -16
  100. data/spec/dummy/db/test.sqlite3 +0 -0
  101. data/spec/dummy/log/development.log +0 -71
  102. data/spec/dummy/log/test.log +0 -33
  103. data/spec/dummy/public/404.html +0 -26
  104. data/spec/dummy/public/422.html +0 -26
  105. data/spec/dummy/public/500.html +0 -25
  106. data/spec/dummy/script/rails +0 -6
  107. data/spec/dummy/spec_link +0 -3
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66a6a8c617143cf4a5bf07ca983c107eb051cf4f
4
+ data.tar.gz: 1603b90503e071746ee3624122d94ded27feb91e
5
+ SHA512:
6
+ metadata.gz: e456d433b9525f7d8b8f3b7224485b4f4525be003a84f75e67dc7f4452fc527300f1d89e6388d85da60afaf943f87d2d5552ed4aed7aee169d6bb33fca7abad1
7
+ data.tar.gz: fa8954c62cd8ae6178990ae71f547e0bbfae9a8a5f3b81680ebaeb500f3dfcfc29cb1bb9dd2d136efd537db80743e73d19ea30bc1a070395e5471a404c1bc671
@@ -1,4 +1,4 @@
1
- Copyright 2013 YOURNAME
1
+ Copyright 2014 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # Effective Assets
2
2
 
3
- A full solution for managing assets (images, files, videos, etc).
3
+ Upload images and files directly to AWS S3 with a custom form input, then seamlessly organize and attach them to any ActiveRecord object.
4
+
5
+ A Rails Engine full solution for managing assets (images, files, videos, etc).
4
6
 
5
7
  Attach one or more assets to any model with validations.
6
8
 
7
- Includes an upload direct to Amazon S3 implementation based on s3_swf_upload and image processing in the background with CarrierWave and DelayedJob
9
+ Upload direct to Amazon S3 implementation based on jQuery-File-Upload and image processing on a background process with CarrierWave and DelayedJob
10
+
11
+ Rails FormBuilder, Formtastic and SimpleForm inputs for displaying, managing, and uploading assets direct to S3.
12
+
13
+ Works with AWS public-read and authenticated-read for easy secured downloads.
8
14
 
9
- Formtastic input for displaying, organizing, and uploading assets direct to s3.
15
+ Includes integration with ActiveAdmin
10
16
 
11
- Includes (optional but recommended) integration with ActiveAdmin
17
+ Rails 3.2.x and Rails4 support
12
18
 
13
19
  ## Getting Started
14
20
 
@@ -32,7 +38,7 @@ rails generate effective_assets:install
32
38
 
33
39
  The generator will install an initializer which describes all configuration options and creates two database migrations, one for EffectiveAssets the other for DelayedJob.
34
40
 
35
- If you want to tweak the table name (to use something other than the default 'assets' and 'attachments'), manually adjust both the configuration file and the migration now.
41
+ If you want to tweak the table name (to use something other than the default `assets` and `attachments`), manually adjust both the configuration file and the migration now.
36
42
 
37
43
  Then migrate the database:
38
44
 
@@ -40,120 +46,343 @@ Then migrate the database:
40
46
  rake db:migrate
41
47
  ```
42
48
 
43
- If you intend to use the form helper method to display and upload assets, require the javascript in your application.js
49
+ If you intend to use the form helper method to display and upload assets, require the javascript in your application.js:
44
50
 
45
51
  ```ruby
46
- //= require effective_addresses
52
+ //= require effective_assets
47
53
  ```
48
54
 
49
- If you intend to use ActiveAdmin (optional, but highly recommended)
55
+ If you intend to use ActiveAdmin (optional):
50
56
 
51
57
  Add to your ActiveAdmin.js file:
52
58
 
53
59
  ```ruby
54
60
  //= require effective_assets
55
-
56
61
  ```
57
62
 
58
63
  And to your ActiveAdmin stylesheet
59
64
 
60
65
  ```ruby
61
66
  body.active_admin {
62
- @import "effective_assets";
63
67
  }
68
+ @import "active_admin/effective_assets";
64
69
  ```
65
70
 
66
71
  If ActiveAdmin is installed, there will automatically be an 'Effective Assets' page.
67
72
 
73
+ ## Create/Configure an S3 Bucket
74
+
75
+ You will need an AWS IAM user with sufficient priviledges and a properly configured S3 bucket to use with effective_assets
76
+
77
+ ### Log into AWS Console
78
+
79
+ - Visit http://aws.amazon.com/console/
80
+ - Click My Account from top-right and sign in with your AWS account.
81
+
82
+ ### Create an S3 Bucket
83
+
84
+ - Click Services -> S3 from the top-left menu
85
+ - Click Create Bucket
86
+ - Give the Bucket a name, and select the US Standard region
87
+
88
+ ### Configure CORS Permissions
89
+
90
+ - From the S3 All Buckets Screen (as above)
91
+
92
+ - Select the desired bucket to configure and select 'Properties'
93
+ - Expand Permissions
94
+ - Click 'Edit CORS Configuration' and enter the following
95
+
96
+ ```xml
97
+ <CORSConfiguration>
98
+ <CORSRule>
99
+ <AllowedOrigin>*</AllowedOrigin>
100
+ <AllowedMethod>POST</AllowedMethod>
101
+ <AllowedHeader>*</AllowedHeader>
102
+ </CORSRule>
103
+ <CORSRule>
104
+ <AllowedOrigin>*</AllowedOrigin>
105
+ <AllowedMethod>GET</AllowedMethod>
106
+ </CORSRule>
107
+ </CORSConfiguration>
108
+ ```
109
+
110
+ - Click Save
111
+
112
+ The Bucket is now set up and ready to accept uploads, but we still need a user that has permission to access S3
113
+
114
+ ### Create an IAM User and record its AWS Access Keys
115
+
116
+ - After logging in to your AWS console
117
+
118
+ - Click Services -> IAM from the top-left
119
+
120
+ - Select Users from the left-side menu
121
+ - Click Create New Users
122
+ - Create just one user with any name
123
+
124
+ - Expand the Show User Security Credentials
125
+ - This displays the AWS Access Key and Secret Access Key.
126
+ - (important) These are the two values you should copy into the effective_assets.rb initializer file
127
+
128
+ - Once the user is created, Click on the User and find the Permissions tab
129
+ - Select Permissions tab
130
+ - Click Attach User Policy
131
+ - Scroll down and Select 'Amazon S3 Full Access'
132
+
133
+ This user is now set up and ready to access the S3 Bucket previously created
134
+
135
+ ### Add S3 Access Keys
136
+
137
+ Add the name of your S3 Bucket, Access Key and Secret Access Key to the config/initializers/effective_assets.rb file.
138
+
139
+ ```ruby
140
+ config.aws_bucket = 'my-bucket'
141
+ config.aws_access_key_id = 'ABCDEFGHIJKLMNOP'
142
+ config.aws_secret_access_key = 'xmowueroewairo74pacja1/werjow'
143
+ ```
144
+
145
+ You should now be able to upload to this bucket.
146
+
147
+
68
148
  ## Usage
69
149
 
70
150
  ### Model
71
151
 
72
- When including the acts_as_asset_box mixin, the idea of 'boxes' is presented. A box is just a category, which can have any name.
152
+ Use the `acts_as_asset_box` mixin to define a set of 'boxes' all your assets are grouped into. A box is just a category, which can have any name.
73
153
 
74
- If the box is declared as a singular, 'photo', then it will be a singular asset. When defined as a plural, 'photos', it will be a set of photos.
154
+ If the box is declared using a singular word, such as `:photo` it will be set up as a `has_one` asset. When defined as a plural, such as `:photos` it implies a `has_many` assets.
75
155
 
76
- The following will create 3 separate sets of assets:
156
+ The following will create 4 separate boxes of assets:
77
157
 
78
158
  ```ruby
79
159
  class User
80
- acts_as_asset_box :fav_icon, :pictures, :logos
160
+ acts_as_asset_box :avatar, :photos, :videos, :mp3s
81
161
  end
82
162
  ```
83
163
 
84
- Calling @user.fav_icon will return a single Effective::Asset. Calling @user.pictures will return an array (relation) of Effective::Assets
164
+ Calling `user.avatar` will return a single `Effective::Asset`. Calling `user.photos` will return an array of `Effective::Assets`.
165
+
166
+ Then to get the URL of an asset:
167
+
168
+ ```ruby
169
+ asset = user.avatar
170
+ => an Effective::Asset
171
+
172
+ asset.url
173
+ => "http://aws_bucket.s3.amazonaws.com/assets/1/my_avatar.png"
174
+
175
+ asset.url(:thumb) # See image versions (below)
176
+ => "http://aws_bucket.s3.amazonaws.com/assets/1/thumb_my_avatar.png"
85
177
 
86
- To use with validations:
178
+ user.photos
179
+ => [Effective::Asset<1>, Effective::Asset<2>] # An array of Effective::Asset objects
180
+ ```
181
+
182
+ ### Validations
87
183
 
88
184
  ```ruby
89
185
  class User
90
- acts_as_asset_box :fav_icon => true, :pictures => false, :videos => 2, :images => 5..10
186
+ acts_as_asset_box :avatar => true, :photos => false, :videos => 2, :mp3s => 5..10
91
187
  end
92
188
  ```
93
189
 
94
- The user in this example is only valid if exists a fav_icon, 2 videos, and 5..10 images.
190
+ true means presence, false means no validations applied.
191
+
192
+ The user in this example is only valid if exists an avatar, 2 videos, and 5..10 mp3s.
193
+
194
+ ### Form Input
195
+
196
+ There is a standard rails form input:
197
+
198
+ ```ruby
199
+ = form_for @user do |f|
200
+ = f.asset_box_input :pictures
201
+ ```
202
+
203
+ A SimpleForm input:
204
+
205
+ ```ruby
206
+ = simple_form_for @user do |f|
207
+ = f.input :pictures, :as => :asset_box
208
+ ```
209
+
210
+ and a Formtastic input:
211
+
212
+ ```ruby
213
+ = semantic_form_for @user do |f|
214
+ = f.input :pictures, :as => :asset_box
215
+ ```
216
+
217
+ The `:as => :asset_box` will work interchangeably with SimpleForm or Formtastic, as long as only one of these gems is present in your application.
218
+
219
+ If you use both SimpleForm and Formtastic, you will need to call asset_box_input differently:
220
+
221
+ ```ruby
222
+ = simple_form_for @user do |f|
223
+ = f.input :pictures, :as => :asset_box_simple_form
224
+
225
+ = semantic_form_for @user do |f|
226
+ = f.input :pictures, :as => :asset_box_formtastic
227
+ ```
228
+
95
229
 
96
230
  ### Uploading & Attaching
97
231
 
98
- Use the custom formtastic input for uploading (direct to S3) and attaching assets to the 'pictures' box.
232
+ Use the custom form input for uploading (direct to S3) and attaching assets to the `pictures` box.
99
233
 
100
234
  ```ruby
101
235
  = f.input :pictures, :as => :asset_box, :uploader => true
102
- = f.input :videos, :as => :asset_box, :limit => 2, :file_types => [:jpg, :gif, :png]
103
- = f.input :logo, :as => :asset_box, :uploader => true, :uploader_visible => true # Show the uploader right away
236
+
237
+ = f.input :pictures, :as => :asset_box, :limit => 2, :file_types => [:jpg, :gif, :png]
238
+
239
+ = f.input :pictures, :as => :asset_box, :dialog => true, :dialog_url => '/admin/effective_assets' # Use the attach dialog
240
+ ```
241
+
242
+ You may also upload secure (AWS: 'authenticated-read') assets with the same uploader
243
+
244
+ ```ruby
245
+ = f.input :pictures, :as => :asset_box, :aws_acl => 'authenticated-read'
246
+ ```
247
+
248
+ There is also a mechanism for collecting additional information from the upload form which will be set in the `asset.extra` field.
249
+
250
+ ```ruby
251
+ = semantic_form_for Product.new do |f|
252
+ = f.input :photos, :as => :asset_box
253
+ = f.semantic_fields_for :photos do |pf|
254
+ = pf.input :field1, :as => :string
255
+ = pf.input :field2, :as => :boolean
104
256
  ```
105
257
 
258
+ Here the semantic_fields_for will create some inputs with name
259
+
260
+ ```ruby
261
+ product[photos][field1]
262
+ product[photos][field2]
263
+ ```
264
+
265
+ Any additional field like this will be passed to the Asset and populate the `extra` Hash attribute
266
+
106
267
  Note: Passing :limit => 2 will have no effect on a singular asset_box, which by definition has a limit of 1.
107
268
 
108
- We use the s3_swf_upload gem for direct-to-s3 uploading. The process is as follows:
269
+ We use the jQuery-File-Upload gem for direct-to-s3 uploading. The process is as follows:
109
270
 
110
- - User sees the form and clicks Browse. Selects 1 or more files, then clicks Start Uploading
111
- - The s3_uploader reads configuration options from effective_assets.rb initializer, and connects to S3
112
- - The file is uploaded directly to its 'final' resting place.
113
- - A post is then made back to the effective#s3_uploads_controller which creates the Asset object and sets up a task in DelayedJob to process the asset (for image resizing)
114
- - An attachment is created, which joins the Asset to the parent Object (User in our example) in the appropriate position.
115
- - The DelayedJob task should be running and will handle any image resizing as defined by the AssetUploader
271
+ - User sees the form and clicks Browse. Selects 1 or more files, then clicks Start Uploading.
272
+ - The server makes a post to the S3UploadsController#create action to initialize an asset, and get a unique ID
273
+ - The file is uploaded directly to its 'final' resting place on S3 via Javascript uploader at `assets/:id/:filename`
274
+ - A PUT is then made back to the S3UploadsController#update which updates the `Effective::Asset` object and sets up a task in `DelayedJob` to process the asset (for image resizing)
275
+ - An `Effective::Attachment` is created, which joins the `Effective::Asset` to the parent Object (`User` in our example) in the appropriate position.
276
+ - The `DelayedJob` task should be running and will handle any image resizing as defined by the `AssetUploader`.
116
277
  - The asset will appear in the form, and the user may click&drag the asset around to set the position.
117
278
 
118
- ### Authorization
119
279
 
120
- All authorization checks are handled via the config.authorization_method found in the effective_assets.rb initializer.
280
+ ### Strong Parameters
121
281
 
122
- It is intended for flow through to CanCan, but that is not required.
123
-
124
- The authorization method can be defined as:
282
+ Make your controller aware of the acts_as_asset_box passed parameters:
125
283
 
126
284
  ```ruby
127
- EffectiveAssets.setup do |config|
128
- config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
285
+ def permitted_params
286
+ params.require(:base_object).permit(EffectiveAssets.permitted_params)
129
287
  end
130
288
  ```
131
289
 
132
- or as a method:
290
+ The permitted parameters are:
133
291
 
134
292
  ```ruby
135
- EffectiveAssets.setup do |config|
136
- config.authorization_method = :authorize_effective_assets
137
- end
293
+ :attachments_attributes => [:id, :asset_id, :attachable_type, :attachable_id, :position, :box, :_destroy]
294
+ ```
295
+
296
+
297
+ ### Image Processing and Resizing
298
+
299
+ CarrierWave and DelayedJob are used by this gem to perform image versioning.
300
+
301
+ This will be moved over to the new ActiveJob API in future versions of this gem, but right now DelayedJob is the only supported background worker.
302
+
303
+ See the installer created at `app/uploaders/asset_uploader.rb` to configure image versions.
304
+
305
+ Use the `process :record_info => :thumb` directive to store image version dimensions and file sizes.
306
+
307
+ When this uploader file is changed, you must reprocess any existing `Effective::Asset` objects to recreate all image versions.
308
+
309
+ This one-liner downloads the original file from AWS S3, creates the image versions locally using imagemagick, then uploads each version to its final resting place back on AWS S3.
310
+
311
+ ```ruby
312
+ Effective::Asset.find(123).reprocess!
313
+ => true
314
+ ```
315
+
316
+ This can be done in batch using the built in rake script (see below).
317
+
318
+ ### Helpers
319
+
320
+ You can always get the URL directly
321
+
322
+ ```ruby
323
+ current_user.avatar.url(:thumb)
324
+ ```
325
+
326
+ To display the asset as a link with an image (if its an image, or a mime-type appropriate icon if its not an image):
327
+
328
+ ```ruby
329
+ # Asset is the @user.fav_icon
330
+ # version is anything you set up in your uploaders/asset_uploader.rb as versions. :thumb
331
+ # Options are passed through to a call to rails image_tag helper
332
+ effective_asset_image_tag(asset, version = nil, options = {})
333
+ ```
334
+
335
+ To display the asset as a link with no image:
336
+
337
+ ```ruby
338
+ # Options are passed through to rails link_to helper
339
+ effective_asset_link_to(asset, version = nil, options = {})
340
+ ```
341
+
342
+ ## Authorization
343
+
344
+ All authorization checks are handled via the config.authorization_method found in the config/initializers/ file.
345
+
346
+ It is intended for flow through to CanCan or Pundit, but that is not required.
347
+
348
+ This method is called by all controller actions with the appropriate action and resource
349
+
350
+ Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
351
+
352
+ Resource will the appropriate Effective::Something ActiveRecord object or class
353
+
354
+ The authorization method is defined in the initializer file:
355
+
356
+ ```ruby
357
+ # As a Proc (with CanCan)
358
+ config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
359
+ ```
360
+
361
+ ```ruby
362
+ # As a Custom Method
363
+ config.authorization_method = :my_authorization_method
138
364
  ```
139
365
 
140
366
  and then in your application_controller.rb:
141
367
 
142
368
  ```ruby
143
- def authorize_effective_assets(action, resource)
144
- can?(action, resource)
369
+ def my_authorization_method(action, resource)
370
+ current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
145
371
  end
146
372
  ```
147
373
 
148
- The action will be one of :read, :create, :update, :destroy, :manage
149
- The resource will generally be the @asset, but in the case of :manage, it is Effective::Asset class.
374
+ or disabled entirely:
150
375
 
151
- If the method or proc returns false (user is not authorized) an ActiveResource::UnauthorizedAccess exception will be raised
376
+ ```ruby
377
+ config.authorization_method = false
378
+ ```
379
+
380
+ If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
152
381
 
153
- You can rescue from this exception by adding the following to your application_controller.rb
382
+ You can rescue from this exception by adding the following to your application_controller.rb:
154
383
 
155
384
  ```ruby
156
- rescue_from ActiveResource::UnauthorizedAccess do |exception|
385
+ rescue_from Effective::AccessDenied do |exception|
157
386
  respond_to do |format|
158
387
  format.html { render 'static_pages/access_denied', :status => 403 }
159
388
  format.any { render :text => 'Access Denied', :status => 403 }
@@ -161,50 +390,76 @@ rescue_from ActiveResource::UnauthorizedAccess do |exception|
161
390
  end
162
391
  ```
163
392
 
164
- ### Image Processing and Resizing
393
+ ### Permissions
394
+
395
+ To allow user uploads, using Cancan:
165
396
 
166
- CarrierWave is used under the covers to do all the image resizing.
167
- The installer created an uploaders/asset_uploader.rb which you can use to set up versions.
397
+ ```ruby
398
+ can [:create, :update, :destroy], Effective::Asset, :user_id => user.id
399
+ ```
168
400
 
169
- Some additional processing goes on to record final image dimensions and file sizes.
170
401
 
402
+ ## Rake Tasks
171
403
 
172
- ### Helpers
404
+ Use the following rake tasks to aid in batch processing a large number of (generally image) files.
173
405
 
174
- To just get the URL of an asset
406
+ ### Reprocess
407
+
408
+ If the `app/uploaders/asset_uploader.rb` file is changed, run the following rake task to reprocess all `Effective::Asset` objects and thereby recreate all image versions
175
409
 
176
410
  ```ruby
177
- @asset = @user.fav_icon
178
- @asset.url
179
- => "http://aws_bucket.s3.amazonaws.com/assets/1/my_favorite_icon.png
411
+ rake effective_assets:reprocess # All assets
412
+ rake effective_assets:reprocess[200] # reprocess #200 and up
413
+ rake effective_assets:reprocess[1,200] # reprocess #1..#200
180
414
  ```
181
415
 
182
- To display the asset as a link with an image (if its an image, or a mime-type appropriate icon if its not an image):
416
+ This command enqueues a `.reprocess!` job for each `Effective::Asset` on the `DelayedJob` queue.
417
+
418
+ If a `DelayedJob` worker process is already running, the reprocessing will begin immediately, otherwise start one with
183
419
 
184
420
  ```ruby
185
- # Asset is the @user.fav_icon
186
- # version is anything you set up in your uploaders/asset_uploader.rb as versions. :thumb
187
- # Options are passed through to a call to rails image_tag helper
188
- effective_asset_image_tag(asset, version = nil, options = {})
421
+ rake jobs:work
189
422
  ```
190
423
 
191
- To display the asset as a link with no image
424
+ ### Check
425
+
426
+ Checks every `Effective::Asset` and all its versions for a working URL (200 http status code).
427
+
428
+ Any non-200 http responses are logged as an error.
429
+
430
+ This is a sanity-check task, that makes sure every url for every asset and version is going to work.
431
+
432
+ This is just single-threaded one process.
433
+
434
+ If you need to check a large number of urls, use multiple rake tasks and pass in ID ranges. Sorry.
192
435
 
193
436
  ```ruby
194
- # Options are passed through to rails link_to helper
195
- effective_asset_link_to(asset, version = nil, options = {})
437
+ rake effective_assets:check # check that every version of every Effective::Asset is a valid http 200 OK url
438
+ rake effective_assets:check[200] # check #200 and up
439
+ rake effective_assets:check[1,200] # check #1..#200
440
+ rake effective:assets:check[1,200,:thumb] # check #1..#200 only :thumb versions
196
441
  ```
197
442
 
198
- ### Integration
443
+ ### Clear
444
+
445
+ Deletes all effective_assets related jobs on the DelayedJob queue.
199
446
 
200
- The 'Insert Asset' functionality from this gem is used in effective_mercury and effective_rte
447
+ ```ruby
448
+ rake effective_assets:clear
449
+ ```
201
450
 
451
+ or to clear all jobs, even non-effective_assets related jobs, use DelayedJob's rake task:
452
+
453
+ ```ruby
454
+ rake jobs:clear
455
+ ```
202
456
 
203
457
  ## License
204
458
 
205
- MIT License. Copyright Code and Effect Inc. http://www.codeandeffect.com
459
+ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
460
+
461
+ Code and Effect is the product arm of [AgileStyle](http://www.agilestyle.com/), an Edmonton-based shop that specializes in building custom web applications with Ruby on Rails.
206
462
 
207
- You are not granted rights or licenses to the trademarks of Code and Effect
208
463
 
209
464
  ## Credits
210
465
 
@@ -214,15 +469,29 @@ CarrierWave (https://github.com/carrierwaveuploader/carrierwave)
214
469
 
215
470
  DelayedJob (https://github.com/collectiveidea/delayed_job)
216
471
 
217
- swf_s3_upload (https://github.com/nathancolgate/s3-swf-upload-plugin)
472
+ jQuery-File-Upload (https://github.com/blueimp/jQuery-File-Upload)
473
+
218
474
 
475
+ ## Testing
219
476
 
220
- ### Testing
477
+ Testing uses the Combustion gem, for easier Rails Engine Testing.
221
478
 
222
- The test suite for this gem is unfortunately not yet complete.
479
+ https://github.com/pat/combustion
223
480
 
224
- Run tests by:
481
+ You will need a valid initializer in spec/internal/config/initializers/effective_assets.rb
482
+
483
+ Run tests by
225
484
 
226
485
  ```ruby
227
- rake spec
486
+ bundle exec guard
228
487
  ```
488
+
489
+ ## Contributing
490
+
491
+ 1. Fork it
492
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
493
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
494
+ 4. Push to the branch (`git push origin my-new-feature`)
495
+ 5. Bonus points for test coverage
496
+ 6. Create new Pull Request
497
+