attachment_magick 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +159 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +98 -0
- data/Rakefile +13 -0
- data/app/controllers/attachment_magick/images_controller.rb +50 -0
- data/app/helpers/attachment_magick/attachment_magick_helper.rb +57 -0
- data/app/models/attachment_magick/active_record_image.rb +18 -0
- data/app/models/attachment_magick/mongoid_image.rb +29 -0
- data/app/views/layouts/attachment_magick/images/_add_image.html.erb +18 -0
- data/app/views/layouts/attachment_magick/images/_video_upload.html.erb +2 -0
- data/attachment_magick.gemspec +25 -0
- data/lib/attachment_magick/configuration/configuration.rb +28 -0
- data/lib/attachment_magick/configuration/custom_style.rb +19 -0
- data/lib/attachment_magick/dragonfly/init.rb +20 -0
- data/lib/attachment_magick/dsl.rb +37 -0
- data/lib/attachment_magick/railtie.rb +10 -0
- data/lib/attachment_magick/test/attachment_magick_test_helper.rb +43 -0
- data/lib/attachment_magick/version.rb +3 -0
- data/lib/attachment_magick.rb +78 -0
- data/lib/generators/attachment_magick/install_generator.rb +15 -0
- data/lib/generators/attachment_magick/migration_generator.rb +17 -0
- data/lib/generators/attachment_magick/templates/attachment_magick_migration.rb +18 -0
- data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/handlers.js +384 -0
- data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/swfupload.js +1132 -0
- data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/swfupload.swf +0 -0
- data/lib/generators/attachment_magick/templates/public/stylesheets/attachment_magick.css +10 -0
- data/lib/generators/attachment_magick/templates/public/stylesheets/swfupload.css +108 -0
- data/test/attachment_magick/controllers/images_controller_test.rb +67 -0
- data/test/attachment_magick/generators/install_generator_test.rb +34 -0
- data/test/attachment_magick/generators/migration_generator_test.rb +16 -0
- data/test/attachment_magick/helpers/attachment_magick_test.rb +56 -0
- data/test/attachment_magick/units/artist_test.rb +11 -0
- data/test/attachment_magick/units/attachment_magick_test.rb +105 -0
- data/test/attachment_magick/units/image_test.rb +26 -0
- data/test/attachment_magick/units/place_test.rb +8 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -0
- data/test/dummy/app/controllers/artists_controller.rb +34 -0
- data/test/dummy/app/controllers/places_controller.rb +34 -0
- data/test/dummy/app/controllers/works_controller.rb +37 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/artists_helper.rb +2 -0
- data/test/dummy/app/helpers/places_helper.rb +2 -0
- data/test/dummy/app/helpers/works_helper.rb +2 -0
- data/test/dummy/app/models/artist.rb +20 -0
- data/test/dummy/app/models/place.rb +8 -0
- data/test/dummy/app/models/work.rb +13 -0
- data/test/dummy/app/views/artists/_form.html.erb +29 -0
- data/test/dummy/app/views/artists/edit.html.erb +1 -0
- data/test/dummy/app/views/artists/index.html.erb +39 -0
- data/test/dummy/app/views/artists/new.html.erb +1 -0
- data/test/dummy/app/views/layouts/_custom_images_list.html.erb +6 -0
- data/test/dummy/app/views/layouts/application.html.erb +27 -0
- data/test/dummy/app/views/places/_form.html.erb +12 -0
- data/test/dummy/app/views/places/edit.html.erb +1 -0
- data/test/dummy/app/views/places/index.html.erb +32 -0
- data/test/dummy/app/views/places/new.html.erb +1 -0
- data/test/dummy/app/views/works/_form.html.erb +18 -0
- data/test/dummy/app/views/works/edit.html.erb +1 -0
- data/test/dummy/app/views/works/index.html.erb +32 -0
- data/test/dummy/app/views/works/new.html.erb +1 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/attachment_magick_setup.rb +12 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/mongoid.yml +18 -0
- data/test/dummy/config/routes.rb +15 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20110310155855_create_places.rb +13 -0
- data/test/dummy/db/migrate/20110310210525_attachment_magick_migration.rb +18 -0
- data/test/dummy/db/schema.rb +33 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/images/little_girl.jpg +0 -0
- data/test/dummy/public/images/swfupload/cancelbutton.gif +0 -0
- data/test/dummy/public/javascripts/application.js +60 -0
- data/test/dummy/public/javascripts/jquery-ui.js +763 -0
- data/test/dummy/public/javascripts/jquery.js +7179 -0
- data/test/dummy/public/javascripts/jquery.min.js +167 -0
- data/test/dummy/public/javascripts/rails.js +137 -0
- data/test/dummy/public/javascripts/swfupload/handlers.js +384 -0
- data/test/dummy/public/javascripts/swfupload/swfupload.js +1132 -0
- data/test/dummy/public/javascripts/swfupload/swfupload.swf +0 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/public/stylesheets/attachment_magick.css +10 -0
- data/test/dummy/public/stylesheets/grid.css +491 -0
- data/test/dummy/public/stylesheets/swfupload.css +108 -0
- data/test/dummy/public/stylesheets/text.css +15 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +48 -0
- metadata +283 -0
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
.thumbnails {margin-top:5px; font-size: 12px; line-height: 16px; font-family: Helvetica, Arial, Sans-serif; color:#000;}
|
|
2
|
+
.thumbnails h4 {margin:15px 0px 15px 0px; border-top:2px solid #CCC;}
|
|
3
|
+
.attachment_magick_image {border-bottom: 1px solid #CCC; margin:15px 0px 0px 0px; clear:left; padding: 3px 3px 3px 3px;cursor:pointer;}
|
|
4
|
+
.attachment_magick_image:hover {background:#EEE;}
|
|
5
|
+
|
|
6
|
+
.attachment_magick_image p {margin:0px;}
|
|
7
|
+
.attachment_magick_image a {float:right;}
|
|
8
|
+
.attachment_magick_image input[type="text"] {width:inherit; font-family:inherit; font-size:1em; border:1px solid #999; -webkit-border-radius:3px; -moz-border-radius:3px; margin-left:-2px;}
|
|
9
|
+
|
|
10
|
+
.grid_19 img {margin-left:5px; margin-right:5px;}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
#btnSubmit { margin: 0 0 0 155px ; }
|
|
4
|
+
/* -- Table Styles ------------------------------- */
|
|
5
|
+
td {
|
|
6
|
+
font: 10pt Helvetica, Arial, sans-serif;
|
|
7
|
+
vertical-align: top;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.progressWrapper {
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.progressContainer {
|
|
15
|
+
margin-bottom: 5px;
|
|
16
|
+
padding: 4px;
|
|
17
|
+
border: solid 1px #E8E8E8;
|
|
18
|
+
background-color: #F7F7F7;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
/* Message */
|
|
22
|
+
.message {
|
|
23
|
+
margin: 1em 0;
|
|
24
|
+
padding: 10px 20px;
|
|
25
|
+
border: solid 1px #FFDD99;
|
|
26
|
+
background-color: #FFFFCC;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
}
|
|
29
|
+
/* Error */
|
|
30
|
+
.red {
|
|
31
|
+
border: solid 1px #B50000;
|
|
32
|
+
background-color: #FFEBEB;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Current */
|
|
36
|
+
.green {
|
|
37
|
+
border: solid 1px #DDF0DD;
|
|
38
|
+
background-color: #EBFFEB;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Complete */
|
|
42
|
+
.blue {
|
|
43
|
+
border: solid 1px #CEE2F2;
|
|
44
|
+
background-color: #F0F5FF;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.progressName {
|
|
48
|
+
font-size: 8pt;
|
|
49
|
+
font-weight: 700;
|
|
50
|
+
color: #555;
|
|
51
|
+
width: 323px;
|
|
52
|
+
height: 14px;
|
|
53
|
+
text-align: left;
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.progressBarInProgress,
|
|
59
|
+
.progressBarComplete,
|
|
60
|
+
.progressBarError {
|
|
61
|
+
font-size: 0;
|
|
62
|
+
width: 0%;
|
|
63
|
+
height: 2px;
|
|
64
|
+
background-color: blue;
|
|
65
|
+
margin-top: 2px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.progressBarComplete {
|
|
69
|
+
width: 100%;
|
|
70
|
+
background-color: green;
|
|
71
|
+
visibility: hidden;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.progressBarError {
|
|
75
|
+
width: 100%;
|
|
76
|
+
background-color: red;
|
|
77
|
+
visibility: hidden;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.progressBarStatus {
|
|
81
|
+
margin-top: 2px;
|
|
82
|
+
width: 337px;
|
|
83
|
+
font-size: 7pt;
|
|
84
|
+
font-family: Arial;
|
|
85
|
+
text-align: left;
|
|
86
|
+
white-space: nowrap;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
a.progressCancel {
|
|
90
|
+
font-size: 0;
|
|
91
|
+
display: block;
|
|
92
|
+
height: 14px;
|
|
93
|
+
width: 14px;
|
|
94
|
+
background-image: url(/images/swfupload/cancelbutton.gif);
|
|
95
|
+
background-repeat: no-repeat;
|
|
96
|
+
background-position: -14px 0px;
|
|
97
|
+
float: right;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
a.progressCancel:hover {
|
|
101
|
+
background-position: 0px 0px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/* -- SWFUpload Object Styles ------------------------------- */
|
|
106
|
+
.swfupload {
|
|
107
|
+
vertical-align: top;
|
|
108
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class AttachmentMagick::ImagesControllerTest < ActionController::TestCase
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
create_artist
|
|
7
|
+
create_work(@artist)
|
|
8
|
+
create_place
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test "should create artist image" do
|
|
12
|
+
post :create, artist_hash.merge({ :Filedata => exemple_file })
|
|
13
|
+
assert_response :success
|
|
14
|
+
assert assert_element_in(response.body, "img")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "should create work image" do
|
|
18
|
+
post :create, work_hash.merge({ :Filedata => exemple_file })
|
|
19
|
+
assert_response :success
|
|
20
|
+
assert assert_element_in(response.body, "img")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "should create place image" do
|
|
24
|
+
post :create, place_hash.merge({ :Filedata => exemple_file })
|
|
25
|
+
assert_response :success
|
|
26
|
+
assert assert_element_in(response.body, "img")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "should update priority order" do
|
|
30
|
+
4.times{ @artist.images.create(:photo => exemple_file) }
|
|
31
|
+
@artist.save
|
|
32
|
+
@artist.reload
|
|
33
|
+
|
|
34
|
+
image_first = @artist.images.first
|
|
35
|
+
image_last = @artist.images.last
|
|
36
|
+
|
|
37
|
+
post :update_sortable, artist_hash.merge({ :images => @artist.images.map(&:id).reverse })
|
|
38
|
+
|
|
39
|
+
@artist.reload
|
|
40
|
+
|
|
41
|
+
assert_equal image_first, @artist.images.order_by(:priority.asc).last
|
|
42
|
+
assert_equal image_last, @artist.images.order_by(:priority.asc).first
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test "should destroy image" do
|
|
46
|
+
get :destroy, artist_hash.merge({ :id => @artist.images.first.to_param })
|
|
47
|
+
|
|
48
|
+
@artist.reload
|
|
49
|
+
assert_response :success
|
|
50
|
+
assert_nil @artist.images.first
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def artist_hash
|
|
57
|
+
{:data_attachment => "#{@artist.class.name}_#{@artist.id}"}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def work_hash
|
|
61
|
+
{:data_attachment => "#{@artist.class.name}_#{@artist.id}_works_#{@artist.works.last.id}", :data_partial => exemple_partial}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def place_hash
|
|
65
|
+
{:data_attachment => "#{@place.class.name}_#{@place.id}"}
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
|
4
|
+
tests AttachmentMagick::Generators::InstallGenerator
|
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
prepare_destination
|
|
9
|
+
create_route_file
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "Assert all files are properly created" do
|
|
13
|
+
run_generator
|
|
14
|
+
|
|
15
|
+
assert_file "public/javascripts/swfupload/handlers.js"
|
|
16
|
+
assert_file "public/javascripts/swfupload/swfupload.js"
|
|
17
|
+
assert_file "public/javascripts/swfupload/swfupload.swf"
|
|
18
|
+
assert_file "public/stylesheets/swfupload.css"
|
|
19
|
+
assert_file "public/stylesheets/attachment_magick.css"
|
|
20
|
+
|
|
21
|
+
assert_file "config/routes.rb" do |route|
|
|
22
|
+
assert_match /'attachment_magick\/images#create'/, route
|
|
23
|
+
assert_match /'attachment_magick\/images#update_sortable'/, route
|
|
24
|
+
assert_match /'attachment_magick\/images#destroy'/, route
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def create_route_file
|
|
31
|
+
mkdir File.join(InstallGeneratorTest.destination_root, 'config')
|
|
32
|
+
copy_file File.join(InstallGeneratorTest.destination_root, '../../dummy/config/routes.rb'), File.join(InstallGeneratorTest.destination_root, 'config/routes.rb')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MigrationGeneratorTest < Rails::Generators::TestCase
|
|
4
|
+
tests AttachmentMagick::Generators::MigrationGenerator
|
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
prepare_destination
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test "Assert all files are properly created" do
|
|
12
|
+
run_generator
|
|
13
|
+
|
|
14
|
+
assert Dir["#{File.expand_path("../../tmp", __FILE__)}/**/*.rb"].first.include?("attachment_magick_migration.rb")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class AttachmentMagick::AttachmentMagickHelperTest < ActionView::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
create_artist
|
|
6
|
+
create_work(@artist)
|
|
7
|
+
create_place
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_attachment_progress_container
|
|
11
|
+
html = attachment_progress_container(@artist)
|
|
12
|
+
assert assert_element_in(html, "div[@id='attachmentProgressContainer']")
|
|
13
|
+
assert assert_element_in(html, "span[@id='attachmentButton']")
|
|
14
|
+
assert assert_element_in(html, "input[@id='attachmentmagick_key']")
|
|
15
|
+
assert_equal "Artist_#{@artist.id}", assert_element_value(html, "input[@id='attachmentmagick_key']", "data_attachment")
|
|
16
|
+
|
|
17
|
+
html = attachment_progress_container(@artist.works.first)
|
|
18
|
+
assert assert_element_in(html, "div[@id='attachmentProgressContainer']")
|
|
19
|
+
assert assert_element_in(html, "span[@id='attachmentButton']")
|
|
20
|
+
assert assert_element_in(html, "input[@id='attachmentmagick_key']")
|
|
21
|
+
assert_equal "Artist_#{@artist.id}_works_#{@artist.works.first.id}", assert_element_value(html, "input[@id='attachmentmagick_key']", "data_attachment")
|
|
22
|
+
|
|
23
|
+
html = attachment_progress_container(@place)
|
|
24
|
+
assert assert_element_in(html, "div[@id='attachmentProgressContainer']")
|
|
25
|
+
assert assert_element_in(html, "span[@id='attachmentButton']")
|
|
26
|
+
assert assert_element_in(html, "input[@id='attachmentmagick_key']")
|
|
27
|
+
assert_equal "Place_#{@place.id}", assert_element_value(html, "input[@id='attachmentmagick_key']", "data_attachment")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_attachment_for_view
|
|
31
|
+
html = attachment_for_view(@artist)
|
|
32
|
+
assert assert_element_in(html, "a[@class='remove_image']")
|
|
33
|
+
assert assert_element_in(html, "input[@id='image_id']")
|
|
34
|
+
|
|
35
|
+
html = attachment_for_view(@artist, exemple_partial)
|
|
36
|
+
assert assert_element_in(html, "div[@class='image_caption']")
|
|
37
|
+
assert assert_element_in(html, "div[@class='image_thumb']")
|
|
38
|
+
assert assert_element_in(html, "img")
|
|
39
|
+
|
|
40
|
+
html = attachment_for_view(@place)
|
|
41
|
+
assert assert_element_in(html, "a[@class='remove_image']")
|
|
42
|
+
assert assert_element_in(html, "input[@id='image_id']")
|
|
43
|
+
|
|
44
|
+
html = attachment_for_view(@place, exemple_partial)
|
|
45
|
+
assert assert_element_in(html, "div[@class='image_caption']")
|
|
46
|
+
assert assert_element_in(html, "div[@class='image_thumb']")
|
|
47
|
+
assert assert_element_in(html, "img")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_attachment_for_video
|
|
51
|
+
html = attachment_for_video
|
|
52
|
+
|
|
53
|
+
assert assert_element_in(html, "input")
|
|
54
|
+
assert assert_element_in(html, "a[@class='video_upload']")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ArtistTest < ActiveSupport::TestCase
|
|
4
|
+
def test_access_grid_method
|
|
5
|
+
assert_equal "36x36", Artist.style_thumb
|
|
6
|
+
assert_equal "54x", Artist.style_grid_1
|
|
7
|
+
assert_equal "150x", Artist.style_grid_10
|
|
8
|
+
assert_equal "200x300#", Artist.style_grid_15
|
|
9
|
+
assert_equal "909x230#", Artist.style_grid_16
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
|
|
4
|
+
class AttachmentMagickTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
class Dog
|
|
7
|
+
include Mongoid::Document
|
|
8
|
+
include AttachmentMagick
|
|
9
|
+
|
|
10
|
+
field :name
|
|
11
|
+
|
|
12
|
+
attachment_magick do
|
|
13
|
+
grid_1
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Cat
|
|
18
|
+
include Mongoid::Document
|
|
19
|
+
include AttachmentMagick
|
|
20
|
+
|
|
21
|
+
field :name
|
|
22
|
+
|
|
23
|
+
attachment_magick do
|
|
24
|
+
grid_1 "300x150"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "deveria manter o valor do grid original" do
|
|
29
|
+
assert_equal "300x150#", Cat.style_grid_1
|
|
30
|
+
assert_equal "54x", Dog.style_grid_1
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_has_attachment_magick
|
|
34
|
+
grids = Artist.send(:generate_grids)
|
|
35
|
+
|
|
36
|
+
Artist.attachment_magick do
|
|
37
|
+
grid_1
|
|
38
|
+
grid_5 "120x240"
|
|
39
|
+
grid_7 :height => 200
|
|
40
|
+
grid_10 :height => 200, :width => 100
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
assert_equal [:grid_1, :grid_5, :grid_7, :grid_10], order_array(Artist.attachment_magick_default_options[:styles].keys)
|
|
44
|
+
|
|
45
|
+
assert_equal grids[:grid_1][:width], Artist.attachment_magick_default_options[:styles][:grid_1][:width]
|
|
46
|
+
assert_equal grids[:grid_1][:height], Artist.attachment_magick_default_options[:styles][:grid_1][:height]
|
|
47
|
+
|
|
48
|
+
assert_equal 120, Artist.attachment_magick_default_options[:styles][:grid_5][:width]
|
|
49
|
+
assert_equal 240, Artist.attachment_magick_default_options[:styles][:grid_5][:height]
|
|
50
|
+
|
|
51
|
+
assert_equal grids[:grid_7][:width], Artist.attachment_magick_default_options[:styles][:grid_7][:width]
|
|
52
|
+
assert_equal 200, Artist.attachment_magick_default_options[:styles][:grid_7][:height]
|
|
53
|
+
|
|
54
|
+
assert_equal 100, Artist.attachment_magick_default_options[:styles][:grid_10][:width]
|
|
55
|
+
assert_equal 200, Artist.attachment_magick_default_options[:styles][:grid_10][:height]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_generate_grids
|
|
59
|
+
column_width = 29
|
|
60
|
+
column_amount = 10
|
|
61
|
+
gutter = 3
|
|
62
|
+
|
|
63
|
+
grid_system = open("http://www.spry-soft.com/grids/grid/?column_width=#{column_width}&column_amount=#{column_amount}&gutter_width=#{gutter}") { |url| Hpricot(url) }
|
|
64
|
+
grids = Artist.send(:generate_grids, column_amount, column_width, gutter)
|
|
65
|
+
|
|
66
|
+
assert_equal grids.size, column_amount + AttachmentMagick.configuration.custom_styles.styles.size
|
|
67
|
+
|
|
68
|
+
grids.keys.each do |key|
|
|
69
|
+
assert_equal grids[key][:width], grid_system.search(".#{key} p").first.inner_html.gsub(/\D/, "").to_i if key.to_s.include?("grid")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_setup
|
|
74
|
+
AttachmentMagick.setup do |config|
|
|
75
|
+
config.columns_amount = 19
|
|
76
|
+
config.columns_width = 54
|
|
77
|
+
config.gutter = 3
|
|
78
|
+
|
|
79
|
+
config.custom_styles do
|
|
80
|
+
small "36x46"
|
|
81
|
+
full :width => 1024
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Artist.attachment_magick do
|
|
86
|
+
small
|
|
87
|
+
full
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
assert_equal 19, AttachmentMagick.configuration.columns_amount
|
|
91
|
+
assert_equal 54, AttachmentMagick.configuration.columns_width
|
|
92
|
+
assert_equal 3, AttachmentMagick.configuration.gutter
|
|
93
|
+
|
|
94
|
+
assert_equal 36, Artist.attachment_magick_default_options[:styles][:small][:width]
|
|
95
|
+
assert_equal 46, Artist.attachment_magick_default_options[:styles][:small][:height]
|
|
96
|
+
|
|
97
|
+
assert_equal 1024, Artist.attachment_magick_default_options[:styles][:full][:width]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def order_array(array)
|
|
103
|
+
array.sort{|x, y| x.to_s.split("_")[1].to_i <=> y.to_s.split("_")[1].to_i}
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class AttachmentMagick::ImageTest < ActiveSupport::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
create_artist
|
|
6
|
+
create_place
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_create_thumb_for_vimeo_in_a_new_field
|
|
10
|
+
@artist_image = @artist.images.create({:source => 'http://vimeo.com/14074949'})
|
|
11
|
+
@place_image = @place.images.create({:source => 'http://vimeo.com/14074949'})
|
|
12
|
+
|
|
13
|
+
assert_equal %'<iframe src=\"http://player.vimeo.com/video/14074949?title=0&byline=0&portrait=0\" width=\"620\" height=\"465\" frameborder=\"0\"></iframe>', @artist_image.source_to_html
|
|
14
|
+
assert_equal 'http://b.vimeocdn.com/ts/937/359/93735969_640.jpg', @artist_image.source_to_image
|
|
15
|
+
assert_equal %'<iframe src=\"http://player.vimeo.com/video/14074949?title=0&byline=0&portrait=0\" width=\"620\" height=\"465\" frameborder=\"0\"></iframe>', @place_image.source_to_html
|
|
16
|
+
assert_equal 'http://b.vimeocdn.com/ts/937/359/93735969_640.jpg', @place_image.source_to_image
|
|
17
|
+
|
|
18
|
+
@artist_image = @artist.images.create({:source => 'http://www.youtube.com/watch?v=FUe83k3t_0s'})
|
|
19
|
+
@place_image = @place.images.create({:source => 'http://www.youtube.com/watch?v=FUe83k3t_0s'})
|
|
20
|
+
|
|
21
|
+
assert_equal %'<iframe class="youtube-player" type="text/html" width="620" height="465" src="http://www.youtube.com/embed/FUe83k3t_0s" frameborder="0">\n</iframe>', @artist_image.source_to_html
|
|
22
|
+
assert_equal 'http://i1.ytimg.com/vi/FUe83k3t_0s/default.jpg', @artist_image.source_to_image
|
|
23
|
+
assert_equal %'<iframe class="youtube-player" type="text/html" width="620" height="465" src="http://www.youtube.com/embed/FUe83k3t_0s" frameborder="0">\n</iframe>', @place_image.source_to_html
|
|
24
|
+
assert_equal 'http://i1.ytimg.com/vi/FUe83k3t_0s/default.jpg', @place_image.source_to_image
|
|
25
|
+
end
|
|
26
|
+
end
|
data/test/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
|
5
|
+
require 'rake'
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class ArtistsController < ApplicationController
|
|
2
|
+
before_filter :load_artist, :only => [:edit, :update, :destroy]
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@artists = Artist.all
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
@artist = Artist.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
@artist = Artist.new(params[:artist])
|
|
14
|
+
@artist.save
|
|
15
|
+
|
|
16
|
+
redirect_to edit_artist_path(@artist)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def update
|
|
20
|
+
@artist.update_attributes(params[:artist])
|
|
21
|
+
redirect_to edit_artist_path(@artist)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def destroy
|
|
25
|
+
@artist.destroy
|
|
26
|
+
redirect_to artists_path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def load_artist
|
|
32
|
+
@artist = Artist.find(params[:id])
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class PlacesController < ApplicationController
|
|
2
|
+
before_filter :load_place, :only => [:edit, :update, :destroy]
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@places = Place.all
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
@place = Place.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
@place = Place.new(params[:place])
|
|
14
|
+
@place.save
|
|
15
|
+
|
|
16
|
+
redirect_to edit_place_path(@place)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def update
|
|
20
|
+
@place.update_attributes(params[:place])
|
|
21
|
+
redirect_to edit_place_path(@place)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def destroy
|
|
25
|
+
@place.destroy
|
|
26
|
+
redirect_to places_path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def load_place
|
|
32
|
+
@place = Place.find(params[:id])
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class WorksController < ApplicationController
|
|
2
|
+
before_filter :load_artist
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@works = @artist.works
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
@work = @artist.works.build
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def edit
|
|
13
|
+
@work = @artist.works.find(params[:id])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create
|
|
17
|
+
@work = @artist.works.create(params[:work])
|
|
18
|
+
redirect_to edit_artist_work_path(@artist, @work)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update
|
|
22
|
+
@work = @artist.works.find(params[:id])
|
|
23
|
+
@work.update_attributes(params[:work])
|
|
24
|
+
redirect_to edit_artist_work_path(@artist, @work)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def destroy
|
|
28
|
+
@artist.works.find(params[:id]).destroy
|
|
29
|
+
redirect_to artists_path
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def load_artist
|
|
35
|
+
@artist = Artist.find(params[:artist_id])
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Artist
|
|
2
|
+
include Mongoid::Document
|
|
3
|
+
include AttachmentMagick
|
|
4
|
+
|
|
5
|
+
field :name
|
|
6
|
+
field :lastname
|
|
7
|
+
embeds_many :works
|
|
8
|
+
|
|
9
|
+
validates_presence_of :name, :lastname
|
|
10
|
+
|
|
11
|
+
attachment_magick do
|
|
12
|
+
grid_1
|
|
13
|
+
grid_10 :width => 150
|
|
14
|
+
grid_15 "200x300"
|
|
15
|
+
grid_16 :height => 230
|
|
16
|
+
thumb :crop => false
|
|
17
|
+
fullscreen
|
|
18
|
+
publisher
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<%unless @artist.new_record?%>
|
|
2
|
+
<div class="grid_3 tpush_2">
|
|
3
|
+
<%= link_to "Novo trabalho", new_artist_work_path(@artist)%>
|
|
4
|
+
<br />
|
|
5
|
+
<br />
|
|
6
|
+
<span>trabalhos</span>
|
|
7
|
+
<%@artist.works.each do |work|%>
|
|
8
|
+
<br />
|
|
9
|
+
<%=link_to work.name, edit_artist_work_path(@artist, work)%>
|
|
10
|
+
<% end %>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div class="grid_13 tpush_2">
|
|
14
|
+
<%=form_for @artist, :html => {:multipart => true} do |form|%>
|
|
15
|
+
<%=form.label :name%>
|
|
16
|
+
<%=form.text_field :name%>
|
|
17
|
+
|
|
18
|
+
<%=form.label :lastname%>
|
|
19
|
+
<%=form.text_field :lastname%>
|
|
20
|
+
<%=form.submit%>
|
|
21
|
+
<br />
|
|
22
|
+
<br />
|
|
23
|
+
|
|
24
|
+
<%= attachment_progress_container @artist%>
|
|
25
|
+
<%= attachment_for_view @artist%>
|
|
26
|
+
<%= attachment_for_video%>
|
|
27
|
+
<% end %>
|
|
28
|
+
</div>
|
|
29
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render :partial => "form" %>
|