ruby_gallery 0.1.5 → 0.1.6

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 (35) hide show
  1. data/README.markdown +29 -1
  2. data/VERSION +1 -1
  3. data/app/.DS_Store +0 -0
  4. data/app/assets/images/border.png +0 -0
  5. data/app/assets/images/controls.png +0 -0
  6. data/app/assets/images/loading.gif +0 -0
  7. data/app/assets/images/loading_background.png +0 -0
  8. data/app/assets/images/overlay.png +0 -0
  9. data/app/assets/images/upload_processing.gif +0 -0
  10. data/app/assets/javascripts/jquery-ui.js +14987 -0
  11. data/app/assets/javascripts/jquery.colorbox.js +1037 -0
  12. data/app/assets/javascripts/ruby_gallery.js +71 -49
  13. data/app/assets/stylesheets/.DS_Store +0 -0
  14. data/app/assets/stylesheets/colorbox.css +93 -0
  15. data/app/assets/stylesheets/entypo.eot +0 -0
  16. data/app/assets/stylesheets/entypo.svg +13 -0
  17. data/app/assets/stylesheets/entypo.ttf +0 -0
  18. data/app/assets/stylesheets/entypo.woff +0 -0
  19. data/app/assets/stylesheets/ruby_gallery.css.scss +81 -60
  20. data/app/helpers/ruby_gallery/ruby_gallery_helper.rb +84 -12
  21. data/app/helpers/ruby_gallery/test_helper.rb +16 -0
  22. data/app/models/album_photo.rb +1 -2
  23. data/app/views/shared/_photo_box.html.erb +6 -0
  24. data/lib/generators/active_record/ruby_gallery_generator.rb +28 -4
  25. data/lib/generators/active_record/templates/album_photo_migration.rb +10 -5
  26. data/lib/generators/active_record/templates/migration.rb +3 -3
  27. data/lib/generators/ruby_gallery/install_generator.rb +54 -1
  28. data/lib/generators/ruby_gallery/orm_helpers.rb +44 -0
  29. data/lib/ruby_gallery.rb +6 -1
  30. data/lib/ruby_gallery/attachments_controller.rb +45 -0
  31. data/ruby_gallery.gemspec +21 -5
  32. metadata +22 -6
  33. data/app/controllers/attachments_controller.rb +0 -3
  34. data/app/models/album_attachment.rb +0 -3
  35. data/lib/generators/active_record/templates/album_attachment_migration.rb +0 -9
@@ -0,0 +1,16 @@
1
+ module RubyGallery::TestHelper
2
+ def upload_factory(model_name, fields={})
3
+ object = model_name.to_s.singularize.classify.constantize.find(params[:id])
4
+
5
+ content_tag(:div, class: "factory-box") do
6
+ content_tag(:form, action: "/upload_factories/upload_processes")
7
+ content_tag(:ul, class: "factory-content") do
8
+ content_tag(:li, class: "factory-item") do
9
+ [tag(:label, 'Upload Photo'),
10
+ tag(:input, type: 'file', multiple: "", class: "factory-input")].join.html_safe
11
+ end
12
+ end
13
+ end
14
+
15
+ end #end def
16
+ end
@@ -1,6 +1,5 @@
1
1
  class AlbumPhoto < ActiveRecord::Base
2
2
  attr_accessible :photo
3
-
4
- belongs_to :album_attachment
3
+ belongs_to :album_photoable, polymorphic: true
5
4
  has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
6
5
  end
@@ -0,0 +1,6 @@
1
+ <li class='photo-cat photo_<%=photo.id %>' key="<%= photo.id%>">
2
+ <span class="entypo-icon-1 remove-photo hide", photo_id="<%= photo.id %>">&#10006;</span>
3
+ <a class="gallery-colorbox" href="<%= photo.photo.url(:medium)%>">
4
+ <%= image_tag photo.photo.url(:thumb) ,size: '120x120' %>
5
+ <input type="hidden" name="position-item" class="item-position" value="<%= photo.position%>" />
6
+ </li>
@@ -1,17 +1,41 @@
1
1
  require 'rails/generators/active_record'
2
+ require 'generators/ruby_gallery/orm_helpers'
2
3
  module ActiveRecord
3
4
  module Generators
4
5
  class RubyGalleryGenerator < ActiveRecord::Generators::Base
6
+ include RubyGallery::Generators::OrmHelpers
5
7
  argument :attributes, :type => :array, :default => [], :banner => "filed:type field:type"
6
8
 
7
9
  source_root File.expand_path("../templates", __FILE__)
8
10
 
9
11
  def copy_ruby_gallery_migration
10
- migration_template "album_photo_migration.rb", "db/migrate/ruby_gallery_create_album_photos"
11
- migration_template "migration.rb", "db/migrate/ruby_gallery_add_columns_to_#{table_name}"
12
- migration_template "album_attachment_migration.rb", "db/migrate/ruby_gallery_create_album_attachments"
12
+ route "put '/#{table_name}/update_ruby_gallery_position', controller: :#{table_name}, action: :update_ruby_gallery_position"
13
+ route "post '/#{table_name}/upload_album', controller: :#{table_name}, action: :upload_album"
14
+ route "delete '/#{table_name}/:id/delete_photo', controller: :#{table_name}, action: :delete_photo"
15
+ if migration_exists?("album_photos") && migration_add_columns_exists?("album_photos")
16
+ # migration_template "migration.rb", "db/migrate/ruby_gallery_add_columns_to_album_photos" unless migration_add_columns_exists?("album_photos")
17
+ else
18
+ migration_template "album_photo_migration.rb", "db/migrate/ruby_gallery_create_album_photos"
19
+ migration_template "migration.rb", "db/migrate/ruby_gallery_add_columns_to_album_photos"
20
+ end
21
+ end
22
+
23
+ def inject_ruby_gallery_content_to_model
24
+ content = %Q{ has_many :album_photos, as: :photoable}
25
+ class_path = class_name.to_s.split("::")
26
+ indent_depth = class_path.size - 1
27
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
28
+ inject_into_class(model_path, class_path.last, content) if model_exists?
29
+ end
30
+
31
+ def inject_ruby_gallery_content_to_controller
32
+ content = %Q{ upload_album_for :#{table_name}}
33
+
34
+ class_path = class_name.to_s.split("::")
35
+ indent_depth = class_path.size - 1
36
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
37
+ inject_into_class(controller_path, class_path.last.tableize.camelize + "Controller", content) if controller_exists?
13
38
  end
14
-
15
39
  end
16
40
  end
17
41
  end
@@ -1,13 +1,18 @@
1
1
  class RubyGalleryCreateAlbumPhotos < ActiveRecord::Migration
2
+
3
+
2
4
  def self.up
3
- drop_table :album_photos
4
- end
5
- def change
6
5
  create_table :album_photos do |b|
7
- b.integer :album_attachment_id
6
+ b.belongs_to :photoable, polymorphic: true
7
+ b.integer :position, default: 0
8
8
  b.timestamps
9
9
  end
10
+
11
+ add_index :album_photos, [:photoable_id, :photoable_type]
12
+ end
13
+
14
+ def self.down
15
+ drop_table :album_photos
10
16
  end
11
-
12
17
 
13
18
  end
@@ -1,9 +1,9 @@
1
- class RubyGalleryAddColumnsTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class RubyGalleryAddColumnsToAlbumPhotos < ActiveRecord::Migration
2
2
  def self.up
3
- add_attachment :<%= table_name %>, :photo
3
+ add_attachment :album_photos, :photo
4
4
  end
5
5
 
6
6
  def self.down
7
- remove_attachment :<%= table_name %>, :photo
7
+ remove_attachment :album_photos , :photo
8
8
  end
9
9
  end
@@ -6,7 +6,6 @@ module RubyGallery
6
6
  module Generators
7
7
  class InstallGenerator < Rails::Generators::Base
8
8
  include Rails::Generators::Migration
9
-
10
9
  source_root File.expand_path("../../templates", __FILE__)
11
10
 
12
11
  desc "Creates a Congig file and copy locate files to your application."
@@ -15,10 +14,64 @@ module RubyGallery
15
14
 
16
15
  def copy_jsfile
17
16
  copy_file "../../../app/assets/javascripts/ruby_gallery.js", "app/assets/javascripts/ruby_gallery.js"
17
+ copy_file "../../../app/assets/javascripts/jquery-ui.js", "app/assets/javascripts/jquery-ui.js"
18
+ copy_file "../../../app/assets/javascripts/jquery.colorbox.js", "app/assets/javascripts/jquery.colorbox.js"
18
19
  end
19
20
 
20
21
  def copy_cssfile
21
22
  copy_file "../../../app/assets/stylesheets/ruby_gallery.css.scss", "app/assets/stylesheets/ruby_gallery.css.scss"
23
+ copy_file "../../../app/assets/stylesheets/colorbox.css", "app/assets/stylesheets/colorbox.css"
24
+ end
25
+
26
+ def copy_imgfile
27
+ copy_file "../../../app/assets/images/upload_processing.gif", "app/assets/images/upload_processing.gif"
28
+ copy_file "../../../app/assets/images/controls.png", "app/assets/images/controls.png"
29
+ copy_file "../../../app/assets/images/loading.gif", "app/assets/images/loading.gif"
30
+ copy_file "../../../app/assets/images/loading_background.png", "app/assets/images/loading_background.png"
31
+ copy_file "../../../app/assets/images/overlay.png", "app/assets/images/overlay.png"
32
+ copy_file "../../../app/assets/images/border.png", "app/assets/images/border.png"
33
+ end
34
+
35
+
36
+
37
+ def inject_javascript
38
+ append_to_file 'app/assets/javascripts/application.js' do
39
+ out = "\n"
40
+ out << "//= require ruby_gallery"
41
+ end
42
+
43
+ append_to_file 'app/assets/javascripts/application.js' do
44
+ out = "\n"
45
+ out << "//= require jquery.colorbox"
46
+ end
47
+
48
+ append_to_file 'app/assets/javascripts/application.js' do
49
+ out = "\n"
50
+ out << "//= require jquery-fileupload/basic"
51
+ end
52
+
53
+ append_to_file 'app/assets/javascripts/application.js' do
54
+ out = "\n"
55
+ out << "//= require jquery-ui"
56
+ end
57
+ end
58
+
59
+ def inject_css
60
+ append_to_file 'app/assets/stylesheets/application.css' do
61
+ out = "\n"
62
+ out << "/* *= require ruby_gallery */"
63
+ end
64
+
65
+ append_to_file 'app/assets/stylesheets/application.css' do
66
+ out = "\n"
67
+ out << "/* *= require colorbox */"
68
+ end
69
+
70
+ append_to_file 'app/assets/stylesheets/application.css' do
71
+ out = "\n"
72
+ out << "/* *= require jquery.fileupload-ui */"
73
+ end
74
+
22
75
  end
23
76
 
24
77
  end
@@ -0,0 +1,44 @@
1
+ module RubyGallery
2
+ module Generators
3
+ module OrmHelpers
4
+ def model_contents
5
+ <<-CONTENT
6
+ # Include default devise modules. Others available are:
7
+ # :token_authenticatable, :confirmable,
8
+ # :lockable, :timeoutable and :omniauthable
9
+ # devise :database_authenticatable, :registerable,
10
+ # :recoverable, :rememberable, :trackable, :validatable
11
+ #
12
+ CONTENT
13
+ end
14
+
15
+ def model_exists?
16
+ File.exists?(File.join(destination_root, model_path))
17
+ end
18
+
19
+ def controller_exists?
20
+ File.exists?(File.join(destination_root, controller_path))
21
+ end
22
+
23
+ def migration_exists?(table_name)
24
+ Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_ruby_gallery_create_#{table_name}.rb$/).first
25
+ end
26
+
27
+ def migration_add_columns_exists?(table_name)
28
+ Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_ruby_gallery_add_columns_to_#{table_name}.rb$/).first
29
+ end
30
+
31
+ def migration_path
32
+ @migration_path ||= File.join("db", "migrate")
33
+ end
34
+
35
+ def model_path
36
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
37
+ end
38
+
39
+ def controller_path
40
+ @controller_path ||= File.join("app", "controllers", "#{table_name}_controller.rb")
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/ruby_gallery.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'rubygems'
2
+ require 'jquery-fileupload-rails'
2
3
  require 'paperclip'
4
+ require 'bourbon'
5
+ require 'ruby_gallery/attachments_controller'
3
6
 
4
- module RubyGallery
7
+ module RubyGallery
5
8
  class Engine < Rails::Engine
9
+ ActionController::Base.send(:extend, RubyGallery::AttachmentsController)
10
+ # same as ActionController::Base.extend(RubyGallery::AttachmentsController)
6
11
  end
7
12
  end
@@ -0,0 +1,45 @@
1
+ module RubyGallery
2
+ module AttachmentsController
3
+ def upload_album_for(models)
4
+ class_name = models.to_s.singularize
5
+ class_object_name = class_name.classify # "Book"
6
+ class_object = class_object_name.constantize # Book
7
+
8
+
9
+ instance_eval do
10
+ define_method("upload_album") do
11
+ object = class_object.find(params[:id])
12
+ # 10.times {
13
+
14
+ photo = object.album_photos.build({photo: (params[:file] and params[:file].is_a?(Array)) ? params[:file][0] : params[:file]})
15
+ photo.save
16
+ # }
17
+
18
+ eval("@#{class_name} = #{class_object_name}.find(params[:id])")
19
+ render :partial => "shared/photo_box",locals: {photo: photo}
20
+ # render text: "successful"
21
+ end
22
+
23
+ define_method("delete_photo") do
24
+ object = class_object.find(params[:id])
25
+ photo = object.album_photos.find(params[:photo_id])
26
+ photo.destroy
27
+ render text: "ok"
28
+ end
29
+
30
+ define_method("update_ruby_gallery_position") do
31
+ object = class_object.find(params[:id])
32
+ json = params[:json]
33
+ json.each do |key,value|
34
+ id = value['id']
35
+ position = value['position']
36
+ photo = object.album_photos.find(id)
37
+ photo.update_attribute(:position, position)
38
+ end
39
+ render :text => "successful"
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
data/ruby_gallery.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby_gallery"
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Dang"]
12
- s.date = "2013-03-21"
12
+ s.date = "2013-03-29"
13
13
  s.description = "Upload image use gallery"
14
14
  s.email = "peter@rubify.com"
15
15
  s.extra_rdoc_files = [
@@ -24,19 +24,35 @@ Gem::Specification.new do |s|
24
24
  "README.markdown",
25
25
  "Rakefile",
26
26
  "VERSION",
27
+ "app/.DS_Store",
28
+ "app/assets/images/border.png",
29
+ "app/assets/images/controls.png",
30
+ "app/assets/images/loading.gif",
31
+ "app/assets/images/loading_background.png",
32
+ "app/assets/images/overlay.png",
33
+ "app/assets/images/upload_processing.gif",
34
+ "app/assets/javascripts/jquery-ui.js",
35
+ "app/assets/javascripts/jquery.colorbox.js",
27
36
  "app/assets/javascripts/ruby_gallery.js",
37
+ "app/assets/stylesheets/.DS_Store",
38
+ "app/assets/stylesheets/colorbox.css",
39
+ "app/assets/stylesheets/entypo.eot",
40
+ "app/assets/stylesheets/entypo.svg",
41
+ "app/assets/stylesheets/entypo.ttf",
42
+ "app/assets/stylesheets/entypo.woff",
28
43
  "app/assets/stylesheets/ruby_gallery.css.scss",
29
- "app/controllers/attachments_controller.rb",
30
44
  "app/helpers/ruby_gallery/ruby_gallery_helper.rb",
31
- "app/models/album_attachment.rb",
45
+ "app/helpers/ruby_gallery/test_helper.rb",
32
46
  "app/models/album_photo.rb",
47
+ "app/views/shared/_photo_box.html.erb",
33
48
  "lib/generators/active_record/ruby_gallery_generator.rb",
34
- "lib/generators/active_record/templates/album_attachment_migration.rb",
35
49
  "lib/generators/active_record/templates/album_photo_migration.rb",
36
50
  "lib/generators/active_record/templates/migration.rb",
37
51
  "lib/generators/ruby_gallery/install_generator.rb",
52
+ "lib/generators/ruby_gallery/orm_helpers.rb",
38
53
  "lib/generators/ruby_gallery/ruby_gallery_generator.rb",
39
54
  "lib/ruby_gallery.rb",
55
+ "lib/ruby_gallery/attachments_controller.rb",
40
56
  "ruby_gallery.gemspec",
41
57
  "test/helper.rb",
42
58
  "test/test_ruby_gallery.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_gallery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bourbon
@@ -154,19 +154,35 @@ files:
154
154
  - README.markdown
155
155
  - Rakefile
156
156
  - VERSION
157
+ - app/.DS_Store
158
+ - app/assets/images/border.png
159
+ - app/assets/images/controls.png
160
+ - app/assets/images/loading.gif
161
+ - app/assets/images/loading_background.png
162
+ - app/assets/images/overlay.png
163
+ - app/assets/images/upload_processing.gif
164
+ - app/assets/javascripts/jquery-ui.js
165
+ - app/assets/javascripts/jquery.colorbox.js
157
166
  - app/assets/javascripts/ruby_gallery.js
167
+ - app/assets/stylesheets/.DS_Store
168
+ - app/assets/stylesheets/colorbox.css
169
+ - app/assets/stylesheets/entypo.eot
170
+ - app/assets/stylesheets/entypo.svg
171
+ - app/assets/stylesheets/entypo.ttf
172
+ - app/assets/stylesheets/entypo.woff
158
173
  - app/assets/stylesheets/ruby_gallery.css.scss
159
- - app/controllers/attachments_controller.rb
160
174
  - app/helpers/ruby_gallery/ruby_gallery_helper.rb
161
- - app/models/album_attachment.rb
175
+ - app/helpers/ruby_gallery/test_helper.rb
162
176
  - app/models/album_photo.rb
177
+ - app/views/shared/_photo_box.html.erb
163
178
  - lib/generators/active_record/ruby_gallery_generator.rb
164
- - lib/generators/active_record/templates/album_attachment_migration.rb
165
179
  - lib/generators/active_record/templates/album_photo_migration.rb
166
180
  - lib/generators/active_record/templates/migration.rb
167
181
  - lib/generators/ruby_gallery/install_generator.rb
182
+ - lib/generators/ruby_gallery/orm_helpers.rb
168
183
  - lib/generators/ruby_gallery/ruby_gallery_generator.rb
169
184
  - lib/ruby_gallery.rb
185
+ - lib/ruby_gallery/attachments_controller.rb
170
186
  - ruby_gallery.gemspec
171
187
  - test/helper.rb
172
188
  - test/test_ruby_gallery.rb
@@ -185,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
201
  version: '0'
186
202
  segments:
187
203
  - 0
188
- hash: 707823898086047540
204
+ hash: 392206747184538881
189
205
  required_rubygems_version: !ruby/object:Gem::Requirement
190
206
  none: false
191
207
  requirements:
@@ -1,3 +0,0 @@
1
- class AttachmentsController < ApplicationController
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class AlbumAttachment < ActiveRecord::Base
2
- has_many :album_photos, dependent: :destroy
3
- end
@@ -1,9 +0,0 @@
1
- class RubyGalleryCreateAlbumAttachments < ActiveRecord::Migration
2
- def change
3
- create_table :album_attachments do |a|
4
- a.string :parent_type
5
- a.integer :parent_id
6
- a.timestamps
7
- end
8
- end
9
- end