assetable 0.1.10 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/README.rdoc +9 -7
  3. data/app/assets/javascripts/assetable/assetable.js.coffee +16 -0
  4. data/app/assets/javascripts/assetable/assetable_uploader.js.coffee +40 -118
  5. data/app/assets/javascripts/assetable/gallery.js.coffee +12 -10
  6. data/app/assets/javascripts/assetable/uploader.js.coffee +27 -11
  7. data/app/assets/javascripts/vendor/jquery-ui-1.10.3.custom.js +285 -19
  8. data/app/assets/stylesheets/assetable/components/_gallery.css.sass +31 -0
  9. data/app/assets/stylesheets/assetable/components/_uploader.css.sass +2 -2
  10. data/app/assets/stylesheets/assetable/core/_utilities.css.sass +5 -1
  11. data/app/controllers/assetable/assets_controller.rb +19 -10
  12. data/app/controllers/assetable/external_services_controller.rb +9 -5
  13. data/app/helpers/assetable/asset_helper.rb +7 -0
  14. data/app/inputs/gallery_input.rb +28 -0
  15. data/app/inputs/uploader_input.rb +24 -0
  16. data/app/models/asset_attachment.rb +27 -0
  17. data/app/models/gallery.rb +3 -1
  18. data/app/views/assetable/assets/_asset.html.haml +30 -21
  19. data/app/views/assetable/assets/_directions.html.haml +9 -0
  20. data/app/views/assetable/assets/_form.html.haml +3 -5
  21. data/app/views/assetable/assets/_table.html.haml +22 -0
  22. data/app/views/assetable/assets/create.js.erb +7 -0
  23. data/app/views/assetable/assets/edit.js.erb +1 -0
  24. data/app/views/assetable/assets/index.js.erb +18 -0
  25. data/app/views/assetable/assets/insert.js.erb +9 -0
  26. data/app/views/assetable/assets/update.js.erb +2 -0
  27. data/app/views/assetable/external_services/_form.html.haml +3 -2
  28. data/app/views/assetable/external_services/create.js.erb +9 -0
  29. data/app/views/assetable/external_services/new.js.erb +1 -0
  30. data/app/views/assetable/shared/_asset_preview.html.haml +21 -0
  31. data/app/views/assetable/shared/templates/_asset_item.html.haml +29 -0
  32. data/app/views/assetable/shared/templates/_gallery_item.html.haml +42 -0
  33. data/config/initializers/uploader_input.rb +1 -1
  34. data/config/routes.rb +3 -1
  35. data/db/migrate/20140220053656_add_sort_order_to_asset_attachments.rb +15 -0
  36. data/lib/assetable.rb +6 -3
  37. data/lib/assetable/{core.rb → active_record/base.rb} +2 -2
  38. data/lib/assetable/inputs/uploaders.rb +27 -0
  39. data/lib/assetable/version.rb +1 -1
  40. metadata +40 -10
  41. data/app/views/assetable/assets/edit.html.haml +0 -1
  42. data/app/views/assetable/external_services/new.html.haml +0 -1
@@ -0,0 +1,9 @@
1
+ var uploader = $('#<%= @uploader_id %>');
2
+
3
+ if (uploader.hasClass("gallery-uploader")) {
4
+ $('#<%= @uploader_id %>').find('.uploader-assets-wrapper').append('<%= j render partial: "assetable/shared/templates/gallery_item", locals: { asset: @external_service, fieldname: @fieldname } %>');
5
+ } else {
6
+ $('#<%= @uploader_id %>').find('.uploader-assets-wrapper').html('<%= j render partial: "assetable/shared/templates/asset_item", locals: { asset: @external_service, fieldname: @fieldname } %>');
7
+ };
8
+
9
+ $('.assetable-external-services').modal('hide').remove();
@@ -0,0 +1 @@
1
+ $('<%= j render partial: 'form', locals: {external_service: @external_service, fieldname: @fieldname, uploader_id: @uploader_id} %>').modal();
@@ -0,0 +1,21 @@
1
+ .uploader-asset-details
2
+ = link_to asset.filename.to_s, target: "_blank" do
3
+ - if asset.image?
4
+ = image_tag asset.filename.preview.to_s, class: "uploader-preview"
5
+ - elsif asset.document?
6
+ = image_tag "assetable/icons/icon-#{asset.extension}.png", class: "uploader-preview"
7
+ - elsif asset.video?
8
+ = image_tag "assetable/icons/icon-mp4.png", class: "uploader-preview"
9
+ - elsif asset.external_service?
10
+ - if asset.has_icon?
11
+ = image_tag "assetable/icons/#{asset.icon}", class: "uploader-preview"
12
+ - else
13
+ = image_tag "assetable/icons/icon-document.png", class: "uploader-preview"
14
+
15
+ %span.uploader-name= asset.name
16
+ .uploader-size-and-actions
17
+ %span.uploader-size= number_to_human_size(asset.file_size)
18
+
19
+ .uploader-actions
20
+ = link_to "delete", "#", class: "btn-uploader btn-uploader-remove-asset"
21
+ = link_to "edit", Rails.application.routes.url_helpers.edit_assetable_asset_path(asset.id), class: "btn-uploader btn-uploader-edit-asset", remote: true
@@ -0,0 +1,29 @@
1
+ - if asset.present?
2
+ .uploader-preview{:'data-asset-id' => asset.id}
3
+ .uploader-asset-details
4
+ = link_to asset.filename.to_s, target: "_blank" do
5
+ - if asset.image?
6
+ = image_tag asset.filename.preview.to_s, class: "uploader-preview"
7
+ - elsif asset.document?
8
+ = image_tag "assetable/icons/icon-#{asset.extension}.png", class: "uploader-preview"
9
+ - elsif asset.video?
10
+ = image_tag "assetable/icons/icon-mp4.png", class: "uploader-preview"
11
+ - elsif asset.external_service?
12
+ - if asset.has_icon?
13
+ = image_tag "assetable/icons/#{asset.icon}", class: "uploader-preview"
14
+ - else
15
+ = image_tag "assetable/icons/icon-document.png", class: "uploader-preview"
16
+
17
+ %span.uploader-name= asset.name
18
+ .uploader-size-and-actions
19
+ %span.uploader-size= number_to_human_size(asset.file_size)
20
+
21
+ .uploader-actions
22
+ = link_to "delete", "#", class: "btn-uploader btn-uploader-remove-asset"
23
+ = link_to "edit", Rails.application.routes.url_helpers.edit_assetable_asset_path(asset.id), class: "btn-uploader btn-uploader-edit-asset", remote: true
24
+
25
+ - if local_assigns.has_key? :fieldname
26
+ = hidden_field_tag(fieldname, asset.id, id: nil)
27
+
28
+ - else
29
+ .uploader-preview
@@ -0,0 +1,42 @@
1
+ - if asset.present?
2
+ .uploader-preview{:'data-asset-id' => asset.id}
3
+ .uploader-asset-details
4
+ = link_to asset.filename.to_s, target: "_blank" do
5
+ - if asset.image?
6
+ = image_tag asset.filename.preview.to_s, class: "uploader-preview"
7
+ - elsif asset.document?
8
+ = image_tag "assetable/icons/icon-#{asset.extension}.png", class: "uploader-preview"
9
+ - elsif asset.video?
10
+ = image_tag "assetable/icons/icon-mp4.png", class: "uploader-preview"
11
+ - elsif asset.external_service?
12
+ - if asset.has_icon?
13
+ = image_tag "assetable/icons/#{asset.icon}", class: "uploader-preview"
14
+ - else
15
+ = image_tag "assetable/icons/icon-document.png", class: "uploader-preview"
16
+
17
+ %span.uploader-name= asset.name
18
+ .uploader-size-and-actions
19
+ %span.uploader-size= number_to_human_size(asset.file_size)
20
+
21
+ .uploader-actions
22
+ = link_to "delete", "#", class: "btn-uploader btn-uploader-remove-asset"
23
+ = link_to "edit", Rails.application.routes.url_helpers.edit_assetable_asset_path(asset.id), class: "btn-uploader btn-uploader-edit-asset", remote: true
24
+
25
+ - if local_assigns.has_key? :fieldname
26
+
27
+ - assetable_index = local_assigns.has_key?(:index) ? index : Time.now.to_i
28
+ - if local_assigns.has_key? :asset_attachment
29
+ - asset_attachment_id = asset_attachment.id
30
+ - asset_attachment_sort_order = asset_attachment.sort_order
31
+ - else
32
+ - asset_attachment_id = nil
33
+ - asset_attachment_sort_order = nil
34
+
35
+ / - id = asset_attachment.id.present? ? asset_attachment.id : Time.now.to_i
36
+ = hidden_field_tag("#{fieldname}[#{assetable_index}][id]", asset_attachment_id, id: nil)
37
+ = hidden_field_tag("#{fieldname}[#{assetable_index}][sort_order]", asset_attachment_sort_order, class: "assetable-gallery-item-sort-order")
38
+ = hidden_field_tag("#{fieldname}[#{assetable_index}][asset_id]", asset.id)
39
+ = hidden_field_tag("#{fieldname}[#{assetable_index}][_destroy]", "0", class: "assetable-gallery-item-remove")
40
+
41
+ - else
42
+ .uploader-preview
@@ -27,7 +27,7 @@ class ActionView::Helpers::FormBuilder
27
27
  end
28
28
 
29
29
  # uploaer html with preview and input
30
- uploader_html = content_tag(:div, (asset_preview), class: "uploader-data-wrapper")
30
+ uploader_html = content_tag(:div, (asset_preview), class: "uploader-assets-wrapper")
31
31
 
32
32
  # Create and return the uploader html
33
33
  uploader_wrapper = content_tag(:div, uploader_html, class: "uploader #{'uploader-has-asset' if asset} #{options[:class]}", id: options[:id], :'data-uploader-input-name' => fieldname, :'data-uploader-directions' => get_directions(options), :'data-max-file-size' => get_max_file_size(options))
@@ -1,7 +1,9 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
3
  namespace :assetable do
4
- resources :assets
4
+ resources :assets do
5
+ post :insert, on: :collection
6
+ end
5
7
  resources :external_services
6
8
  end
7
9
 
@@ -0,0 +1,15 @@
1
+ class AddSortOrderToAssetAttachments < ActiveRecord::Migration
2
+ def change
3
+ add_column :asset_attachments, :sort_order, :integer, default: 0
4
+
5
+ AssetAttachment.reset_column_information
6
+
7
+ Gallery.all.each do |gallery|
8
+ if gallery.asset_attachments.present?
9
+ gallery.asset_attachments.each_with_index do |attachment, index|
10
+ attachment.update_attribute(:sort_order, index)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,18 +1,21 @@
1
1
  require "carrierwave"
2
2
  require "fog"
3
- require "plupload-rails"
4
3
  require "kaminari"
4
+ require "plupload-rails"
5
+ require "simple_form"
5
6
 
6
7
  require "haml-rails"
7
8
  require "sass-rails"
8
9
  require "jquery-rails"
9
10
 
10
- require "assetable/core"
11
11
  require "assetable/engine"
12
12
  require "assetable/config"
13
13
 
14
+ require "assetable/active_record/base"
15
+ require "assetable/inputs/uploaders"
16
+
14
17
  module Assetable
15
-
18
+
16
19
  extend Config
17
20
 
18
21
  end
@@ -1,5 +1,5 @@
1
1
  module Assetable
2
- module Core
2
+ module Base
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
@@ -38,4 +38,4 @@ module Assetable
38
38
  end
39
39
  end
40
40
 
41
- ActiveRecord::Base.send :include, Assetable::Core
41
+ ActiveRecord::Base.send :include, Assetable::Base
@@ -0,0 +1,27 @@
1
+ module Assetable::Uploaders
2
+
3
+ # Gallery preview is a set of assets. Let's loop over the assets in the
4
+ # gallery and create a preview for each.
5
+ def gallery_preview fieldname
6
+ if modal_gallery = object.send("#{attribute_name}")
7
+ gallery = ""
8
+
9
+ # modal_gallery.assets.each do |asset|
10
+ modal_gallery.asset_attachments.each_with_index do |asset_attachment, index|
11
+ # gallery += asset_preview(asset, :gallery, fieldname)
12
+ gallery += ActionController::Base.new.send(:render_to_string, partial: "assetable/shared/templates/gallery_item", locals: { asset: asset_attachment.asset, asset_attachment: asset_attachment, fieldname: fieldname, index: index })
13
+ end
14
+
15
+ gallery
16
+ end
17
+ end
18
+
19
+ def asset_preview asset, type=:asset, fieldname=nil
20
+ ActionController::Base.new.send(:render_to_string, partial: "assetable/shared/templates/#{type.downcase.to_s}_item", locals: { asset: asset, fieldname: fieldname })
21
+ end
22
+
23
+ def directions_html
24
+ ActionController::Base.new.send(:render_to_string, :partial => 'assetable/assets/directions')
25
+ end
26
+
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Assetable
2
- VERSION = "0.1.10"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assetable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Koht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ! '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: kaminari
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rmagick
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +207,7 @@ dependencies:
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
- name: kaminari
210
+ name: simple_form
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
213
  - - ! '>='
@@ -207,7 +221,7 @@ dependencies:
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
209
223
  - !ruby/object:Gem::Dependency
210
- name: haml-rails
224
+ name: coffee-rails
211
225
  requirement: !ruby/object:Gem::Requirement
212
226
  requirements:
213
227
  - - ! '>='
@@ -221,7 +235,7 @@ dependencies:
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
- name: sass-rails
238
+ name: haml-rails
225
239
  requirement: !ruby/object:Gem::Requirement
226
240
  requirements:
227
241
  - - ! '>='
@@ -235,7 +249,7 @@ dependencies:
235
249
  - !ruby/object:Gem::Version
236
250
  version: '0'
237
251
  - !ruby/object:Gem::Dependency
238
- name: coffee-rails
252
+ name: jquery-rails
239
253
  requirement: !ruby/object:Gem::Requirement
240
254
  requirements:
241
255
  - - ! '>='
@@ -249,7 +263,7 @@ dependencies:
249
263
  - !ruby/object:Gem::Version
250
264
  version: '0'
251
265
  - !ruby/object:Gem::Dependency
252
- name: jquery-rails
266
+ name: sass-rails
253
267
  requirement: !ruby/object:Gem::Requirement
254
268
  requirements:
255
269
  - - ! '>='
@@ -295,6 +309,7 @@ files:
295
309
  - app/assets/images/assetable/icons/icon-xml.png
296
310
  - app/assets/images/assetable/icons/icon-zip.png
297
311
  - app/assets/javascripts/assetable/asset_gallery.js.coffee
312
+ - app/assets/javascripts/assetable/assetable.js.coffee
298
313
  - app/assets/javascripts/assetable/assetable_uploader.js.coffee
299
314
  - app/assets/javascripts/assetable/gallery.js.coffee
300
315
  - app/assets/javascripts/assetable/uploader.js.coffee
@@ -314,6 +329,9 @@ files:
314
329
  - app/assets/stylesheets/assetable/core/_variables.css.sass
315
330
  - app/controllers/assetable/assets_controller.rb
316
331
  - app/controllers/assetable/external_services_controller.rb
332
+ - app/helpers/assetable/asset_helper.rb
333
+ - app/inputs/gallery_input.rb
334
+ - app/inputs/uploader_input.rb
317
335
  - app/models/asset.rb
318
336
  - app/models/asset_attachment.rb
319
337
  - app/models/document.rb
@@ -326,11 +344,21 @@ files:
326
344
  - app/uploaders/image_uploader.rb
327
345
  - app/uploaders/video_uploader.rb
328
346
  - app/views/assetable/assets/_asset.html.haml
347
+ - app/views/assetable/assets/_directions.html.haml
329
348
  - app/views/assetable/assets/_form.html.haml
330
349
  - app/views/assetable/assets/_gallery.html.haml
331
- - app/views/assetable/assets/edit.html.haml
350
+ - app/views/assetable/assets/_table.html.haml
351
+ - app/views/assetable/assets/create.js.erb
352
+ - app/views/assetable/assets/edit.js.erb
353
+ - app/views/assetable/assets/index.js.erb
354
+ - app/views/assetable/assets/insert.js.erb
355
+ - app/views/assetable/assets/update.js.erb
332
356
  - app/views/assetable/external_services/_form.html.haml
333
- - app/views/assetable/external_services/new.html.haml
357
+ - app/views/assetable/external_services/create.js.erb
358
+ - app/views/assetable/external_services/new.js.erb
359
+ - app/views/assetable/shared/_asset_preview.html.haml
360
+ - app/views/assetable/shared/templates/_asset_item.html.haml
361
+ - app/views/assetable/shared/templates/_gallery_item.html.haml
334
362
  - config/initializers/carrierwave.rb
335
363
  - config/initializers/gallery_input.rb
336
364
  - config/initializers/uploader_input.rb
@@ -339,9 +367,11 @@ files:
339
367
  - db/migrate/20131123172825_create_asset_attachments.rb
340
368
  - db/migrate/20131125200943_create_galleries.rb
341
369
  - db/migrate/20140121173312_add_ratio_to_assets.rb
370
+ - db/migrate/20140220053656_add_sort_order_to_asset_attachments.rb
371
+ - lib/assetable/active_record/base.rb
342
372
  - lib/assetable/config.rb
343
- - lib/assetable/core.rb
344
373
  - lib/assetable/engine.rb
374
+ - lib/assetable/inputs/uploaders.rb
345
375
  - lib/assetable/version.rb
346
376
  - lib/assetable.rb
347
377
  - lib/tasks/assetable_tasks.rake
@@ -1 +0,0 @@
1
- = render 'form'
@@ -1 +0,0 @@
1
- = render 'form'