polygallery 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/polygallery/acts_as_polyphoto.rb +48 -0
  3. data/app/models/polygallery/gallery.rb +1 -20
  4. data/app/models/polygallery/photo.rb +1 -24
  5. data/app/views/polygallery/galleries/_simple_fields_for.html.haml +3 -3
  6. data/lib/polygallery/has_polygallery.rb +7 -11
  7. data/lib/polygallery/has_polyphotos.rb +52 -9
  8. data/lib/polygallery/version.rb +1 -1
  9. data/test/dummy/app/assets/javascripts/application.js +1 -0
  10. data/test/dummy/app/assets/stylesheets/application.css +1 -0
  11. data/test/dummy/app/controllers/events_controller.rb +3 -2
  12. data/test/dummy/app/models/custom_gallery.rb +13 -6
  13. data/test/dummy/app/models/event.rb +5 -4
  14. data/test/dummy/app/views/layouts/application.html.haml +7 -2
  15. data/test/dummy/config/application.rb +2 -1
  16. data/test/dummy/config/initializers/simple_form_fileinput.rb +9 -7
  17. data/test/dummy/config/routes.rb +1 -0
  18. data/test/dummy/db/migrate/20150320165705_create_polygalleries.rb +22 -0
  19. data/test/dummy/db/schema.rb +3 -3
  20. data/test/dummy/log/development.log +6400 -0
  21. data/test/dummy/log/test.log +8949 -0
  22. data/test/dummy/public/system/polygallery/photos/photos/000/000/002/medium/logo_placeholder_medium.png +0 -0
  23. data/test/dummy/public/system/polygallery/photos/photos/000/000/002/original/logo_placeholder_medium.png +0 -0
  24. data/test/dummy/public/system/polygallery/photos/photos/000/000/002/thumb/logo_placeholder_medium.png +0 -0
  25. data/test/dummy/public/system/polygallery/photos/photos/000/000/003/medium/logo_placeholder_medium.png +0 -0
  26. data/test/dummy/public/system/polygallery/photos/photos/000/000/003/original/logo_placeholder_medium.png +0 -0
  27. data/test/dummy/public/system/polygallery/photos/photos/000/000/003/thumb/logo_placeholder_medium.png +0 -0
  28. data/test/dummy/public/system/polygallery/photos/photos/000/000/004/medium/logo_placeholder_medium.png +0 -0
  29. data/test/dummy/public/system/polygallery/photos/photos/000/000/004/original/logo_placeholder_medium.png +0 -0
  30. data/test/dummy/public/system/polygallery/photos/photos/000/000/004/thumb/logo_placeholder_medium.png +0 -0
  31. data/test/dummy/spec/factories/events.rb +7 -0
  32. data/test/dummy/spec/factories/polygallery/photos.rb +7 -0
  33. data/test/dummy/spec/features/events_spec.rb +60 -0
  34. data/test/dummy/spec/rails_helper.rb +50 -0
  35. data/test/dummy/spec/spec_helper.rb +138 -0
  36. data/test/dummy/spec/upload_files/logo_placeholder_medium.png +0 -0
  37. data/test/dummy/tmp/cache/assets/development/sass/d58d4fb9eedfbbaea362e7eed4f4b120ecc36459/enhancements.css.scssc +0 -0
  38. data/test/dummy/tmp/cache/assets/development/sprockets/138f3adae029720184284e5af56ba6ee +0 -0
  39. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  40. data/test/dummy/tmp/cache/assets/development/sprockets/165fa1b3eb4e30266c9cd78ba25a6879 +0 -0
  41. data/test/dummy/tmp/cache/assets/development/sprockets/1b48b24452c10fa45f34ec79aa2ca587 +0 -0
  42. data/test/dummy/tmp/cache/assets/development/sprockets/1c9faaf28d05409b88ad3113374d613c +0 -0
  43. data/test/dummy/tmp/cache/assets/development/sprockets/1d61d3cd6f59fc3758908d3ea27aaf0b +0 -0
  44. data/test/dummy/tmp/cache/assets/development/sprockets/1e1c73f8892119a4dbc6ead7718b4472 +0 -0
  45. data/test/dummy/tmp/cache/assets/development/sprockets/20537eac47b88a0b70cf0fec72c5c957 +0 -0
  46. data/test/dummy/tmp/cache/assets/development/sprockets/23a02f793bdc3b6a6cbd015f184c6f6c +0 -0
  47. data/test/dummy/tmp/cache/assets/development/sprockets/24670b1af8e69df61aafc78f7817bcee +0 -0
  48. data/test/dummy/tmp/cache/assets/development/sprockets/2757fae967a52701ef3724ae5a76c4a8 +0 -0
  49. data/test/dummy/tmp/cache/assets/development/sprockets/2822de3b22c28bd5e718c9bf500457b2 +0 -0
  50. data/test/dummy/tmp/cache/assets/development/sprockets/29e4552fca58a1885579b3932b6a9603 +0 -0
  51. data/test/dummy/tmp/cache/assets/development/sprockets/2b731b63fb1d665043d920a05b591cdc +0 -0
  52. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  53. data/test/dummy/tmp/cache/assets/development/sprockets/30e3552cad42917377b8675173b87d6d +0 -0
  54. data/test/dummy/tmp/cache/assets/development/sprockets/3285c3b5fd63e6e64ad469b8d96aae8f +0 -0
  55. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  56. data/test/dummy/tmp/cache/assets/development/sprockets/366b734bd9d2050f91efe4fa45bd1f60 +0 -0
  57. data/test/dummy/tmp/cache/assets/development/sprockets/3f657ddfc843294ed3fc8242f82e7a97 +0 -0
  58. data/test/dummy/tmp/cache/assets/development/sprockets/40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  59. data/test/dummy/tmp/cache/assets/development/sprockets/4838bd0bcba2e22c3c7aef8feb88db17 +0 -0
  60. data/test/dummy/tmp/cache/assets/development/sprockets/49e036553e32b5ecddd9e7de7a25ccea +0 -0
  61. data/test/dummy/tmp/cache/assets/development/sprockets/4a98a84c5ce12f2b9646335623b4e224 +0 -0
  62. data/test/dummy/tmp/cache/assets/development/sprockets/4daff1d5b8e6da6d2ed55886db193ef2 +0 -0
  63. data/test/dummy/tmp/cache/assets/development/sprockets/4ea33e825e6e38bd22dccab488a0255b +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/5ef83a7011cee8efacb9afc7173fe765 +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/65dccf676de4439612547abc6451ba65 +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/69bda14eaa1d8ad1ea1235abb619e366 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/7b45798a1475deb0d6739c888f060c96 +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/7be9086c960bb4384c9d23a52e489f29 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/7c5867dbaa2d85cd5508dc339972e314 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/86f909bf5baee50515afadaa3ce2df8f +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/8c81470cda06da3ee9ec2181fe7743b0 +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/8e3f978ef00686e7a7cad1a57185f90a +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/8e5a9738e9bc15478e026d98335454f9 +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/8f29e45e02d0321a6250df9b5ca050fe +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/8f8936f164170e095c5ca2d0c2ae6127 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/9b9c0e78635195bcb386a8b6e9ee1e97 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/a49b0e8a393070d4a440d78743af3460 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/a995a3b95e4a7b0e5b9fa7c49efd6b74 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/a9f028f7a492b5907ed80268be8f50f4 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/abfcce22636ec4371a92e6ceb1077a54 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/b2e3c54b17f3d7fc54aab42082c470f8 +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/b878faf942403e313a5b103e5d80488e +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/b9b29a56a8585a110f306871e8938d2b +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/ba56eb60d599a0ca3d2f6b67772774c2 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/c502e11bd52b854e6af9627c3da0616a +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/cebfc296bf824dfc0f567874a00522d4 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/cf29797a4195344bac977b8ebfca7fff +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/e33b68bc0cecc21d45c44c8d2fd46c76 +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/e4b5a49edafa42a1ffe8f10535156b1b +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/edbef6e0d0a4742346cf479f2c522eb0 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/f1ea202e87b3ffc6964c9b0358531976 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/f209bca5b11567d04157eefee66c6a48 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/f5d86e31abec9b44e777e3f639187d5a +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/f644fd75cbead0e58c847aa16546e2a8 +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/f844ec54464006be394ce9de15eb0814 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/f950876669f7719a544d0de445843b08 +0 -0
  100. data/test/dummy/tmp/cache/assets/test/sass/d58d4fb9eedfbbaea362e7eed4f4b120ecc36459/enhancements.css.scssc +0 -0
  101. data/test/dummy/tmp/cache/assets/test/sprockets/138f3adae029720184284e5af56ba6ee +0 -0
  102. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  103. data/test/dummy/tmp/cache/assets/test/sprockets/165fa1b3eb4e30266c9cd78ba25a6879 +0 -0
  104. data/test/dummy/tmp/cache/assets/test/sprockets/1b48b24452c10fa45f34ec79aa2ca587 +0 -0
  105. data/test/dummy/tmp/cache/assets/test/sprockets/1c9faaf28d05409b88ad3113374d613c +0 -0
  106. data/test/dummy/tmp/cache/assets/test/sprockets/1e1c73f8892119a4dbc6ead7718b4472 +0 -0
  107. data/test/dummy/tmp/cache/assets/test/sprockets/20537eac47b88a0b70cf0fec72c5c957 +0 -0
  108. data/test/dummy/tmp/cache/assets/test/sprockets/23a02f793bdc3b6a6cbd015f184c6f6c +0 -0
  109. data/test/dummy/tmp/cache/assets/test/sprockets/2757fae967a52701ef3724ae5a76c4a8 +0 -0
  110. data/test/dummy/tmp/cache/assets/test/sprockets/29e4552fca58a1885579b3932b6a9603 +0 -0
  111. data/test/dummy/tmp/cache/assets/test/sprockets/2b731b63fb1d665043d920a05b591cdc +0 -0
  112. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  113. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  114. data/test/dummy/tmp/cache/assets/test/sprockets/3f657ddfc843294ed3fc8242f82e7a97 +0 -0
  115. data/test/dummy/tmp/cache/assets/test/sprockets/40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  116. data/test/dummy/tmp/cache/assets/test/sprockets/4838bd0bcba2e22c3c7aef8feb88db17 +0 -0
  117. data/test/dummy/tmp/cache/assets/test/sprockets/4a98a84c5ce12f2b9646335623b4e224 +0 -0
  118. data/test/dummy/tmp/cache/assets/test/sprockets/4ea33e825e6e38bd22dccab488a0255b +0 -0
  119. data/test/dummy/tmp/cache/assets/test/sprockets/65dccf676de4439612547abc6451ba65 +0 -0
  120. data/test/dummy/tmp/cache/assets/test/sprockets/69bda14eaa1d8ad1ea1235abb619e366 +0 -0
  121. data/test/dummy/tmp/cache/assets/test/sprockets/7b45798a1475deb0d6739c888f060c96 +0 -0
  122. data/test/dummy/tmp/cache/assets/test/sprockets/7be9086c960bb4384c9d23a52e489f29 +0 -0
  123. data/test/dummy/tmp/cache/assets/test/sprockets/86f909bf5baee50515afadaa3ce2df8f +0 -0
  124. data/test/dummy/tmp/cache/assets/test/sprockets/8c81470cda06da3ee9ec2181fe7743b0 +0 -0
  125. data/test/dummy/tmp/cache/assets/test/sprockets/8e3f978ef00686e7a7cad1a57185f90a +0 -0
  126. data/test/dummy/tmp/cache/assets/test/sprockets/8e5a9738e9bc15478e026d98335454f9 +0 -0
  127. data/test/dummy/tmp/cache/assets/test/sprockets/8f29e45e02d0321a6250df9b5ca050fe +0 -0
  128. data/test/dummy/tmp/cache/assets/test/sprockets/9b9c0e78635195bcb386a8b6e9ee1e97 +0 -0
  129. data/test/dummy/tmp/cache/assets/test/sprockets/a49b0e8a393070d4a440d78743af3460 +0 -0
  130. data/test/dummy/tmp/cache/assets/test/sprockets/abfcce22636ec4371a92e6ceb1077a54 +0 -0
  131. data/test/dummy/tmp/cache/assets/test/sprockets/b878faf942403e313a5b103e5d80488e +0 -0
  132. data/test/dummy/tmp/cache/assets/test/sprockets/b9b29a56a8585a110f306871e8938d2b +0 -0
  133. data/test/dummy/tmp/cache/assets/test/sprockets/cebfc296bf824dfc0f567874a00522d4 +0 -0
  134. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  135. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  136. data/test/dummy/tmp/cache/assets/test/sprockets/e33b68bc0cecc21d45c44c8d2fd46c76 +0 -0
  137. data/test/dummy/tmp/cache/assets/test/sprockets/e4b5a49edafa42a1ffe8f10535156b1b +0 -0
  138. data/test/dummy/tmp/cache/assets/test/sprockets/edbef6e0d0a4742346cf479f2c522eb0 +0 -0
  139. data/test/dummy/tmp/cache/assets/test/sprockets/f1ea202e87b3ffc6964c9b0358531976 +0 -0
  140. data/test/dummy/tmp/cache/assets/test/sprockets/f209bca5b11567d04157eefee66c6a48 +0 -0
  141. data/test/dummy/tmp/cache/assets/test/sprockets/f5d86e31abec9b44e777e3f639187d5a +0 -0
  142. data/test/dummy/tmp/cache/assets/test/sprockets/f644fd75cbead0e58c847aa16546e2a8 +0 -0
  143. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  144. data/test/dummy/tmp/cache/assets/test/sprockets/f950876669f7719a544d0de445843b08 +0 -0
  145. data/test/dummy/tmp/pids/server.pid +1 -0
  146. metadata +299 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 137ce1705597829ac39367ead7a49ef91ffc0c40
4
- data.tar.gz: 19220503a1da5878e6e1e5f69c15008e7a4d320a
3
+ metadata.gz: fa9f9f989f87f7a55dd5a9174add48b1947727ae
4
+ data.tar.gz: 52d22be3a15e569dc030f43b7bb31cc59b07f094
5
5
  SHA512:
6
- metadata.gz: ec69cdbe7ead12a9b70dcb56345fc57f15bc952a8889d42694219ffe386e4c1cb40dba1aa8a5e1e135449b3dff4c378715c1eedcf26934ef8bd214bae788b4c5
7
- data.tar.gz: 4389199fc43be31caddfe97df80494970c609c9f24638742d99163cdadc0ff4081c02baafec46a448204733432f995a89ebb87ceadcdc9de2b63d72bf17b7521
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 DEFAULTS
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
- #photos.polygallery-cocoon-table
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
- defaults = if options[:associations] && options[:associations][:class_name] && options[:associations][:class_name] != 'Polygallery::Gallery'
17
- Kernel.const_get(options[:associations][:class_name])::DEFAULTS
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
- klass = self.class_name.present? ? Kernel.const_get(self.class_name) : Gallery
8
- klass::DEFAULTS
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
- # raise 'BOOM' if options.keys.any?
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
- :gallery_title => self.title
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
@@ -1,3 +1,3 @@
1
1
  module Polygallery
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -13,4 +13,5 @@
13
13
  //= require jquery
14
14
  //= require bootstrap.min
15
15
  //= require polygallery/init
16
+ //= require simple_form_fileinput/init
16
17
  //= require_tree .
@@ -13,5 +13,6 @@
13
13
  *= require_tree .
14
14
  *= require bootstrap.min
15
15
  *= require bootstrap-theme.min
16
+ *= require simple_form_fileinput/enhancements
16
17
  *= require_self
17
18
  */
@@ -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 => polygallery_params)
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
- DEFAULTS = {
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, :associations => {
5
- :gallery => { :class_name => '::CustomGallery' },
6
- :photos => { :class_name => '::CustomPhoto' }
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= yield
21
- = javascript_include_tag 'application'
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"} } &times;
24
+ = msg
25
+ = yield
26
+ = javascript_include_tag 'application'
@@ -22,5 +22,6 @@ module Dummy
22
22
  # config.eager_load_paths += ["#{Rails.root}/lib"]
23
23
 
24
24
  # config.assets.prefix = ''
25
+ config.eager_load_paths += %W(#{File.expand_path(Rails.root.join('..', '..', 'lib'))})
25
26
  end
26
- end
27
+ end
@@ -1,15 +1,17 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class FileInput < Base
4
- def input
5
- input_html_options[:title] = 'Drop a file here, or click to browse...'
6
- if input_html_options.key?(:data)
7
- input_html_options[:data][:filename_placement] = 'inside'
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
- input_html_options[:data] = {:filename_placement => 'inside'}
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, input_html_options)
13
+ @builder.file_field(attribute_name, merged_input_options)
12
14
  end
13
15
  end
14
16
  end
15
- end
17
+ end
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+
2
3
  resources :events
3
4
 
4
5
  root 'home#index'
@@ -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
@@ -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: 20141001192141) do
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