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.
Files changed (107) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +159 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +98 -0
  6. data/Rakefile +13 -0
  7. data/app/controllers/attachment_magick/images_controller.rb +50 -0
  8. data/app/helpers/attachment_magick/attachment_magick_helper.rb +57 -0
  9. data/app/models/attachment_magick/active_record_image.rb +18 -0
  10. data/app/models/attachment_magick/mongoid_image.rb +29 -0
  11. data/app/views/layouts/attachment_magick/images/_add_image.html.erb +18 -0
  12. data/app/views/layouts/attachment_magick/images/_video_upload.html.erb +2 -0
  13. data/attachment_magick.gemspec +25 -0
  14. data/lib/attachment_magick/configuration/configuration.rb +28 -0
  15. data/lib/attachment_magick/configuration/custom_style.rb +19 -0
  16. data/lib/attachment_magick/dragonfly/init.rb +20 -0
  17. data/lib/attachment_magick/dsl.rb +37 -0
  18. data/lib/attachment_magick/railtie.rb +10 -0
  19. data/lib/attachment_magick/test/attachment_magick_test_helper.rb +43 -0
  20. data/lib/attachment_magick/version.rb +3 -0
  21. data/lib/attachment_magick.rb +78 -0
  22. data/lib/generators/attachment_magick/install_generator.rb +15 -0
  23. data/lib/generators/attachment_magick/migration_generator.rb +17 -0
  24. data/lib/generators/attachment_magick/templates/attachment_magick_migration.rb +18 -0
  25. data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/handlers.js +384 -0
  26. data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/swfupload.js +1132 -0
  27. data/lib/generators/attachment_magick/templates/public/javascripts/swfupload/swfupload.swf +0 -0
  28. data/lib/generators/attachment_magick/templates/public/stylesheets/attachment_magick.css +10 -0
  29. data/lib/generators/attachment_magick/templates/public/stylesheets/swfupload.css +108 -0
  30. data/test/attachment_magick/controllers/images_controller_test.rb +67 -0
  31. data/test/attachment_magick/generators/install_generator_test.rb +34 -0
  32. data/test/attachment_magick/generators/migration_generator_test.rb +16 -0
  33. data/test/attachment_magick/helpers/attachment_magick_test.rb +56 -0
  34. data/test/attachment_magick/units/artist_test.rb +11 -0
  35. data/test/attachment_magick/units/attachment_magick_test.rb +105 -0
  36. data/test/attachment_magick/units/image_test.rb +26 -0
  37. data/test/attachment_magick/units/place_test.rb +8 -0
  38. data/test/dummy/Rakefile +7 -0
  39. data/test/dummy/app/controllers/application_controller.rb +4 -0
  40. data/test/dummy/app/controllers/artists_controller.rb +34 -0
  41. data/test/dummy/app/controllers/places_controller.rb +34 -0
  42. data/test/dummy/app/controllers/works_controller.rb +37 -0
  43. data/test/dummy/app/helpers/application_helper.rb +2 -0
  44. data/test/dummy/app/helpers/artists_helper.rb +2 -0
  45. data/test/dummy/app/helpers/places_helper.rb +2 -0
  46. data/test/dummy/app/helpers/works_helper.rb +2 -0
  47. data/test/dummy/app/models/artist.rb +20 -0
  48. data/test/dummy/app/models/place.rb +8 -0
  49. data/test/dummy/app/models/work.rb +13 -0
  50. data/test/dummy/app/views/artists/_form.html.erb +29 -0
  51. data/test/dummy/app/views/artists/edit.html.erb +1 -0
  52. data/test/dummy/app/views/artists/index.html.erb +39 -0
  53. data/test/dummy/app/views/artists/new.html.erb +1 -0
  54. data/test/dummy/app/views/layouts/_custom_images_list.html.erb +6 -0
  55. data/test/dummy/app/views/layouts/application.html.erb +27 -0
  56. data/test/dummy/app/views/places/_form.html.erb +12 -0
  57. data/test/dummy/app/views/places/edit.html.erb +1 -0
  58. data/test/dummy/app/views/places/index.html.erb +32 -0
  59. data/test/dummy/app/views/places/new.html.erb +1 -0
  60. data/test/dummy/app/views/works/_form.html.erb +18 -0
  61. data/test/dummy/app/views/works/edit.html.erb +1 -0
  62. data/test/dummy/app/views/works/index.html.erb +32 -0
  63. data/test/dummy/app/views/works/new.html.erb +1 -0
  64. data/test/dummy/config/application.rb +24 -0
  65. data/test/dummy/config/boot.rb +10 -0
  66. data/test/dummy/config/database.yml +22 -0
  67. data/test/dummy/config/environment.rb +5 -0
  68. data/test/dummy/config/environments/development.rb +26 -0
  69. data/test/dummy/config/environments/production.rb +49 -0
  70. data/test/dummy/config/environments/test.rb +35 -0
  71. data/test/dummy/config/initializers/attachment_magick_setup.rb +12 -0
  72. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/test/dummy/config/initializers/inflections.rb +10 -0
  74. data/test/dummy/config/initializers/mime_types.rb +5 -0
  75. data/test/dummy/config/initializers/secret_token.rb +7 -0
  76. data/test/dummy/config/initializers/session_store.rb +8 -0
  77. data/test/dummy/config/locales/en.yml +5 -0
  78. data/test/dummy/config/mongoid.yml +18 -0
  79. data/test/dummy/config/routes.rb +15 -0
  80. data/test/dummy/config.ru +4 -0
  81. data/test/dummy/db/migrate/20110310155855_create_places.rb +13 -0
  82. data/test/dummy/db/migrate/20110310210525_attachment_magick_migration.rb +18 -0
  83. data/test/dummy/db/schema.rb +33 -0
  84. data/test/dummy/public/404.html +26 -0
  85. data/test/dummy/public/422.html +26 -0
  86. data/test/dummy/public/500.html +26 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/dummy/public/images/little_girl.jpg +0 -0
  89. data/test/dummy/public/images/swfupload/cancelbutton.gif +0 -0
  90. data/test/dummy/public/javascripts/application.js +60 -0
  91. data/test/dummy/public/javascripts/jquery-ui.js +763 -0
  92. data/test/dummy/public/javascripts/jquery.js +7179 -0
  93. data/test/dummy/public/javascripts/jquery.min.js +167 -0
  94. data/test/dummy/public/javascripts/rails.js +137 -0
  95. data/test/dummy/public/javascripts/swfupload/handlers.js +384 -0
  96. data/test/dummy/public/javascripts/swfupload/swfupload.js +1132 -0
  97. data/test/dummy/public/javascripts/swfupload/swfupload.swf +0 -0
  98. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  99. data/test/dummy/public/stylesheets/attachment_magick.css +10 -0
  100. data/test/dummy/public/stylesheets/grid.css +491 -0
  101. data/test/dummy/public/stylesheets/swfupload.css +108 -0
  102. data/test/dummy/public/stylesheets/text.css +15 -0
  103. data/test/dummy/script/rails +6 -0
  104. data/test/integration/navigation_test.rb +7 -0
  105. data/test/support/integration_case.rb +5 -0
  106. data/test/test_helper.rb +48 -0
  107. metadata +283 -0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ .DS_Store
8
+ rcov/
9
+ tmp/
10
+ coverage/
11
+ ._*
12
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.3"
4
+ gem "capybara", ">= 0.4.0"
5
+ gem "sqlite3-ruby", :require => "sqlite3"
6
+
7
+ gem 'mongoid', '>=2.0.0.rc.6'
8
+ gem 'bson_ext', '>= 1.2.0'
9
+ gem 'nokogiri'
10
+ gem 'hpricot'
11
+ gem 'colorific'
12
+ gem 'ruby-debug19'
13
+ gem 'simplecov'
14
+ # Specify your gem's dependencies in attachment_magick.gemspec
15
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,159 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ attachment_magick (0.0.1)
5
+ dragonfly (>= 0.8.1)
6
+ jquery-rails (>= 0.2.7)
7
+ marcosinger-auto_html (>= 1.3.4)
8
+ rack-cache (>= 1.0)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ abstract (1.0.0)
14
+ actionmailer (3.0.3)
15
+ actionpack (= 3.0.3)
16
+ mail (~> 2.2.9)
17
+ actionpack (3.0.3)
18
+ activemodel (= 3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ erubis (~> 2.6.6)
22
+ i18n (~> 0.4)
23
+ rack (~> 1.2.1)
24
+ rack-mount (~> 0.6.13)
25
+ rack-test (~> 0.5.6)
26
+ tzinfo (~> 0.3.23)
27
+ activemodel (3.0.3)
28
+ activesupport (= 3.0.3)
29
+ builder (~> 2.1.2)
30
+ i18n (~> 0.4)
31
+ activerecord (3.0.3)
32
+ activemodel (= 3.0.3)
33
+ activesupport (= 3.0.3)
34
+ arel (~> 2.0.2)
35
+ tzinfo (~> 0.3.23)
36
+ activeresource (3.0.3)
37
+ activemodel (= 3.0.3)
38
+ activesupport (= 3.0.3)
39
+ activesupport (3.0.3)
40
+ archive-tar-minitar (0.5.2)
41
+ arel (2.0.9)
42
+ bson (1.3.0)
43
+ bson_ext (1.3.0)
44
+ builder (2.1.2)
45
+ capybara (0.4.1.2)
46
+ celerity (>= 0.7.9)
47
+ culerity (>= 0.2.4)
48
+ mime-types (>= 1.16)
49
+ nokogiri (>= 1.3.3)
50
+ rack (>= 1.0.0)
51
+ rack-test (>= 0.5.4)
52
+ selenium-webdriver (>= 0.0.27)
53
+ xpath (~> 0.1.3)
54
+ celerity (0.8.9)
55
+ childprocess (0.1.8)
56
+ ffi (~> 1.0.6)
57
+ colorific (0.0.2)
58
+ minitest (~> 2.0)
59
+ ruby-progressbar (>= 0.0.9)
60
+ columnize (0.3.2)
61
+ culerity (0.2.15)
62
+ dragonfly (0.8.2)
63
+ rack
64
+ erubis (2.6.6)
65
+ abstract (>= 1.0.0)
66
+ ffi (1.0.7)
67
+ rake (>= 0.8.7)
68
+ hpricot (0.8.4)
69
+ i18n (0.5.0)
70
+ jquery-rails (0.2.7)
71
+ rails (~> 3.0)
72
+ thor (~> 0.14.4)
73
+ json_pure (1.5.1)
74
+ linecache19 (0.5.12)
75
+ ruby_core_source (>= 0.1.4)
76
+ mail (2.2.15)
77
+ activesupport (>= 2.3.6)
78
+ i18n (>= 0.4.0)
79
+ mime-types (~> 1.16)
80
+ treetop (~> 1.4.8)
81
+ marcosinger-auto_html (1.3.4)
82
+ mime-types (1.16)
83
+ minitest (2.0.2)
84
+ mongo (1.3.0)
85
+ bson (>= 1.3.0)
86
+ mongoid (2.0.1)
87
+ activemodel (~> 3.0)
88
+ mongo (~> 1.3)
89
+ tzinfo (~> 0.3.22)
90
+ will_paginate (~> 3.0.pre)
91
+ nokogiri (1.4.4)
92
+ polyglot (0.3.1)
93
+ rack (1.2.2)
94
+ rack-cache (1.0)
95
+ rack (>= 0.4)
96
+ rack-mount (0.6.14)
97
+ rack (>= 1.0.0)
98
+ rack-test (0.5.7)
99
+ rack (>= 1.0)
100
+ rails (3.0.3)
101
+ actionmailer (= 3.0.3)
102
+ actionpack (= 3.0.3)
103
+ activerecord (= 3.0.3)
104
+ activeresource (= 3.0.3)
105
+ activesupport (= 3.0.3)
106
+ bundler (~> 1.0)
107
+ railties (= 3.0.3)
108
+ railties (3.0.3)
109
+ actionpack (= 3.0.3)
110
+ activesupport (= 3.0.3)
111
+ rake (>= 0.8.7)
112
+ thor (~> 0.14.4)
113
+ rake (0.8.7)
114
+ ruby-debug-base19 (0.11.25)
115
+ columnize (>= 0.3.1)
116
+ linecache19 (>= 0.5.11)
117
+ ruby_core_source (>= 0.1.4)
118
+ ruby-debug19 (0.11.6)
119
+ columnize (>= 0.3.1)
120
+ linecache19 (>= 0.5.11)
121
+ ruby-debug-base19 (>= 0.11.19)
122
+ ruby-progressbar (0.0.9)
123
+ ruby_core_source (0.1.5)
124
+ archive-tar-minitar (>= 0.5.2)
125
+ rubyzip (0.9.4)
126
+ selenium-webdriver (0.1.4)
127
+ childprocess (>= 0.1.7)
128
+ ffi (>= 1.0.7)
129
+ json_pure
130
+ rubyzip
131
+ simplecov (0.4.2)
132
+ simplecov-html (~> 0.4.4)
133
+ simplecov-html (0.4.4)
134
+ sqlite3 (1.3.3)
135
+ sqlite3-ruby (1.3.3)
136
+ sqlite3 (>= 1.3.3)
137
+ thor (0.14.6)
138
+ treetop (1.4.9)
139
+ polyglot (>= 0.3.1)
140
+ tzinfo (0.3.26)
141
+ will_paginate (3.0.pre2)
142
+ xpath (0.1.3)
143
+ nokogiri (~> 1.3)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ attachment_magick!
150
+ bson_ext (>= 1.2.0)
151
+ capybara (>= 0.4.0)
152
+ colorific
153
+ hpricot
154
+ mongoid (>= 2.0.0.rc.6)
155
+ nokogiri
156
+ rails (= 3.0.3)
157
+ ruby-debug19
158
+ simplecov
159
+ sqlite3-ruby
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,98 @@
1
+ == AttachmentMagick
2
+
3
+ Attachment Magick is a gem to upload images and videos(vimeo) using swfupload.
4
+ Supports Mongoid, coming soon support to activerecord.
5
+
6
+ == Installation
7
+
8
+ This gem is not released yet, some dependencies are still necessary
9
+ Add to Gemfile
10
+
11
+ #AttachmentMagick requires
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'
16
+
17
+ Then run
18
+
19
+ bundle install
20
+
21
+ After the gem installation, run the generator
22
+
23
+ attachment_magick:install
24
+
25
+ The generator will install swfupload (js and css files) and will create some routes.
26
+
27
+ Create a initializer like this (config/initializers/attachment_magick_setup.rb)
28
+
29
+ AttachmentMagick.setup do |config|
30
+ config.default_add_partial = '/layouts/attachment_magick/images/add_image'
31
+ config.columns_amount = 16
32
+ config.columns_width = 52
33
+ config.gutter = 8
34
+
35
+ config.custom_styles do
36
+ publisher "52x"
37
+ custom_style "50x50"
38
+ end
39
+ end
40
+
41
+ * Attachment Magick is based in 960 Grid System (http://960.gs/)
42
+
43
+ Add to application.rb
44
+
45
+ config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/media'
46
+ config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
47
+ :verbose => true,
48
+ :metastore => "file:#{Rails.root}/tmp/dragonfly/cache/meta",
49
+ :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body"
50
+ }
51
+
52
+ == Getting started
53
+
54
+ Include the js files to your application layout or page
55
+
56
+ javascript_include_tag :defaults, "swfupload/handlers", "swfupload/swfupload"
57
+
58
+ Include AttachmentMagick Module to your model
59
+
60
+ class Post
61
+ include Mongoid::Document
62
+ include AttachmentMagick
63
+
64
+ field :title
65
+ end
66
+
67
+ Call this helpers in form views
68
+
69
+ attachment_progress_container @post
70
+ attachment_for_view @post
71
+ attachment_for_video
72
+
73
+ == Customizing views
74
+
75
+ === Just Images
76
+
77
+ <div class="attachment_magick_image" id="image_<%=image.id%>" style="width:inerit; margin-bottom:10px;">
78
+ <%= image_tag image.photo.thumb(image._parent.class.style_publisher).url%>
79
+ <input id ="image_id" type ="hidden" value ="<%=image.id%>">
80
+
81
+ <%= link_to "[x]", "javascript://", :class => "remove_image", :style => "float:right;"%>
82
+ </div>
83
+
84
+ <%= attachment_for_view @post, "path_to_my_partial" %>
85
+
86
+ == Customizing sizes
87
+
88
+ class Post
89
+ include Mongoid::Document
90
+ include AttachmentMagick
91
+
92
+ field :title
93
+
94
+ attachment_magick do
95
+ grid_1 "100x100"
96
+ end
97
+ end
98
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = true
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,50 @@
1
+ class AttachmentMagick::ImagesController < ActionController::Base
2
+ # protect_from_forgery :except => :create
3
+ respond_to :html, :js
4
+ before_filter :load_klass
5
+
6
+ def create
7
+ @image = @klass.images.create(:photo => params[:Filedata], :source => params[:source], :image_type => params[:data_type])
8
+ @klass.save
9
+
10
+ if params[:data_partial].present?
11
+ render :partial => params[:data_partial], :collection => [@image], :as => :image
12
+ else
13
+ render :partial => AttachmentMagick.configuration.default_add_partial, :collection => [@image], :as => :image, :locals => { :size => @klass.class.style_publisher }
14
+ end
15
+ end
16
+
17
+ def update_sortable
18
+ array_ids = params[:images]
19
+ hash = {}
20
+
21
+ array_ids.each_with_index do |id, index|
22
+ hash.merge!( {"#{index}" => {:id => "#{id}", :priority => index}} )
23
+ end
24
+
25
+ @klass.images_attributes = hash
26
+ @klass.save
27
+
28
+ render :text => "ok"
29
+ end
30
+
31
+ def destroy
32
+ @klass.images.find(params[:id]).destroy
33
+ render :text => "ok"
34
+ end
35
+
36
+ private
37
+
38
+ def load_klass
39
+ query = ""
40
+ objects = params[:data_attachment].split("_")
41
+ objects = objects.in_groups_of(2)
42
+
43
+ objects.each do |el|
44
+ str = objects.index(el) == 0 ? "" : "."
45
+ query << "#{str}#{el.first}.find('#{el.last}')"
46
+ end
47
+
48
+ @klass = eval(query)
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: UTF-8
2
+
3
+ module AttachmentMagick::AttachmentMagickHelper
4
+ def attachment_progress_container(object, data_type="images")
5
+ unless object.new_record?
6
+ obj = object
7
+ key = "#{object.class.to_s.underscore}_#{object.id}"
8
+
9
+ if obj.respond_to?(:embedded?)
10
+ if obj.embedded?
11
+ embedded_in = obj.relations.values.select { |x| x.macro == :embedded_in}.first
12
+ parent = embedded_in.class_name
13
+ parent_id = obj._parent.id.to_s
14
+ inverse_of = embedded_in.inverse_of
15
+ text_eval = "#{parent}_#{parent_id}_#{inverse_of}_#{obj.id.to_s}"
16
+ end
17
+ end
18
+
19
+ data_attachment = text_eval.blank? ? "#{object.class}_#{object.id}" : text_eval
20
+
21
+ html = %{<div id='attachmentProgressContainer'></div>
22
+ <span id='attachmentButton'></span>
23
+ <input id='attachmentmagick_key' data_attachment='#{data_attachment}' data_type='#{data_type}' type='hidden' value='#{key}'>
24
+ }
25
+
26
+ html.html_safe
27
+ end
28
+ end
29
+
30
+ def attachment_for_view(object, partial = nil, collection=nil, use_sortable=true)
31
+ unless object.new_record?
32
+ unless collection.present?
33
+ if defined? Mongoid::Document
34
+ if object.class.include?(Mongoid::Document)
35
+ collection = object.images.order_by(:priority.asc)
36
+ end
37
+ end
38
+
39
+ if defined? ActiveRecord::Persistence
40
+ if object.class.include?(ActiveRecord::Persistence)
41
+ collection = object.images.order(:priority)
42
+ end
43
+ end
44
+ end
45
+
46
+ key = "#{object.class.to_s.underscore}_#{object.id}"
47
+ html_partial = "<input id='attachmentmagick_partial' data-partial='#{partial}' type='hidden' value='#{key}'>" if partial
48
+ html = render(:partial => partial || AttachmentMagick.configuration.default_add_partial, :collection => collection, :as =>:image)
49
+
50
+ "#{html_partial}<div id='#{key}' class='#{'attachmentSortable' if use_sortable}'>#{html}</div><div></div>".html_safe
51
+ end
52
+ end
53
+
54
+ def attachment_for_video
55
+ %{<label>vídeo</label><ol class='form-block'>#{render :partial => "layouts/attachment_magick/images/video_upload"}</ol>}.html_safe
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module AttachmentMagick
2
+ class ActiveRecordImage < ActiveRecord::Base
3
+ set_table_name "amagick_images"
4
+
5
+ belongs_to :imageable, :polymorphic => true
6
+ image_accessor :photo
7
+
8
+ auto_html_for :source => "_to_html" do
9
+ youtube(:width => 620, :height => 465)
10
+ vimeo(:width => 620, :height => 465)
11
+ end
12
+
13
+ auto_html_for :source => "_to_image" do
14
+ youtube_image
15
+ vimeo_image(:size => :large)
16
+ end
17
+ end if defined? ActiveRecord::Persistence
18
+ end
@@ -0,0 +1,29 @@
1
+ module AttachmentMagick
2
+ class MongoidImage
3
+ include Mongoid::Document
4
+ include AutoHtml
5
+ include AutoHtmlFor
6
+
7
+ field :photo_uid
8
+ field :caption
9
+ field :priority
10
+ field :source
11
+ field :image_type
12
+ image_accessor :photo
13
+ embedded_in :imageable, :inverse_of => :image
14
+
15
+ auto_html_for :source => "_to_html" do
16
+ youtube(:width => 620, :height => 465)
17
+ vimeo(:width => 620, :height => 465)
18
+ end
19
+
20
+ auto_html_for :source => "_to_image" do
21
+ youtube_image
22
+ vimeo_image(:size => :large)
23
+ end
24
+
25
+ def imageable
26
+ self._parent
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ <div class="grid_5 attachment_magick_image">
2
+ <div class="grid_3 alpha">
3
+ <%= image_tag image.source.nil? ? image.photo.thumb(image.imageable.class.style_publisher).url : image.source_to_image%>
4
+ <input type="hidden" value="<%= image.id%>" id="image_id">
5
+ </div>
6
+ <div class="grid_2 omega">
7
+ <p>
8
+ <%= link_to "remover", "javascript://", :class => "remove_image"%>
9
+ <br />
10
+ <%= link_to "ver original", image.source || image.photo.url, :target => "blank"%>
11
+ </p>
12
+ </div>
13
+ <div class="grid_5 alpha omega">
14
+ <label>LEGENDA</label>
15
+ <%= text_field_tag "#{image.imageable.class.name.downcase}[images_attributes][#{image.id}][caption]", image.caption%>
16
+ <%= hidden_field_tag "#{image.imageable.class.name.downcase}[images_attributes][#{image.id}][id]", image.id%>
17
+ </div>
18
+ </div>
@@ -0,0 +1,2 @@
1
+ <%= text_field_tag "image[source]"%>
2
+ <%= link_to "UPLOAD VÍDEO", "javascript://", :class => "video_upload"%>
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "attachment_magick/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "attachment_magick"
7
+ s.version = AttachmentMagick::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Marco Antônio Singer", "Carlos Brando"]
10
+ s.email = ["markaum@gmail.com", "eduardobrando@gmail.com"]
11
+ s.homepage = "http://github.com/marcosinger/attachment_magick"
12
+ s.summary = "little more magick when you upload image files (with SwfUpload and Dragonfly)"
13
+
14
+ s.rubyforge_project = "attachment_magick"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'dragonfly', '>= 0.8.1'
22
+ s.add_dependency 'rack-cache', '>= 1.0'
23
+ s.add_dependency 'jquery-rails', '>= 0.2.7'
24
+ s.add_dependency 'marcosinger-auto_html', '>= 1.3.4'
25
+ end
@@ -0,0 +1,28 @@
1
+ require "attachment_magick/configuration/custom_style"
2
+
3
+ module AttachmentMagick
4
+ class Configuration
5
+
6
+ attr_accessor :columns_amount
7
+ attr_accessor :columns_width
8
+ attr_accessor :gutter
9
+ attr_accessor :default_add_partial
10
+
11
+ def initialize
12
+ @columns_amount = 19
13
+ @columns_width = 54
14
+ @gutter = 3
15
+ @custom_styles = []
16
+ @default_add_partial = "layouts/attachment_magick/images/add_image"
17
+ end
18
+
19
+ def custom_styles(&block)
20
+ if block_given?
21
+ @custom_styles = CustomStyle.new
22
+ @custom_styles.instance_eval(&block)
23
+ else
24
+ return @custom_styles
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module AttachmentMagick
2
+ class CustomStyle
3
+
4
+ def method_missing(meth, *args, &blk)
5
+ instance_variable_set "@#{meth}", args.first
6
+ self.class.class_eval { attr_reader meth.to_sym }
7
+ end
8
+
9
+ def styles
10
+ hash = {}
11
+ instance_variables.each do |method|
12
+ method = method.to_s.gsub("@", "")
13
+ hash.merge!({ method.to_sym => send(method) })
14
+ end
15
+
16
+ return hash
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'rack/cache'
2
+ require 'dragonfly'
3
+
4
+ app = Dragonfly[:images]
5
+ app.configure_with(:imagemagick)
6
+ app.configure_with(:rails)
7
+
8
+ if defined? ActiveRecord::Base
9
+ app.define_macro(ActiveRecord::Base, :image_accessor)
10
+ end
11
+
12
+ if defined? Mongoid::Document
13
+ require 'mongoid'
14
+
15
+ mongo_yml_path = Rails.env.test? ? "#{File.expand_path('../../../../test/dummy/config', __FILE__)}" : "config"
16
+ db = YAML.load_file(File.join(mongo_yml_path, 'mongoid.yml'))[Rails.env]['database']
17
+ app.datastore = Dragonfly::DataStorage::MongoDataStore.new :database => db
18
+
19
+ app.define_macro_on_include(Mongoid::Document, :image_accessor)
20
+ end
@@ -0,0 +1,37 @@
1
+ module AttachmentMagick
2
+ class DSL
3
+ attr_reader :styles
4
+ attr_reader :default_options
5
+
6
+ def initialize(set, default_grids)
7
+ @set = set
8
+ @styles = {}
9
+ @default_grids = default_grids
10
+ @default_options = {:crop => true}
11
+ end
12
+
13
+ def method_missing(name, *params, &blk)
14
+ options = params.first
15
+
16
+ if options.nil?
17
+ options = @default_grids[name.to_sym]
18
+ elsif options.is_a?(String)
19
+ values = options.split('x')
20
+
21
+ options = {}
22
+ options.merge!(:width => values.first.to_i) if values.first
23
+ options.merge!(:height => values.last.to_i) if values.second
24
+
25
+ options = @default_grids[name.to_sym].merge(options)
26
+ elsif options.is_a?(Hash)
27
+ options = @default_grids[name.to_sym].merge(options)
28
+ end
29
+
30
+ @styles.merge!(name.to_sym => @default_options.merge(options))
31
+ end
32
+
33
+ def styles
34
+ @styles.empty? ? nil : @styles
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ require "attachment_magick"
2
+ require "rails"
3
+
4
+ module AttachmentMagick
5
+ class Engine < Rails::Engine
6
+ initializer 'attachment_magick.helper' do |app|
7
+ ActionView::Base.send :include, AttachmentMagickHelper
8
+ end
9
+ end
10
+ end