polygallery 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/polygallery/acts_as_polyphoto.rb +48 -0
- data/app/models/polygallery/gallery.rb +1 -20
- data/app/models/polygallery/photo.rb +1 -24
- data/app/views/polygallery/galleries/_simple_fields_for.html.haml +3 -3
- data/lib/polygallery/has_polygallery.rb +7 -11
- data/lib/polygallery/has_polyphotos.rb +52 -9
- data/lib/polygallery/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/stylesheets/application.css +1 -0
- data/test/dummy/app/controllers/events_controller.rb +3 -2
- data/test/dummy/app/models/custom_gallery.rb +13 -6
- data/test/dummy/app/models/event.rb +5 -4
- data/test/dummy/app/views/layouts/application.html.haml +7 -2
- data/test/dummy/config/application.rb +2 -1
- data/test/dummy/config/initializers/simple_form_fileinput.rb +9 -7
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/migrate/20150320165705_create_polygalleries.rb +22 -0
- data/test/dummy/db/schema.rb +3 -3
- data/test/dummy/log/development.log +6400 -0
- data/test/dummy/log/test.log +8949 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/002/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/002/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/002/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/003/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/003/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/003/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/004/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/004/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/004/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/spec/factories/events.rb +7 -0
- data/test/dummy/spec/factories/polygallery/photos.rb +7 -0
- data/test/dummy/spec/features/events_spec.rb +60 -0
- data/test/dummy/spec/rails_helper.rb +50 -0
- data/test/dummy/spec/spec_helper.rb +138 -0
- data/test/dummy/spec/upload_files/logo_placeholder_medium.png +0 -0
- data/test/dummy/tmp/cache/assets/development/sass/d58d4fb9eedfbbaea362e7eed4f4b120ecc36459/enhancements.css.scssc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/138f3adae029720184284e5af56ba6ee +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/165fa1b3eb4e30266c9cd78ba25a6879 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1b48b24452c10fa45f34ec79aa2ca587 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1c9faaf28d05409b88ad3113374d613c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1d61d3cd6f59fc3758908d3ea27aaf0b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1e1c73f8892119a4dbc6ead7718b4472 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/20537eac47b88a0b70cf0fec72c5c957 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/23a02f793bdc3b6a6cbd015f184c6f6c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/24670b1af8e69df61aafc78f7817bcee +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2757fae967a52701ef3724ae5a76c4a8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2822de3b22c28bd5e718c9bf500457b2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/29e4552fca58a1885579b3932b6a9603 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2b731b63fb1d665043d920a05b591cdc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/30e3552cad42917377b8675173b87d6d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3285c3b5fd63e6e64ad469b8d96aae8f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/366b734bd9d2050f91efe4fa45bd1f60 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3f657ddfc843294ed3fc8242f82e7a97 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/40fc2f3d2a468a00e463f1d313cb1683 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4838bd0bcba2e22c3c7aef8feb88db17 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/49e036553e32b5ecddd9e7de7a25ccea +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4a98a84c5ce12f2b9646335623b4e224 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4daff1d5b8e6da6d2ed55886db193ef2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4ea33e825e6e38bd22dccab488a0255b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5ef83a7011cee8efacb9afc7173fe765 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/65dccf676de4439612547abc6451ba65 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/69bda14eaa1d8ad1ea1235abb619e366 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7b45798a1475deb0d6739c888f060c96 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7be9086c960bb4384c9d23a52e489f29 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7c5867dbaa2d85cd5508dc339972e314 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/86f909bf5baee50515afadaa3ce2df8f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8c81470cda06da3ee9ec2181fe7743b0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8e3f978ef00686e7a7cad1a57185f90a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8e5a9738e9bc15478e026d98335454f9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8f29e45e02d0321a6250df9b5ca050fe +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8f8936f164170e095c5ca2d0c2ae6127 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9b9c0e78635195bcb386a8b6e9ee1e97 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a49b0e8a393070d4a440d78743af3460 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a995a3b95e4a7b0e5b9fa7c49efd6b74 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a9f028f7a492b5907ed80268be8f50f4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/abfcce22636ec4371a92e6ceb1077a54 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b2e3c54b17f3d7fc54aab42082c470f8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b878faf942403e313a5b103e5d80488e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b9b29a56a8585a110f306871e8938d2b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ba56eb60d599a0ca3d2f6b67772774c2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c502e11bd52b854e6af9627c3da0616a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cebfc296bf824dfc0f567874a00522d4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cf29797a4195344bac977b8ebfca7fff +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e33b68bc0cecc21d45c44c8d2fd46c76 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e4b5a49edafa42a1ffe8f10535156b1b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/edbef6e0d0a4742346cf479f2c522eb0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f1ea202e87b3ffc6964c9b0358531976 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f209bca5b11567d04157eefee66c6a48 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f5d86e31abec9b44e777e3f639187d5a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f644fd75cbead0e58c847aa16546e2a8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f844ec54464006be394ce9de15eb0814 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f950876669f7719a544d0de445843b08 +0 -0
- data/test/dummy/tmp/cache/assets/test/sass/d58d4fb9eedfbbaea362e7eed4f4b120ecc36459/enhancements.css.scssc +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/138f3adae029720184284e5af56ba6ee +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/165fa1b3eb4e30266c9cd78ba25a6879 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/1b48b24452c10fa45f34ec79aa2ca587 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/1c9faaf28d05409b88ad3113374d613c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/1e1c73f8892119a4dbc6ead7718b4472 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/20537eac47b88a0b70cf0fec72c5c957 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/23a02f793bdc3b6a6cbd015f184c6f6c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2757fae967a52701ef3724ae5a76c4a8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/29e4552fca58a1885579b3932b6a9603 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2b731b63fb1d665043d920a05b591cdc +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3f657ddfc843294ed3fc8242f82e7a97 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/40fc2f3d2a468a00e463f1d313cb1683 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4838bd0bcba2e22c3c7aef8feb88db17 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4a98a84c5ce12f2b9646335623b4e224 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4ea33e825e6e38bd22dccab488a0255b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/65dccf676de4439612547abc6451ba65 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/69bda14eaa1d8ad1ea1235abb619e366 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7b45798a1475deb0d6739c888f060c96 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7be9086c960bb4384c9d23a52e489f29 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/86f909bf5baee50515afadaa3ce2df8f +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8c81470cda06da3ee9ec2181fe7743b0 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8e3f978ef00686e7a7cad1a57185f90a +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8e5a9738e9bc15478e026d98335454f9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8f29e45e02d0321a6250df9b5ca050fe +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9b9c0e78635195bcb386a8b6e9ee1e97 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a49b0e8a393070d4a440d78743af3460 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/abfcce22636ec4371a92e6ceb1077a54 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b878faf942403e313a5b103e5d80488e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b9b29a56a8585a110f306871e8938d2b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cebfc296bf824dfc0f567874a00522d4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e33b68bc0cecc21d45c44c8d2fd46c76 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e4b5a49edafa42a1ffe8f10535156b1b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/edbef6e0d0a4742346cf479f2c522eb0 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f1ea202e87b3ffc6964c9b0358531976 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f209bca5b11567d04157eefee66c6a48 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f5d86e31abec9b44e777e3f639187d5a +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f644fd75cbead0e58c847aa16546e2a8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f950876669f7719a544d0de445843b08 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- metadata +299 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9f9f989f87f7a55dd5a9174add48b1947727ae
|
4
|
+
data.tar.gz: 52d22be3a15e569dc030f43b7bb31cc59b07f094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bda03dccc7bbc3cc2e53b1db97e539e6b886886299bb1472b79e85ebe8469b57b5f7007c5a0cd6e98414da14f4e0ca9a13aa74dda482ee7572bbf725695bcbe
|
7
|
+
data.tar.gz: 780269277ba55672bb7602c42dfa0d83e8f68f543f98aee61e68c152f2c24055053d437d89b871a55a1041120d74ae8c2840a472c4e6712fdc88bb2ed91566e1
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Polygallery
|
2
|
+
module ActsAsPolyphoto
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
DEFAULTS = {
|
6
|
+
:paperclip => {
|
7
|
+
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
8
|
+
:default_url => '/images/:style/missing.png'
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
included do
|
13
|
+
attr_accessor :photo_to_upload,
|
14
|
+
:galleryable_id, :galleryable_type, :gallery_title
|
15
|
+
|
16
|
+
# has_attached_file :photo,
|
17
|
+
# :styles => PAPERCLIP_SETTINGS[:styles], # ->(a) { if a.instance.class.name then raise a.instance.class.name else PAPERCLIP_SETTINGS[:styles] end },
|
18
|
+
# :default_url => PAPERCLIP_SETTINGS[:default_url]
|
19
|
+
# validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
|
20
|
+
# validates_attachment_presence :photo # TODO: make this a setting
|
21
|
+
|
22
|
+
belongs_to :gallery, :class_name => 'Polygallery::Gallery'
|
23
|
+
|
24
|
+
after_initialize :init_attachment
|
25
|
+
before_save :process_photo_to_upload
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
end
|
30
|
+
|
31
|
+
def paperclip_settings
|
32
|
+
return self.gallery.polygallery_settings[:paperclip] if self.gallery.present?
|
33
|
+
DEFAULTS[:paperclip]
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_photo_to_upload
|
37
|
+
self.photo = File.open(photo_to_upload) if photo_to_upload.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_attachment
|
41
|
+
self.class.has_attached_file :photo,
|
42
|
+
:styles => paperclip_settings[:styles],
|
43
|
+
:default_url => paperclip_settings[:default_url]
|
44
|
+
self.class.validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
|
45
|
+
# self.class.validates_attachment_presence :photo # TODO: make this a setting
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,27 +1,8 @@
|
|
1
1
|
module Polygallery
|
2
2
|
class Gallery < ActiveRecord::Base
|
3
|
-
DEFAULTS = {
|
4
|
-
:associations => {
|
5
|
-
:gallery => {
|
6
|
-
:class_name => 'Polygallery::Gallery',
|
7
|
-
:as => :galleryable,
|
8
|
-
:dependent => :destroy
|
9
|
-
},
|
10
|
-
:photos => {
|
11
|
-
:class_name => 'Polygallery::Photo',
|
12
|
-
:before_add => :set_nest,
|
13
|
-
:dependent => :destroy
|
14
|
-
}
|
15
|
-
},
|
16
|
-
:nested_attributes => {
|
17
|
-
:gallery => {:reject_if => :all_blank},
|
18
|
-
:photos => {:reject_if => lambda{|attributes| attributes['photo'].nil? }, :allow_destroy => true}
|
19
|
-
},
|
20
|
-
:validates => {}
|
21
|
-
}
|
22
3
|
|
23
4
|
belongs_to :galleryable, :polymorphic => true
|
24
|
-
has_polyphotos
|
5
|
+
has_polyphotos
|
25
6
|
|
26
7
|
def settings
|
27
8
|
if galleryable.present?
|
@@ -1,28 +1,5 @@
|
|
1
1
|
module Polygallery
|
2
2
|
class Photo < ActiveRecord::Base
|
3
|
-
|
4
|
-
PAPERCLIP_SETTINGS = {
|
5
|
-
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
6
|
-
:default_url => '/images/:style/missing.png'
|
7
|
-
}
|
8
|
-
has_attached_file :photo,
|
9
|
-
:styles => PAPERCLIP_SETTINGS[:styles], # ->(a) { if a.instance.class.name then raise a.instance.class.name else PAPERCLIP_SETTINGS[:styles] end },
|
10
|
-
:default_url => PAPERCLIP_SETTINGS[:default_url]
|
11
|
-
validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
|
12
|
-
# validates_attachment_presence :photo # TODO: make this a setting
|
13
|
-
|
14
|
-
belongs_to :gallery, :class_name => 'Polygallery::Gallery'
|
15
|
-
|
16
|
-
attr_accessor :photo_to_upload, :galleryable_id, :galleryable_type, :gallery_title
|
17
|
-
before_save :process_photo_to_upload
|
18
|
-
|
19
|
-
def paperclip_settings
|
20
|
-
PAPERCLIP_SETTINGS
|
21
|
-
end
|
22
|
-
|
23
|
-
def process_photo_to_upload
|
24
|
-
self.photo = File.open(photo_to_upload) if photo_to_upload.present?
|
25
|
-
end
|
26
|
-
|
3
|
+
include ActsAsPolyphoto
|
27
4
|
end
|
28
5
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
- if options[:label]
|
5
5
|
%h3.lead
|
6
|
-
= link_to_add_association 'Add Photo', ff, :photos, :partial => 'polygallery/photos/simple_fields_for', :class => 'btn btn-default btn-sm pull-right', :data => {:association_insertion_node => '.photo-receptacle', :association_insertion_method => 'append'}
|
6
|
+
= link_to_add_association 'Add Photo', ff, gallery.class.polygallery_settings[:association_names][:photos], :partial => 'polygallery/photos/simple_fields_for', :class => 'btn btn-default btn-sm pull-right', :data => {:association_insertion_node => '.photo-receptacle', :association_insertion_method => 'append'}
|
7
7
|
- if options[:label] == true
|
8
8
|
= gallery.title.titleize
|
9
9
|
- else
|
10
10
|
= options[:label].titleize
|
11
|
-
|
11
|
+
.polygallery-cocoon-table{:id => gallery.class.polygallery_settings[:association_names][:photos].to_s}
|
12
12
|
%table.table.table-bordered.table-striped.table-condensed.polygallery-photos-table
|
13
13
|
%thead
|
14
14
|
%tr
|
@@ -22,4 +22,4 @@
|
|
22
22
|
-#- if !options[:label]
|
23
23
|
-# = ff.input_field :content, options[:input_html].merge({:as => :ckeditor})
|
24
24
|
-#- else
|
25
|
-
-#= ff.input :content, :as => :ckeditor, :label => options[:label].is_a?(String) ? options[:label] : name.to_s.titleize, :input_html => name.is_a?(String) ? options[:input_html].merge({:value => pb.content}) : options[:input_html]
|
25
|
+
-#= ff.input :content, :as => :ckeditor, :label => options[:label].is_a?(String) ? options[:label] : name.to_s.titleize, :input_html => name.is_a?(String) ? options[:input_html].merge({:value => pb.content}) : options[:input_html]
|
@@ -13,8 +13,11 @@ module Polygallery
|
|
13
13
|
title = 'gallery'
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
associations = options[:associations]
|
17
|
+
gallery_association = options[:associations][:gallery] if associations.present?
|
18
|
+
gallery_class_name = gallery_association[:class_name] if gallery_association.present?
|
19
|
+
defaults = if gallery_class_name.present? && gallery_class_name != 'Polygallery::Gallery'
|
20
|
+
Kernel.const_get(gallery_class_name)::DEFAULTS
|
18
21
|
else
|
19
22
|
Gallery::DEFAULTS
|
20
23
|
end
|
@@ -26,16 +29,9 @@ module Polygallery
|
|
26
29
|
accepts_nested_attributes_for title.to_sym, settings[:nested_attributes][:gallery]
|
27
30
|
has_many "#{title}_photos".to_sym,
|
28
31
|
:through => title.to_sym,
|
29
|
-
:source => :photos,
|
32
|
+
:source => settings[:association_names][:photos],
|
30
33
|
:class_name => settings[:associations][:photos][:class_name]
|
31
34
|
|
32
|
-
# if settings[:paperclip] != defaults[:paperclip]
|
33
|
-
# after_create do
|
34
|
-
# raise 'CREATE BOOM'
|
35
|
-
# send(title.to_sym).photos.each{|p| p.photo.reprocess! }
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
|
39
35
|
after_initialize do
|
40
36
|
send("build_#{title.to_s}".to_sym) if send(title.to_sym).nil?
|
41
37
|
send(title.to_sym).send(:galleryable=, self)
|
@@ -68,4 +64,4 @@ module Polygallery
|
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
71
|
-
ActiveRecord::Base.send :include, Polygallery::HasPolygallery
|
67
|
+
ActiveRecord::Base.send :include, Polygallery::HasPolygallery
|
@@ -1,12 +1,40 @@
|
|
1
1
|
module Polygallery
|
2
2
|
module HasPolyphotos
|
3
3
|
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
DEFAULTS = {
|
6
|
+
:associations => {
|
7
|
+
:gallery => {
|
8
|
+
:class_name => 'Polygallery::Gallery',
|
9
|
+
:as => :galleryable,
|
10
|
+
:dependent => :destroy
|
11
|
+
},
|
12
|
+
:photos => {
|
13
|
+
:class_name => 'Polygallery::Photo',
|
14
|
+
:before_add => :set_nest,
|
15
|
+
:dependent => :destroy
|
16
|
+
}
|
17
|
+
},
|
18
|
+
:association_names => {
|
19
|
+
:gallery => :gallery,
|
20
|
+
:photos => :photos
|
21
|
+
},
|
22
|
+
:nested_attributes => {
|
23
|
+
:gallery => {:reject_if => :all_blank},
|
24
|
+
:photos => {:reject_if => lambda{|attributes| attributes['photo'].nil? }, :allow_destroy => true}
|
25
|
+
},
|
26
|
+
:validates => {},
|
27
|
+
:paperclip => {
|
28
|
+
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
29
|
+
:default_url => ActionController::Base.helpers.asset_path('polygallery/thumbnail-missing.png')
|
30
|
+
}
|
31
|
+
}
|
4
32
|
|
5
33
|
included do
|
6
|
-
def defaults
|
7
|
-
|
8
|
-
|
9
|
-
end
|
34
|
+
# def defaults
|
35
|
+
# klass = self.class_name.present? ? Kernel.const_get(self.class_name) : Gallery
|
36
|
+
# klass::DEFAULTS
|
37
|
+
# end
|
10
38
|
end
|
11
39
|
|
12
40
|
module ClassMethods
|
@@ -16,22 +44,31 @@ module Polygallery
|
|
16
44
|
title = 'photos'
|
17
45
|
end
|
18
46
|
|
19
|
-
#
|
20
|
-
settings = options
|
47
|
+
# puts reflect_on_all_associations(:belongs_to).map{|a| a.table_name }
|
48
|
+
settings = HasPolyphotos::DEFAULTS.deep_merge(options)
|
49
|
+
cattr_accessor :polygallery_settings
|
50
|
+
send(:polygallery_settings=, settings)
|
51
|
+
puts HasPolyphotos::DEFAULTS
|
21
52
|
has_many title.to_sym, settings[:associations][:photos]
|
22
|
-
accepts_nested_attributes_for title.to_sym, settings[:nested_attributes][:photos] # TODO: get the actual settings somehow
|
53
|
+
accepts_nested_attributes_for title.to_sym, settings[:nested_attributes][:photos] # TODO: get the actual @settings somehow
|
23
54
|
after_initialize do
|
24
55
|
# raise galleryable_type if galleryable_type.present?
|
25
56
|
send(title.to_sym).build(
|
26
57
|
:galleryable_id => galleryable_id,
|
27
58
|
:galleryable_type => galleryable_type,
|
28
|
-
:
|
59
|
+
:"#{settings[:association_names][:gallery]}_title" => self.title
|
29
60
|
) unless send(title.to_sym).any?
|
30
61
|
end
|
62
|
+
after_initialize :do_something
|
31
63
|
include HasPolyphotos::LocalInstanceMethods
|
32
64
|
end
|
65
|
+
|
66
|
+
# def polygallery_settings
|
67
|
+
# @settings
|
68
|
+
# end
|
33
69
|
end
|
34
70
|
|
71
|
+
|
35
72
|
module LocalInstanceMethods
|
36
73
|
def set_nest(photo)
|
37
74
|
photo.gallery ||= self
|
@@ -39,8 +76,14 @@ module Polygallery
|
|
39
76
|
photo.galleryable_type ||= galleryable_type
|
40
77
|
photo.gallery_title ||= title
|
41
78
|
end
|
79
|
+
|
80
|
+
def do_something
|
81
|
+
@polygallery_settings = Kernel.const_get(self.galleryable_type)
|
82
|
+
.send :"#{self.title}_settings"
|
83
|
+
end
|
84
|
+
|
42
85
|
end
|
43
86
|
end
|
44
87
|
end
|
45
88
|
|
46
|
-
ActiveRecord::Base.send :include, Polygallery::HasPolyphotos
|
89
|
+
ActiveRecord::Base.send :include, Polygallery::HasPolyphotos
|
data/lib/polygallery/version.rb
CHANGED
@@ -13,7 +13,8 @@ class EventsController < ApplicationController
|
|
13
13
|
else
|
14
14
|
flash[:error] = 'Your event could not be saved!'
|
15
15
|
end
|
16
|
-
redirect_to event_path(@event)
|
16
|
+
# redirect_to event_path(@event)
|
17
|
+
redirect_to root_path
|
17
18
|
end
|
18
19
|
|
19
20
|
def index
|
@@ -46,7 +47,7 @@ class EventsController < ApplicationController
|
|
46
47
|
|
47
48
|
private
|
48
49
|
def event_params
|
49
|
-
params.require(:event).permit(:title, :gallery_attributes => polygallery_params, :custom_gallery_attributes =>
|
50
|
+
params.require(:event).permit(:title, :gallery_attributes => polygallery_params, :custom_gallery_attributes => [:id, :title, :_destroy, {:photos_attributes => [:id, :photo, :title, :caption, :_destroy]}])
|
50
51
|
end
|
51
52
|
def fetch_event
|
52
53
|
@event = Event.find(params[:id])
|
@@ -1,8 +1,7 @@
|
|
1
1
|
class CustomGallery < Polygallery::Gallery
|
2
|
-
include Polygallery::CustomizedGallery
|
2
|
+
# include Polygallery::CustomizedGallery
|
3
3
|
|
4
|
-
|
5
|
-
:associations => {
|
4
|
+
has_polyphotos :associations => {
|
6
5
|
:gallery => {
|
7
6
|
:class_name => 'CustomGallery',
|
8
7
|
:as => :galleryable,
|
@@ -14,11 +13,19 @@ class CustomGallery < Polygallery::Gallery
|
|
14
13
|
:dependent => :destroy
|
15
14
|
}
|
16
15
|
},
|
16
|
+
:association_names => {
|
17
|
+
:gallery => :custom_gallery,
|
18
|
+
:photos => :custom_photos
|
19
|
+
},
|
17
20
|
:nested_attributes => {
|
18
21
|
:gallery => {:reject_if => :all_blank},
|
19
22
|
:photos => {:reject_if => lambda{|attributes| attributes['photo'].nil? }, :allow_destroy => true}
|
20
23
|
},
|
21
|
-
:validates => {}
|
22
|
-
|
24
|
+
:validates => {},
|
25
|
+
:paperclip => {
|
26
|
+
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
27
|
+
:default_url => '/images/:style/missing.png'
|
28
|
+
}
|
29
|
+
|
23
30
|
|
24
|
-
end
|
31
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Event < ActiveRecord::Base
|
2
2
|
|
3
3
|
has_polygallery
|
4
|
-
has_polygallery :custom_gallery, :
|
5
|
-
|
6
|
-
|
7
|
-
}
|
4
|
+
has_polygallery :custom_gallery, :paperclip => {:styles => ['500x500#']}
|
5
|
+
# :associations => {
|
6
|
+
# :gallery => { :class_name => '::CustomGallery' },
|
7
|
+
# :photos => { :class_name => '::CustomPhoto' }
|
8
|
+
# }
|
8
9
|
|
9
10
|
end
|
@@ -17,5 +17,10 @@
|
|
17
17
|
|
18
18
|
= csrf_meta_tags
|
19
19
|
%body
|
20
|
-
.container-fluid
|
21
|
-
|
20
|
+
.container-fluid
|
21
|
+
- flash.each do |name, msg|
|
22
|
+
= content_tag :div, :class => "alert alert-#{name == :error ? "danger" : "success" } alert-dismissable" do
|
23
|
+
%button.close{:type => "button", :data => {:dismiss => "alert"}, :aria => {:hidden => "true"} } ×
|
24
|
+
= msg
|
25
|
+
= yield
|
26
|
+
= javascript_include_tag 'application'
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module SimpleForm
|
2
2
|
module Inputs
|
3
3
|
class FileInput < Base
|
4
|
-
def input
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def input(wrapper_options)
|
5
|
+
merged_input_options = merge_wrapper_options input_html_options, wrapper_options
|
6
|
+
merged_input_options[:data] ||= {}
|
7
|
+
if Rails.env.test?
|
8
|
+
merged_input_options[:data][:bfi_disabled] = true
|
8
9
|
else
|
9
|
-
|
10
|
+
merged_input_options[:title] = 'Drop a file here, or click to browse...'
|
11
|
+
merged_input_options[:data][:filename_placement] = 'inside'
|
10
12
|
end
|
11
|
-
@builder.file_field(attribute_name,
|
13
|
+
@builder.file_field(attribute_name, merged_input_options)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreatePolygalleries < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :polygallery_galleries do |t|
|
4
|
+
t.string :title, :default => 'gallery'
|
5
|
+
t.integer :default_photo_id
|
6
|
+
t.integer :galleryable_id
|
7
|
+
t.string :galleryable_type
|
8
|
+
t.string :class_name
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
create_table :polygallery_photos do |t|
|
13
|
+
t.integer :gallery_id
|
14
|
+
t.attachment :photo
|
15
|
+
t.string :title
|
16
|
+
t.text :caption
|
17
|
+
t.string :class_name
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20150320165705) do
|
15
15
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|
@@ -27,9 +27,9 @@ ActiveRecord::Schema.define(version: 20141001192141) do
|
|
27
27
|
t.integer "default_photo_id"
|
28
28
|
t.integer "galleryable_id"
|
29
29
|
t.string "galleryable_type"
|
30
|
+
t.string "class_name"
|
30
31
|
t.datetime "created_at"
|
31
32
|
t.datetime "updated_at"
|
32
|
-
t.string "class_name"
|
33
33
|
end
|
34
34
|
|
35
35
|
create_table "polygallery_photos", force: true do |t|
|
@@ -40,9 +40,9 @@ ActiveRecord::Schema.define(version: 20141001192141) do
|
|
40
40
|
t.datetime "photo_updated_at"
|
41
41
|
t.string "title"
|
42
42
|
t.text "caption"
|
43
|
+
t.string "class_name"
|
43
44
|
t.datetime "created_at"
|
44
45
|
t.datetime "updated_at"
|
45
|
-
t.string "class_name"
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|