attachment_magick 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -1
- data/README.rdoc +20 -24
- data/app/controllers/attachment_magick/images_controller.rb +1 -1
- data/app/helpers/attachment_magick/attachment_magick_helper.rb +40 -3
- data/app/models/attachment_magick/active_record_image.rb +9 -1
- data/app/models/attachment_magick/mongoid_image.rb +17 -1
- data/app/views/{layouts/attachment_magick/images → attachment_magick}/_add_image.html.erb +5 -1
- data/app/views/{layouts/attachment_magick/images → attachment_magick}/_video_upload.html.erb +0 -0
- data/lib/attachment_magick/configuration/configuration.rb +1 -1
- data/lib/attachment_magick/test/attachment_magick_test_helper.rb +16 -1
- data/lib/attachment_magick/version.rb +1 -1
- data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/handlers.js +1 -1
- data/test/attachment_magick/controllers/images_controller_test.rb +12 -0
- data/test/attachment_magick/helpers/attachment_magick_test.rb +11 -3
- data/test/dummy/app/views/artists/_form.html.erb +4 -5
- data/test/dummy/app/views/layouts/application.html.erb +1 -1
- data/test/dummy/config/application.rb +2 -0
- data/test/dummy/config/initializers/attachment_magick_setup.rb +0 -1
- data/test/dummy/public/javascripts/swfupload/handlers.js +1 -1
- metadata +5 -7
- data/test/dummy/public/images/little_girl.jpg +0 -0
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
attachment_magick (0.0
|
4
|
+
attachment_magick (0.1.0)
|
5
5
|
dragonfly (>= 0.8.1)
|
6
6
|
jquery-rails (>= 0.2.7)
|
7
7
|
marcosinger-auto_html (>= 1.3.4)
|
@@ -151,6 +151,7 @@ DEPENDENCIES
|
|
151
151
|
capybara (>= 0.4.0)
|
152
152
|
colorific
|
153
153
|
hpricot
|
154
|
+
mime-types (>= 1.16)
|
154
155
|
mongoid (>= 2.0.0.rc.6)
|
155
156
|
nokogiri
|
156
157
|
rails (= 3.0.3)
|
data/README.rdoc
CHANGED
@@ -1,47 +1,43 @@
|
|
1
1
|
== AttachmentMagick
|
2
2
|
|
3
3
|
Attachment Magick is a gem to upload images and videos(vimeo) using swfupload.
|
4
|
-
Supports Mongoid
|
4
|
+
Supports Mongoid and ActiveRecord.
|
5
5
|
|
6
6
|
== Installation
|
7
7
|
|
8
|
-
This gem is not released yet, some dependencies are still necessary
|
9
8
|
Add to Gemfile
|
10
9
|
|
11
|
-
|
12
|
-
gem 'attachment_magick', :git => 'git://github.com/marcosinger/attachment_magick.git'
|
13
|
-
gem 'auto_html', :git => 'git://github.com/marcosinger/auto_html.git'
|
14
|
-
gem 'hpricot'
|
15
|
-
gem 'haml'
|
10
|
+
gem 'attachment_magick'
|
16
11
|
|
17
|
-
Then run
|
18
|
-
|
19
|
-
bundle install
|
20
12
|
|
21
13
|
After the gem installation, run the generator
|
22
14
|
|
23
|
-
attachment_magick:install
|
15
|
+
rails g attachment_magick:install
|
24
16
|
|
25
17
|
The generator will install swfupload (js and css files) and will create some routes.
|
26
18
|
|
19
|
+
And if you using ActiveRecord, run this too
|
20
|
+
|
21
|
+
rails g attachment_magick:migration
|
22
|
+
|
27
23
|
Create a initializer like this (config/initializers/attachment_magick_setup.rb)
|
28
24
|
|
29
25
|
AttachmentMagick.setup do |config|
|
30
|
-
config.default_add_partial = '/
|
26
|
+
#config.default_add_partial = '/attachment_magick/add_image' # default
|
31
27
|
config.columns_amount = 16
|
32
|
-
config.columns_width
|
33
|
-
config.gutter
|
28
|
+
config.columns_width = 52
|
29
|
+
config.gutter = 8
|
34
30
|
|
35
31
|
config.custom_styles do
|
36
32
|
publisher "52x"
|
37
|
-
|
33
|
+
my_custom_style "50x50"
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
* Attachment Magick is based in 960 Grid System (http://960.gs/)
|
42
38
|
|
43
39
|
Add to application.rb
|
44
|
-
|
40
|
+
|
45
41
|
config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/media'
|
46
42
|
config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
47
43
|
:verbose => true,
|
@@ -58,17 +54,21 @@ Include the js files to your application layout or page
|
|
58
54
|
Include AttachmentMagick Module to your model
|
59
55
|
|
60
56
|
class Post
|
61
|
-
include Mongoid::Document
|
62
57
|
include AttachmentMagick
|
63
58
|
|
64
|
-
|
59
|
+
...
|
65
60
|
end
|
66
61
|
|
67
62
|
Call this helpers in form views
|
68
63
|
|
69
64
|
attachment_progress_container @post
|
70
65
|
attachment_for_view @post
|
71
|
-
attachment_for_video
|
66
|
+
attachment_for_video @post
|
67
|
+
attachment_for_flash @image.photo.url
|
68
|
+
|
69
|
+
For customize your list for images
|
70
|
+
attachment_for_view @post, 'path/my_partial'
|
71
|
+
|
72
72
|
|
73
73
|
== Customizing views
|
74
74
|
|
@@ -86,13 +86,9 @@ Call this helpers in form views
|
|
86
86
|
== Customizing sizes
|
87
87
|
|
88
88
|
class Post
|
89
|
-
include Mongoid::Document
|
90
89
|
include AttachmentMagick
|
91
90
|
|
92
|
-
field :title
|
93
|
-
|
94
91
|
attachment_magick do
|
95
92
|
grid_1 "100x100"
|
96
93
|
end
|
97
|
-
end
|
98
|
-
|
94
|
+
end
|
@@ -4,7 +4,7 @@ class AttachmentMagick::ImagesController < ActionController::Base
|
|
4
4
|
before_filter :load_klass
|
5
5
|
|
6
6
|
def create
|
7
|
-
@image = @klass.images.create(:photo => params[:Filedata], :source => params[:source], :
|
7
|
+
@image = @klass.images.create(:photo => params[:Filedata], :source => params[:source], :file_name => params[:source] ? "" : params[:Filedata].original_filename)
|
8
8
|
@klass.save
|
9
9
|
|
10
10
|
if params[:data_partial].present?
|
@@ -50,8 +50,45 @@ module AttachmentMagick::AttachmentMagickHelper
|
|
50
50
|
"#{html_partial}<div id='#{key}' class='#{'attachmentSortable' if use_sortable}'>#{html}</div><div></div>".html_safe
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
54
|
-
def attachment_for_video
|
55
|
-
%{<label>vídeo</label><ol class='form-block'>#{render :partial => "
|
53
|
+
|
54
|
+
def attachment_for_video(object)
|
55
|
+
%{<label>vídeo</label><ol class='form-block'>#{render :partial => "/attachment_magick/video_upload"}</ol>}.html_safe unless object.new_record?
|
56
|
+
end
|
57
|
+
|
58
|
+
#FIXME - verify this html
|
59
|
+
def attachment_for_flash(url, width=100, height=60)
|
60
|
+
"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='#{width}' height='#{height}' id='#{url}' align='middle'>
|
61
|
+
<param name='movie' value='#{url}' />
|
62
|
+
<param name='quality' value='high' />
|
63
|
+
<param name='bgcolor' value='#FFF' />
|
64
|
+
<param name='play' value='true' />
|
65
|
+
<param name='loop' value='true' />
|
66
|
+
<param name='wmode' value='window' />
|
67
|
+
<param name='scale' value='showall' />
|
68
|
+
<param name='menu' value='true' />
|
69
|
+
<param name='devicefont' value='false' />
|
70
|
+
<param name='salign' value='' />
|
71
|
+
<param name='allowScriptAccess' value='sameDomain' />
|
72
|
+
<!--[if !IE]>-->
|
73
|
+
<object type='application/x-shockwave-flash' data='#{url}' width='#{width}' height='#{height}'>
|
74
|
+
<param name='movie' value='#{url}' />
|
75
|
+
<param name='quality' value='high' />
|
76
|
+
<param name='bgcolor' value='#FFF' />
|
77
|
+
<param name='play' value='true' />
|
78
|
+
<param name='loop' value='true' />
|
79
|
+
<param name='wmode' value='window' />
|
80
|
+
<param name='scale' value='showall' />
|
81
|
+
<param name='menu' value='true' />
|
82
|
+
<param name='devicefont' value='false' />
|
83
|
+
<param name='salign' value='' />
|
84
|
+
<param name='allowScriptAccess' value='sameDomain' />
|
85
|
+
<!--<![endif]-->
|
86
|
+
<a href='http://www.adobe.com/go/getflash'>
|
87
|
+
<img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' />
|
88
|
+
</a>
|
89
|
+
<!--[if !IE]>-->
|
90
|
+
</object>
|
91
|
+
<!--<![endif]-->
|
92
|
+
</object>".html_safe
|
56
93
|
end
|
57
94
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module AttachmentMagick
|
2
2
|
class ActiveRecordImage < ActiveRecord::Base
|
3
3
|
set_table_name "amagick_images"
|
4
|
-
|
4
|
+
|
5
5
|
belongs_to :imageable, :polymorphic => true
|
6
6
|
image_accessor :photo
|
7
7
|
|
8
|
+
attr_accessor :file_name #not implemented yet
|
9
|
+
|
8
10
|
auto_html_for :source => "_to_html" do
|
9
11
|
youtube(:width => 620, :height => 465)
|
10
12
|
vimeo(:width => 620, :height => 465)
|
@@ -14,5 +16,11 @@ module AttachmentMagick
|
|
14
16
|
youtube_image
|
15
17
|
vimeo_image(:size => :large)
|
16
18
|
end
|
19
|
+
|
20
|
+
#not implemented yet
|
21
|
+
def is_flash?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
17
25
|
end if defined? ActiveRecord::Persistence
|
18
26
|
end
|
@@ -1,14 +1,20 @@
|
|
1
|
+
require "mime/types"
|
2
|
+
|
1
3
|
module AttachmentMagick
|
2
4
|
class MongoidImage
|
3
5
|
include Mongoid::Document
|
4
6
|
include AutoHtml
|
5
7
|
include AutoHtmlFor
|
6
8
|
|
9
|
+
before_create :set_content_type
|
10
|
+
|
11
|
+
attr_accessor :file_name
|
12
|
+
|
7
13
|
field :photo_uid
|
8
14
|
field :caption
|
9
15
|
field :priority
|
10
16
|
field :source
|
11
|
-
field :
|
17
|
+
field :content_type
|
12
18
|
image_accessor :photo
|
13
19
|
embedded_in :imageable, :inverse_of => :image
|
14
20
|
|
@@ -25,5 +31,15 @@ module AttachmentMagick
|
|
25
31
|
def imageable
|
26
32
|
self._parent
|
27
33
|
end
|
34
|
+
|
35
|
+
#FIXME - find a better way to compare
|
36
|
+
def is_flash?
|
37
|
+
self.content_type =~ /flash/ ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def set_content_type
|
42
|
+
self.content_type = MIME::Types.type_for(self.file_name.to_s).to_s
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
<div class="grid_5 attachment_magick_image">
|
2
2
|
<div class="grid_3 alpha">
|
3
|
-
|
3
|
+
<% if image.is_flash? %>
|
4
|
+
<%= attachment_for_flash(image.photo.url) %>
|
5
|
+
<% else %>
|
6
|
+
<%= image_tag((image.source.nil? ? image.photo.thumb(image.imageable.class.style_publisher).url : image.source_to_image), :alt => "") %>
|
7
|
+
<% end %>
|
4
8
|
<input type="hidden" value="<%= image.id%>" id="image_id">
|
5
9
|
</div>
|
6
10
|
<div class="grid_2 omega">
|
data/app/views/{layouts/attachment_magick/images → attachment_magick}/_video_upload.html.erb
RENAMED
File without changes
|
@@ -1,3 +1,10 @@
|
|
1
|
+
class Tempfile
|
2
|
+
def original_filename
|
3
|
+
"little_girl.jpg"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
|
1
8
|
module AttachmentMagickTestHelper
|
2
9
|
def assert_element_in(target, match)
|
3
10
|
target = Nokogiri::HTML(target)
|
@@ -34,7 +41,15 @@ module AttachmentMagickTestHelper
|
|
34
41
|
end
|
35
42
|
|
36
43
|
def exemple_file
|
37
|
-
|
44
|
+
Tempfile.new('little_girl.jpg')
|
45
|
+
end
|
46
|
+
|
47
|
+
def exemple_youtube
|
48
|
+
'http://www.youtube.com/watch?v=FUe83k3t_0s'
|
49
|
+
end
|
50
|
+
|
51
|
+
def exemple_vimeo
|
52
|
+
'http://vimeo.com/14051767'
|
38
53
|
end
|
39
54
|
|
40
55
|
def exemple_partial
|
@@ -48,7 +48,7 @@ var attachmentMagick = {
|
|
48
48
|
post_params : { 'data_attachment' : data_attachment, 'data_partial' : data_partial },
|
49
49
|
|
50
50
|
file_size_limit: '20 MB',
|
51
|
-
file_types: '*.jpg; *.png; *.gif; *.jpeg',
|
51
|
+
file_types: '*.jpg; *.png; *.gif; *.jpeg; *.swf',
|
52
52
|
file_types_description: 'Images Files',
|
53
53
|
file_upload_limit : 0,
|
54
54
|
|
@@ -14,6 +14,18 @@ class AttachmentMagick::ImagesControllerTest < ActionController::TestCase
|
|
14
14
|
assert assert_element_in(response.body, "img")
|
15
15
|
end
|
16
16
|
|
17
|
+
test "should create artist vimeo video" do
|
18
|
+
post :create, artist_hash.merge({ :source => exemple_vimeo })
|
19
|
+
assert_response :success
|
20
|
+
assert assert_element_in(response.body, "img")
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should create artist youtube video" do
|
24
|
+
post :create, artist_hash.merge({ :source => exemple_youtube })
|
25
|
+
assert_response :success
|
26
|
+
assert assert_element_in(response.body, "img")
|
27
|
+
end
|
28
|
+
|
17
29
|
test "should create work image" do
|
18
30
|
post :create, work_hash.merge({ :Filedata => exemple_file })
|
19
31
|
assert_response :success
|
@@ -46,11 +46,19 @@ class AttachmentMagick::AttachmentMagickHelperTest < ActionView::TestCase
|
|
46
46
|
assert assert_element_in(html, "div[@class='image_thumb']")
|
47
47
|
assert assert_element_in(html, "img")
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_attachment_for_video
|
51
|
-
html = attachment_for_video
|
52
|
-
|
51
|
+
html = attachment_for_video(@artist)
|
52
|
+
|
53
53
|
assert assert_element_in(html, "input")
|
54
54
|
assert assert_element_in(html, "a[@class='video_upload']")
|
55
55
|
end
|
56
|
+
|
57
|
+
def test_attachment_for_flash
|
58
|
+
@artist.images.create(:photo => exemple_file)
|
59
|
+
|
60
|
+
html = attachment_for_flash(@artist.images.first.photo.url)
|
61
|
+
assert assert_element_in(html, "object")
|
62
|
+
assert assert_element_in(html, "object[@width='100'][@height='60']")
|
63
|
+
end
|
56
64
|
end
|
@@ -9,21 +9,20 @@
|
|
9
9
|
<%=link_to work.name, edit_artist_work_path(@artist, work)%>
|
10
10
|
<% end %>
|
11
11
|
</div>
|
12
|
-
|
12
|
+
<% end %>
|
13
13
|
<div class="grid_13 tpush_2">
|
14
14
|
<%=form_for @artist, :html => {:multipart => true} do |form|%>
|
15
15
|
<%=form.label :name%>
|
16
16
|
<%=form.text_field :name%>
|
17
|
-
|
17
|
+
|
18
18
|
<%=form.label :lastname%>
|
19
19
|
<%=form.text_field :lastname%>
|
20
20
|
<%=form.submit%>
|
21
21
|
<br />
|
22
22
|
<br />
|
23
|
-
|
23
|
+
|
24
24
|
<%= attachment_progress_container @artist%>
|
25
25
|
<%= attachment_for_view @artist%>
|
26
|
-
<%= attachment_for_video%>
|
26
|
+
<%= attachment_for_video @artist%>
|
27
27
|
<% end %>
|
28
28
|
</div>
|
29
|
-
<% end %>
|
@@ -14,6 +14,8 @@ module Dummy
|
|
14
14
|
config.encoding = "utf-8"
|
15
15
|
config.filter_parameters += [:password]
|
16
16
|
|
17
|
+
config.action_view.javascript_expansions[:defaults] = %w(jquery.min rails application)
|
18
|
+
|
17
19
|
config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/media'
|
18
20
|
config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
19
21
|
:verbose => true,
|
@@ -48,7 +48,7 @@ var attachmentMagick = {
|
|
48
48
|
post_params : { 'data_attachment' : data_attachment, 'data_partial' : data_partial },
|
49
49
|
|
50
50
|
file_size_limit: '20 MB',
|
51
|
-
file_types: '*.jpg; *.png; *.gif; *.jpeg',
|
51
|
+
file_types: '*.jpg; *.png; *.gif; *.jpeg; *.swf',
|
52
52
|
file_types_description: 'Images Files',
|
53
53
|
file_upload_limit : 0,
|
54
54
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: attachment_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Marco Ant\xC3\xB4nio Singer"
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-04-
|
14
|
+
date: 2011-04-08 00:00:00 -03:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -79,8 +79,8 @@ files:
|
|
79
79
|
- app/helpers/attachment_magick/attachment_magick_helper.rb
|
80
80
|
- app/models/attachment_magick/active_record_image.rb
|
81
81
|
- app/models/attachment_magick/mongoid_image.rb
|
82
|
-
- app/views/
|
83
|
-
- app/views/
|
82
|
+
- app/views/attachment_magick/_add_image.html.erb
|
83
|
+
- app/views/attachment_magick/_video_upload.html.erb
|
84
84
|
- attachment_magick.gemspec
|
85
85
|
- lib/attachment_magick.rb
|
86
86
|
- lib/attachment_magick/configuration/configuration.rb
|
@@ -156,7 +156,6 @@ files:
|
|
156
156
|
- test/dummy/public/422.html
|
157
157
|
- test/dummy/public/500.html
|
158
158
|
- test/dummy/public/favicon.ico
|
159
|
-
- test/dummy/public/images/little_girl.jpg
|
160
159
|
- test/dummy/public/images/swfupload/cancelbutton.gif
|
161
160
|
- test/dummy/public/javascripts/application.js
|
162
161
|
- test/dummy/public/javascripts/jquery-ui.js
|
@@ -199,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
198
|
requirements: []
|
200
199
|
|
201
200
|
rubyforge_project: attachment_magick
|
202
|
-
rubygems_version: 1.
|
201
|
+
rubygems_version: 1.5.2
|
203
202
|
signing_key:
|
204
203
|
specification_version: 3
|
205
204
|
summary: little more magick when you upload image files (with SwfUpload and Dragonfly)
|
@@ -262,7 +261,6 @@ test_files:
|
|
262
261
|
- test/dummy/public/422.html
|
263
262
|
- test/dummy/public/500.html
|
264
263
|
- test/dummy/public/favicon.ico
|
265
|
-
- test/dummy/public/images/little_girl.jpg
|
266
264
|
- test/dummy/public/images/swfupload/cancelbutton.gif
|
267
265
|
- test/dummy/public/javascripts/application.js
|
268
266
|
- test/dummy/public/javascripts/jquery-ui.js
|
Binary file
|