media_magick 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.travis.yml +7 -3
- data/CHANGELOG.md +92 -1
- data/README.md +1 -1
- data/app/assets/javascripts/media_magick/plupload_it.js +30 -9
- data/app/controllers/media_magick/attach_controller.rb +16 -28
- data/app/helpers/media_magick/application_helper.rb +46 -5
- data/app/views/_file.html.erb +2 -2
- data/app/views/_image.html.erb +3 -3
- data/app/views/_upload.html.erb +3 -10
- data/app/views/_video.html.erb +8 -0
- data/gemfiles/mongoid-3.0.gemfile +7 -0
- data/lib/media_magick.rb +1 -5
- data/lib/media_magick/controller/helpers.rb +20 -0
- data/lib/media_magick/engine.rb +1 -1
- data/lib/media_magick/model.rb +41 -48
- data/lib/media_magick/version.rb +1 -1
- data/lib/media_magick/video/parser.rb +62 -0
- data/media_magick.gemspec +8 -4
- data/spec/controllers/media_magick/attach_controller_spec.rb +12 -11
- data/spec/dummy/app/assets/javascripts/application.js +5 -0
- data/spec/dummy/app/assets/javascripts/posts.js +2 -0
- data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +83 -0
- data/spec/dummy/app/helpers/posts_helper.rb +2 -0
- data/spec/dummy/app/models/album.rb +3 -1
- data/spec/dummy/app/models/post.rb +10 -0
- data/spec/dummy/app/models/track.rb +1 -0
- data/spec/dummy/app/uploaders/post_uploader.rb +17 -0
- data/spec/dummy/app/views/posts/_form.html.erb +47 -0
- data/spec/dummy/app/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/views/posts/index.html.erb +25 -0
- data/spec/dummy/app/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/views/posts/show.html.erb +15 -0
- data/spec/dummy/app/views/users/index.html.erb +1 -1
- data/spec/dummy/config/mongoid.yml +65 -17
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/helpers/media_magick/application_helper_spec.rb +90 -27
- data/spec/integration/images_spec.rb +1 -1
- data/spec/lib/media_magick/controller/helper_spec.rb +37 -0
- data/spec/lib/media_magick/model_spec.rb +41 -9
- data/spec/lib/media_magick/video/parser_spec.rb +67 -0
- data/spec/spec_helper.rb +11 -8
- data/spec/views/_upload.html.erb_spec.rb +26 -0
- metadata +76 -21
- data/.rvmrc +0 -1
- data/spec/dummy/app/helpers/users_helper.rb +0 -2
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9.2
|
4
3
|
- 1.9.3
|
5
|
-
|
4
|
+
|
5
|
+
services: mongodb
|
6
|
+
|
6
7
|
notifications:
|
7
8
|
email:
|
8
9
|
- contato@lucasrenan.com
|
9
10
|
- rbrancher@gmail.com
|
10
11
|
- tiagogodinho3@gmail.com
|
11
|
-
|
12
|
+
|
13
|
+
gemfile:
|
14
|
+
- Gemfile
|
15
|
+
- gemfiles/mongoid-3.0.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,90 @@
|
|
1
|
+
## Next Release (branch: master)
|
2
|
+
|
3
|
+
### Improvements
|
4
|
+
|
5
|
+
* Adding support to videos.
|
6
|
+
|
7
|
+
Model:
|
8
|
+
|
9
|
+
``` rb
|
10
|
+
class Album
|
11
|
+
include Mongoid::Document
|
12
|
+
include MediaMagick::Model
|
13
|
+
|
14
|
+
attaches_many :medias, allow_videos: true
|
15
|
+
end
|
16
|
+
|
17
|
+
album = Album.create
|
18
|
+
album.medias.create(video: 'youtube.com/watch?v=FfUHkPf9D9k')
|
19
|
+
album.reload.photos.first.url
|
20
|
+
album.reload.photos.first.filename
|
21
|
+
|
22
|
+
# Specific methods
|
23
|
+
|
24
|
+
album.reload.medias.first.type #=> 'video'
|
25
|
+
album.reload.medias.first.video #=> 'youtube.com/watch?v=FfUHkPf9D9k'
|
26
|
+
album.reload.medias.first.source #=> <iframe>youtube video</iframe>
|
27
|
+
```
|
28
|
+
|
29
|
+
View:
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
attachment_container_for_video @album, :files
|
33
|
+
```
|
34
|
+
|
35
|
+
* Adding support to Mongoid 3.
|
36
|
+
|
37
|
+
### Major Changes (Backwards Incompatible)
|
38
|
+
|
39
|
+
* Media Magick no longer supports Ruby 1.8.7.
|
40
|
+
|
41
|
+
* Adding the `as` option in `attachment_container` to define the partial to be rendered
|
42
|
+
|
43
|
+
After:
|
44
|
+
|
45
|
+
``` rb
|
46
|
+
class Album
|
47
|
+
include Mongoid::Document
|
48
|
+
include MediaMagick::Model
|
49
|
+
|
50
|
+
attaches_many :files, type: 'file'
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
Now:
|
55
|
+
|
56
|
+
``` rb
|
57
|
+
attachment_container @album, :files, as: 'file'
|
58
|
+
```
|
59
|
+
|
60
|
+
* Now **newAttachments** and **loadedAttachments** are options for `attachment_container`
|
61
|
+
|
62
|
+
After:
|
63
|
+
|
64
|
+
``` rb
|
65
|
+
attachment_container @album, :photos, { class: 'thumbnails' }, { class: 'span3' }, partial: 'albums/photo'
|
66
|
+
|
67
|
+
# without newAttachments and loadedAttachments
|
68
|
+
attachment_container @album, :photos, {}, {}, partial: 'albums/photo'
|
69
|
+
```
|
70
|
+
|
71
|
+
Now:
|
72
|
+
|
73
|
+
``` rb
|
74
|
+
attachment_container @album, :photos, newAttachments: { class: 'thumbnails' }, loadedAttachments: { class: 'span3' }, partial: 'albums/photo'
|
75
|
+
|
76
|
+
# without newAttachments and loadedAttachments
|
77
|
+
attachment_container @album, :photos, partial: 'albums/photo'
|
78
|
+
```
|
79
|
+
|
80
|
+
* `MediaMagick::Model#attachs_many` has been removed in favor of `attaches_many`.
|
81
|
+
|
82
|
+
* Removing related relations and the ability to create an image without a father.
|
83
|
+
|
84
|
+
### Resolved Issues
|
85
|
+
|
86
|
+
* Javascript returning undefined instead of "" prevents attachments from working at embedded documents
|
87
|
+
|
1
88
|
## 0.1.0 - June 11, 2012
|
2
89
|
|
3
90
|
### Improvements
|
@@ -38,7 +125,11 @@ album = Album.new
|
|
38
125
|
photo = album.photos.create(photo: params[:file])
|
39
126
|
```
|
40
127
|
|
41
|
-
* Allow the `
|
128
|
+
* Allow the `attaches_many` to be used in embedded documents
|
129
|
+
|
130
|
+
``` erb
|
131
|
+
<%= attachment_container @album, :photos, {}, {}, embedded_in: @album.artist %>
|
132
|
+
```
|
42
133
|
|
43
134
|
### Deprecations
|
44
135
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MediaMagick [![Build Status](https://secure.travis-ci.org/nudesign/media_magick.png?branch=master)](http://travis-ci.org/nudesign/media_magick) [![Build Status](https://gemnasium.com/nudesign/media_magick.png
|
1
|
+
# MediaMagick [![Build Status](https://secure.travis-ci.org/nudesign/media_magick.png?branch=master)](http://travis-ci.org/nudesign/media_magick) [![Build Status](https://gemnasium.com/nudesign/media_magick.png)](http://gemnasium.com/nudesign/media_magick) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/nudesign/media_magick)
|
2
2
|
|
3
3
|
MediaMagick aims to make dealing with multimedia resources a very easy task – like magic. It wraps up robust solutions for upload, associate and display images, videos, audios and files to any model in your rails app.
|
4
4
|
|
@@ -54,12 +54,12 @@
|
|
54
54
|
flash_swf_url: settings.flash_swf_url,
|
55
55
|
max_file_size: settings.max_file_size,
|
56
56
|
multipart_params: {
|
57
|
-
id:
|
58
|
-
relation:
|
59
|
-
model:
|
60
|
-
partial:
|
61
|
-
embedded_in_model: $container.data('embedded-in-model'),
|
62
|
-
embedded_in_id: $container.data('embedded-in-id')
|
57
|
+
id: $container.data('id'),
|
58
|
+
relation: $container.data('relation'),
|
59
|
+
model: $container.data('model'),
|
60
|
+
partial: $container.data('partial') === undefined ? '' : $container.data('partial'),
|
61
|
+
embedded_in_model: $container.data('embedded-in-model') === undefined ? '' : $container.data('embedded-in-model'),
|
62
|
+
embedded_in_id: $container.data('embedded-in-id') === undefined ? '' : $container.data('embedded-in-id')
|
63
63
|
},
|
64
64
|
resize: settings.resize,
|
65
65
|
runtimes: settings.runtimes,
|
@@ -71,9 +71,10 @@
|
|
71
71
|
uploader.bind('Init', function(up, params) {
|
72
72
|
if ($('#' + settings.container + '-runtimeInfo').length > 0) $('#' + settings.container + '-runtimeInfo').text("Current runtime: " + params.runtime);
|
73
73
|
// if ($container.find("dt").length > 0 && $container.find("dt").text() == "") $container.find("dt").text($container.attr('id'));
|
74
|
-
|
75
|
-
$("
|
76
|
-
|
74
|
+
|
75
|
+
var modelAndRelation = $container.data('model') + "-" + $container.data('relation');
|
76
|
+
|
77
|
+
$("#" + $container.attr("id") + " a.remove").live('click', function() {
|
77
78
|
var $attachment = $(this).parents('.attachment');
|
78
79
|
var $attachmentUploader = $(this).parents('.attachmentUploader');
|
79
80
|
|
@@ -88,6 +89,26 @@
|
|
88
89
|
$attachment.remove();
|
89
90
|
});
|
90
91
|
});
|
92
|
+
|
93
|
+
$("#attachmentVideoUploader" + modelAndRelation).live('click', function() {
|
94
|
+
var $attachment = $(this).parents('.attachment');
|
95
|
+
var $attachmentUploader = $(this).parents('.attachmentUploader');
|
96
|
+
var $videoField = $("#attachmentVideoUploaderField" + modelAndRelation);
|
97
|
+
|
98
|
+
$.get('/upload', {
|
99
|
+
model: $container.data('model'),
|
100
|
+
id: $container.data('id'),
|
101
|
+
relation: $container.data('relation'),
|
102
|
+
relation_id: $attachment.data('id'),
|
103
|
+
embedded_in_model: $attachmentUploader.data('embedded-in-model'),
|
104
|
+
embedded_in_id: $attachmentUploader.data('embedded-in-id'),
|
105
|
+
partial: $container.data('partial') === undefined ? '' : $container.data('partial'),
|
106
|
+
video: $videoField.val()
|
107
|
+
}, function(data) {
|
108
|
+
$("#" + $container.attr("id") + "-loadedAttachments").append(data);
|
109
|
+
$videoField.val("");
|
110
|
+
});
|
111
|
+
});
|
91
112
|
});
|
92
113
|
|
93
114
|
$('#' + settings.container + '-' + settings.upload_button).click(function(e) {
|
@@ -1,30 +1,26 @@
|
|
1
1
|
require 'action_controller/railtie'
|
2
|
+
require 'media_magick/controller/helpers'
|
2
3
|
|
3
4
|
module MediaMagick
|
4
5
|
class AttachController < ActionController::Base
|
6
|
+
include MediaMagick::Controller::Helpers
|
7
|
+
|
5
8
|
def create
|
6
9
|
if !params[:embedded_in_model].blank?
|
7
10
|
embedded_in = params[:embedded_in_model].constantize.find(params[:embedded_in_id])
|
8
11
|
klass = embedded_in.send(params[:model].pluralize.downcase).find(params[:id])
|
9
|
-
attachment = klass.send(params[:relation].pluralize).create(params[:relation].singularize => params[:file])
|
10
|
-
klass.save
|
11
12
|
else
|
12
|
-
|
13
|
-
klass = params[:model].constantize.where(id: params[:id])
|
14
|
-
klass = klass.empty? ? nil : klass.first
|
15
|
-
|
16
|
-
if klass
|
17
|
-
attachment = klass.send(params[:relation].pluralize).create(params[:relation].singularize => params[:file])
|
18
|
-
else
|
19
|
-
attachment = params[:model].constantize.relations[params[:relation]][:class_name].constantize.create!(params[:relation].singularize => params[:file])
|
20
|
-
end
|
21
|
-
else
|
22
|
-
klass = params[:model].constantize.find(params[:id])
|
23
|
-
attachment = klass.send(params[:relation].pluralize).create(params[:relation].singularize => params[:file])
|
24
|
-
klass.save
|
25
|
-
end
|
13
|
+
klass = params[:model].constantize.find(params[:id])
|
26
14
|
end
|
27
15
|
|
16
|
+
if params[:video]
|
17
|
+
attachment = klass.send(params[:relation].pluralize).create(video: params[:video])
|
18
|
+
else
|
19
|
+
attachment = klass.send(params[:relation].pluralize).create(params[:relation].singularize => params[:file])
|
20
|
+
end
|
21
|
+
|
22
|
+
klass.save
|
23
|
+
|
28
24
|
partial = params[:partial].blank? ? "/#{attachment.class::TYPE}" : params[:partial]
|
29
25
|
|
30
26
|
render :partial => partial, :locals => {:model => params[:model], :relation => params[:relation], :attachment => attachment}
|
@@ -45,14 +41,10 @@ module MediaMagick
|
|
45
41
|
attachments = params[:elements]
|
46
42
|
attachments = attachments.split(',') unless attachments.kind_of?(Array)
|
47
43
|
|
48
|
-
|
49
|
-
parent = params[:embedded_in_model].classify.constantize.find(params[:embedded_in_id]).send(params[:model].pluralize.downcase).find(params[:model_id])
|
50
|
-
else
|
51
|
-
parent = params[:model].constantize.find(params[:model_id])
|
52
|
-
end
|
44
|
+
doc = find_doc_by_params(params)
|
53
45
|
|
54
46
|
attachments.each_with_index do |id, i|
|
55
|
-
attachment =
|
47
|
+
attachment = doc.send(params[:relation]).find(id)
|
56
48
|
attachment.priority = i
|
57
49
|
attachment.save
|
58
50
|
end
|
@@ -61,14 +53,10 @@ module MediaMagick
|
|
61
53
|
end
|
62
54
|
|
63
55
|
def recreate_versions
|
64
|
-
|
65
|
-
parent = params[:embedded_in_model].classify.constantize.find(params[:embedded_in_id]).send(params[:model].pluralize.downcase).find(params[:model_id])
|
66
|
-
else
|
67
|
-
parent = params[:model].classify.constantize.find(params[:model_id])
|
68
|
-
end
|
56
|
+
doc = find_doc_by_params(params)
|
69
57
|
|
70
58
|
errors = []
|
71
|
-
|
59
|
+
doc.send(params[:relation].pluralize).each do |attachment|
|
72
60
|
errors << attachment unless attachment.recreate_versions!
|
73
61
|
end
|
74
62
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module MediaMagick
|
2
2
|
module ApplicationHelper
|
3
|
-
def attachment_container(model, relation,
|
3
|
+
def attachment_container(model, relation, options = {})
|
4
4
|
data_attributes = {
|
5
5
|
model: model.class.to_s,
|
6
6
|
id: model.id.to_s,
|
7
7
|
relation: relation.to_s
|
8
8
|
}
|
9
9
|
|
10
|
-
data_attributes.merge!(:partial => options
|
10
|
+
data_attributes.merge!(:partial => get_partial_name(options))
|
11
11
|
data_attributes.merge!(:embedded_in_id => options[:embedded_in].id.to_s, :embedded_in_model => options[:embedded_in].class.to_s) if options[:embedded_in]
|
12
12
|
|
13
13
|
content_tag :div, id: model.class.to_s.downcase << '-' << relation.to_s, class: 'attachmentUploader ' << relation.to_s, data: data_attributes do
|
@@ -17,14 +17,55 @@ module MediaMagick
|
|
17
17
|
partial_attributes = {
|
18
18
|
model: model,
|
19
19
|
relations: relation,
|
20
|
-
newAttachments: newAttachments,
|
21
|
-
loadedAttachments: loadedAttachments,
|
22
|
-
partial: options
|
20
|
+
newAttachments: options[:newAttachments] || {},
|
21
|
+
loadedAttachments: options[:loadedAttachments] || {},
|
22
|
+
partial: get_partial_name(options)
|
23
23
|
}
|
24
24
|
|
25
25
|
render '/upload', partial_attributes
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def attachment_container_for_video(model, relation, options = {})
|
31
|
+
data_attributes = {
|
32
|
+
model: model.class.to_s,
|
33
|
+
id: model.id.to_s,
|
34
|
+
relation: relation.to_s
|
35
|
+
}
|
36
|
+
|
37
|
+
data_attributes.merge!(:partial => get_partial_name(options))
|
38
|
+
data_attributes.merge!(:embedded_in_id => options[:embedded_in].id.to_s, :embedded_in_model => options[:embedded_in].class.to_s) if options[:embedded_in]
|
39
|
+
|
40
|
+
content_tag :div, id: model.class.to_s.downcase << '-' << relation.to_s, class: 'attachmentUploader ' << relation.to_s, data: data_attributes do
|
41
|
+
if block_given?
|
42
|
+
yield
|
43
|
+
else
|
44
|
+
partial_attributes = {
|
45
|
+
model: model,
|
46
|
+
relations: relation,
|
47
|
+
newAttachments: options[:newAttachments] || {},
|
48
|
+
loadedAttachments: options[:loadedAttachments] || {},
|
49
|
+
partial: get_partial_name(options)
|
50
|
+
}
|
51
|
+
|
52
|
+
render '/video', partial_attributes
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def get_partial_name(options)
|
60
|
+
if options[:partial]
|
61
|
+
options[:partial]
|
62
|
+
else
|
63
|
+
if options[:as]
|
64
|
+
"/#{options[:as]}"
|
65
|
+
else
|
66
|
+
'/image'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
29
70
|
end
|
30
71
|
end
|
data/app/views/_file.html.erb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<li class="attachment" data-id="<%= attachment.to_param %>">
|
2
|
-
<%= link_to attachment.filename, attachment.url unless attachment.file.nil? %>
|
3
|
-
<%= link_to t('media_magick.remove'), "javascript://", method: "delete",
|
2
|
+
<%= link_to attachment.filename, attachment.url, download: attachment.filename unless attachment.file.nil? %>
|
3
|
+
<%= link_to t('media_magick.remove'), "javascript://", method: "delete", class: "remove btn btn-mini btn-danger", data: { confirm: t('media_magick.confirm_removal') } %>
|
4
4
|
|
5
5
|
<%= hidden_field_tag "#{model.parameterize}[#{relation.singularize}_ids][]", attachment.id if model && relation %>
|
6
6
|
</li>
|
data/app/views/_image.html.erb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
<li class="attachment" id="<%= attachment.to_param %>" data-id="<%= attachment.to_param %>">
|
2
|
-
<%= image_tag attachment.url, alt: attachment.filename %>
|
3
|
-
<%= link_to t('media_magick.remove'), "javascript://", method: "delete",
|
1
|
+
<li class="attachment" id="<%= attachment.to_param %>" data-id="<%= attachment.to_param %>">
|
2
|
+
<%= image_tag attachment.url, alt: attachment.filename if attachment.file %>
|
3
|
+
<%= link_to t('media_magick.remove'), "javascript://", method: "delete", class: "remove btn btn-mini btn-danger", data: { confirm: t('media_magick.confirm_removal') } %>
|
4
4
|
|
5
5
|
<%= hidden_field_tag "#{model.parameterize}[#{relation.singularize}_ids][]", attachment.id if model && relation %>
|
6
6
|
</li>
|
data/app/views/_upload.html.erb
CHANGED
@@ -6,14 +6,7 @@
|
|
6
6
|
<a class="pickAttachments btn" href="javascript://"><%= t('media_magick.select') %></a>
|
7
7
|
<a class="uploadAttachments btn" href="javascript://"><%= t('media_magick.upload') %></a>
|
8
8
|
</div>
|
9
|
+
|
9
10
|
<ul class="loadedAttachments <%= loadedAttachments[:class] %>">
|
10
|
-
|
11
|
-
|
12
|
-
<%= render partial, attachment: attachment %>
|
13
|
-
<% elsif attachment.class::TYPE.to_s == 'file' %>
|
14
|
-
<%= render :partial => "/file", :locals => { :attachment => attachment } %>
|
15
|
-
<% elsif attachment.class::TYPE.to_s == 'image' %>
|
16
|
-
<%= render :partial => "/image", :locals => { :attachment => attachment, :model => nil, :relation => nil } %>
|
17
|
-
<% end %>
|
18
|
-
<% end %>
|
19
|
-
</ul>
|
11
|
+
<%= render partial: partial, collection: model.send(relations), :as => :attachment, :locals => { model: nil, relation: nil } %>
|
12
|
+
</ul>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% id = "#{model.class.name}-#{relations}" %>
|
2
|
+
|
3
|
+
<input type="text" id="attachmentVideoUploaderField<%= id %>">
|
4
|
+
<a id="attachmentVideoUploader<%= id %>" href="javascript://">upload</a>
|
5
|
+
|
6
|
+
<ul class="loadedAttachments <%= loadedAttachments[:class] %>">
|
7
|
+
<%= render partial: partial, collection: model.send(relations), :as => :attachment, :locals => { model: nil, relation: nil } %>
|
8
|
+
</ul>
|
data/lib/media_magick.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module MediaMagick
|
2
|
+
module Controller
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# {"embedded_in_model"=>"embedded_model",
|
7
|
+
# "embedded_in_id"=>"embedded_id", "model"=>"model",
|
8
|
+
# "model_id"=>"id"
|
9
|
+
# }
|
10
|
+
def find_doc_by_params(params)
|
11
|
+
if params[:embedded_in_model].blank?
|
12
|
+
doc = params[:model].classify.constantize.find(params[:model_id])
|
13
|
+
else
|
14
|
+
doc = params[:embedded_in_model].classify.constantize.find(params[:embedded_in_id]).send(params[:model].pluralize.downcase).find(params[:model_id])
|
15
|
+
end
|
16
|
+
doc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/media_magick/engine.rb
CHANGED