polygallery 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/app/controllers/concerns/polygallery/strong_params.rb +5 -3
- data/app/models/concerns/polygallery/acts_as_polyphoto.rb +64 -32
- data/app/views/polygallery/galleries/_simple_fields_for.html.haml +5 -4
- data/app/views/polygallery/photos/_simple_fields_for.html.haml +2 -1
- data/lib/polygallery/has_polygallery.rb +85 -14
- data/lib/polygallery/has_polyphotos.rb +46 -55
- data/lib/polygallery/railtie.rb +1 -1
- data/lib/polygallery/version.rb +1 -1
- data/test/dummy/app/controllers/events_controller.rb +2 -1
- data/test/dummy/app/controllers/home_controller.rb +1 -0
- data/test/dummy/app/models/event.rb +1 -5
- data/test/dummy/app/views/events/_simple_form.html.haml +1 -1
- data/test/dummy/log/development.log +4002 -0
- data/test/dummy/log/test.log +11639 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/001/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/001/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/001/thumb/logo_placeholder_medium.png +0 -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/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/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/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/005/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/005/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/005/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/006/custom/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/006/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/006/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/006/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/007/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/007/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/007/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/008/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/008/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/008/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/011/custom/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/011/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/011/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/011/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/014/custom/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/014/medium/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/014/original/logo_placeholder_medium.png +0 -0
- data/test/dummy/public/system/polygallery/photos/photos/000/000/014/thumb/logo_placeholder_medium.png +0 -0
- data/test/dummy/spec/features/events_spec.rb +54 -7
- metadata +50 -4
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 748c58237c3287c39ed71c22b4d610f9930d16fe
|
4
|
+
data.tar.gz: 4679777b8785fb32c0e997c6083c441dffa80ba9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 778e7320a67042cd19d166f52c824002790aa3141061609069af9d1f2970993d3cef86623640a1b611a98df0f6b67b7019e65f652742afb4db525c8a0e138cb1
|
7
|
+
data.tar.gz: c2d0c55787f5f5e3f2a60f83b28ab953d16e093cf89f743361f2e1da3074a6219c965e8d2e0c426b073877e06a3e2cb1d1ab546cfbbe106dfbccc6e08a667b39
|
@@ -4,7 +4,9 @@ module Polygallery::StrongParams
|
|
4
4
|
included do
|
5
5
|
end
|
6
6
|
|
7
|
-
def polygallery_params
|
8
|
-
[:id, :title, :_destroy, {:
|
7
|
+
def polygallery_params(association='photos')
|
8
|
+
[:id, :title, :_destroy, {:"#{association}_attributes" =>
|
9
|
+
[:id, :photo, :title, :caption,
|
10
|
+
:gallery_title, :_destroy]}]
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
@@ -2,47 +2,79 @@ module Polygallery
|
|
2
2
|
module ActsAsPolyphoto
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
DEFAULTS = {
|
6
|
-
:paperclip => {
|
7
|
-
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
8
|
-
:default_url => '/images/:style/missing.png'
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
5
|
included do
|
13
|
-
attr_accessor :photo_to_upload,
|
6
|
+
attr_accessor :photo_to_upload, :polygallery_options,
|
14
7
|
: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
|
8
|
+
acts_as_polyphoto
|
26
9
|
end
|
27
10
|
|
28
11
|
module ClassMethods
|
29
|
-
|
12
|
+
def acts_as_polyphoto(options={})
|
13
|
+
defaults = self.polygallery_settings
|
14
|
+
settings = defaults.deep_merge(options)
|
15
|
+
|
16
|
+
after_initialize do
|
17
|
+
@polygallery_settings = settings if settings == HasPolygallery::DEFAULTS
|
18
|
+
self.initialize_polyphoto
|
19
|
+
end
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
DEFAULTS[:paperclip]
|
34
|
-
end
|
21
|
+
include ActsAsPolyphoto::LocalInstanceMethods
|
22
|
+
end
|
35
23
|
|
36
|
-
|
37
|
-
|
24
|
+
def polygallery_settings
|
25
|
+
@polygallery_settings || HasPolygallery::DEFAULTS
|
26
|
+
end
|
38
27
|
end
|
39
28
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
module LocalInstanceMethods
|
30
|
+
def include_polygallery_settings(settings)
|
31
|
+
@polygallery_settings = settings
|
32
|
+
self.initialize_polyphoto
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize_polyphoto
|
36
|
+
settings = self.polygallery_settings
|
37
|
+
|
38
|
+
self.class.belongs_to settings[:association_names][:gallery],
|
39
|
+
:class_name => settings[:associations][:gallery][:class_name],
|
40
|
+
:foreign_key => :gallery_id
|
41
|
+
|
42
|
+
self.init_attachment
|
43
|
+
self.class.before_save :process_photo_to_upload
|
44
|
+
end
|
45
|
+
|
46
|
+
def polygallery_settings
|
47
|
+
polygallery_options || @polygallery_settings || HasPolygallery::DEFAULTS
|
48
|
+
# if gallery_title.present? && galleryable_type.present?
|
49
|
+
# galleryable_class = Kernel.const_get(galleryable_type)
|
50
|
+
# galleryable_class.send :"#{gallery_title}_settings"
|
51
|
+
# elsif gallery_title.present?
|
52
|
+
# self.send(gallery_title.to_sym).polygallery_settings
|
53
|
+
# elsif self.gallery.present? && gallery.polygallery_settings.present?
|
54
|
+
# self.gallery.polygallery_settings
|
55
|
+
# else
|
56
|
+
# HasPolygallery::DEFAULTS
|
57
|
+
# end
|
58
|
+
end
|
59
|
+
|
60
|
+
def paperclip_settings
|
61
|
+
self.polygallery_settings[:paperclip]
|
62
|
+
end
|
63
|
+
|
64
|
+
def process_photo_to_upload
|
65
|
+
self.photo = File.open(photo_to_upload) if photo_to_upload.present?
|
66
|
+
end
|
67
|
+
|
68
|
+
def init_attachment
|
69
|
+
self.class.has_attached_file :photo,
|
70
|
+
:styles => paperclip_settings[:styles],
|
71
|
+
:default_url => paperclip_settings[:default_url]
|
72
|
+
validations = polygallery_settings[:paperclip_validations]
|
73
|
+
self.class.validates_attachment_content_type(:photo, :content_type =>
|
74
|
+
validations[:content_type]) if validations[:content_type]
|
75
|
+
self.class.validates_attachment_presence(:photo) if validations[:presence]
|
76
|
+
end
|
77
|
+
|
46
78
|
end
|
47
79
|
end
|
48
80
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
- photo_association_name = gallery.polygallery_settings[:association_names][:photos]
|
1
2
|
= f.simple_fields_for gallery.title.to_sym do |ff|
|
2
3
|
= ff.input_field :title, :as => :hidden, :value => gallery.title
|
3
4
|
|
4
5
|
- if options[:label]
|
5
6
|
%h3.lead
|
6
|
-
= link_to_add_association 'Add Photo', ff,
|
7
|
+
= link_to_add_association 'Add Photo', ff, photo_association_name, :partial => 'polygallery/photos/simple_fields_for', :class => 'btn btn-default btn-sm pull-right', :data => {:association_insertion_node => "##{photo_association_name} .photo-receptacle", :association_insertion_method => 'append'}
|
7
8
|
- if options[:label] == true
|
8
9
|
= gallery.title.titleize
|
9
10
|
- else
|
10
11
|
= options[:label].titleize
|
11
|
-
.polygallery-cocoon-table{:id =>
|
12
|
+
.polygallery-cocoon-table{:id => photo_association_name.to_s}
|
12
13
|
%table.table.table-bordered.table-striped.table-condensed.polygallery-photos-table
|
13
14
|
%thead
|
14
15
|
%tr
|
@@ -16,8 +17,8 @@
|
|
16
17
|
%th File
|
17
18
|
%th.text-center Actions
|
18
19
|
%tbody.photo-receptacle
|
19
|
-
= ff.simple_fields_for
|
20
|
-
= render
|
20
|
+
= ff.simple_fields_for photo_association_name do |pf|
|
21
|
+
= render 'polygallery/photos/simple_fields_for', :f => pf
|
21
22
|
|
22
23
|
-#- if !options[:label]
|
23
24
|
-# = ff.input_field :content, options[:input_html].merge({:as => :ckeditor})
|
@@ -1,9 +1,10 @@
|
|
1
1
|
%tr.nested-fields{:data => {:new => f.object.new_record?}}
|
2
2
|
%td.text-center
|
3
|
+
-# = f.input_field :gallery_title
|
3
4
|
= image_tag f.object.photo.file? ? f.object.photo.url(:thumb) : 'polygallery/thumbnail-missing.jpg', :class => 'img-responsive' # image_path('polygallery/thumbnail-missing.jpg')
|
4
5
|
%td
|
5
6
|
= f.input_field :photo
|
6
7
|
= f.input_field :caption, :placeholder => "Caption... (optional)", :style => "margin-top:5px;", :as => :string
|
7
8
|
%td.text-center{:style => "width:51px;"}
|
8
9
|
= link_to_remove_association f, :class => 'btn btn-default btn-sm' do
|
9
|
-
%span.glyphicon.glyphicon-trash
|
10
|
+
%span.glyphicon.glyphicon-trash
|
@@ -2,8 +2,51 @@ module Polygallery
|
|
2
2
|
module HasPolygallery
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
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
|
+
:foreign_key => :gallery_id
|
17
|
+
}
|
18
|
+
},
|
19
|
+
:association_names => {
|
20
|
+
:gallery => :gallery,
|
21
|
+
:photos => :photos
|
22
|
+
},
|
23
|
+
:nested_attributes => {
|
24
|
+
:gallery => {
|
25
|
+
:reject_if => :all_blank
|
26
|
+
# proc {|attributes| false }
|
27
|
+
# photo_attr_sets = attributes
|
28
|
+
# .select{|k, _| k.include? 'photos_attributes' }
|
29
|
+
# photo_attr_sets.select{|_, photo_sets|
|
30
|
+
# photo_sets.select{|_, photo_attrs|
|
31
|
+
# puts photo_attrs
|
32
|
+
# photo_attrs.key? 'photo' }.empty? }.empty? }
|
33
|
+
},
|
34
|
+
:photos => {
|
35
|
+
:reject_if => proc {|attributes| !attributes.key?('photo') },
|
36
|
+
:allow_destroy => true}
|
37
|
+
},
|
38
|
+
:validates => {},
|
39
|
+
:paperclip => {
|
40
|
+
:styles => {:medium => '300x300#', :thumb => '100x100#'},
|
41
|
+
:default_url => ActionController::Base.helpers.image_path('polygallery/thumbnail-missing.png')
|
42
|
+
},
|
43
|
+
:paperclip_validations => {
|
44
|
+
:content_type => /\Aimage\/.*\Z/,
|
45
|
+
:presence => false
|
46
|
+
}
|
47
|
+
}
|
6
48
|
|
49
|
+
included do
|
7
50
|
end
|
8
51
|
|
9
52
|
module ClassMethods
|
@@ -17,49 +60,77 @@ module Polygallery
|
|
17
60
|
gallery_association = options[:associations][:gallery] if associations.present?
|
18
61
|
gallery_class_name = gallery_association[:class_name] if gallery_association.present?
|
19
62
|
defaults = if gallery_class_name.present? && gallery_class_name != 'Polygallery::Gallery'
|
20
|
-
Kernel.const_get(gallery_class_name)::
|
63
|
+
Kernel.const_get(gallery_class_name)::POLYGALLERY_DEFAULTS
|
21
64
|
else
|
22
|
-
|
65
|
+
HasPolygallery::DEFAULTS
|
23
66
|
end
|
67
|
+
if options[:association_names].nil? && title.to_s != 'gallery'
|
68
|
+
options[:association_names] = {
|
69
|
+
:gallery => title.to_sym,
|
70
|
+
:photos => :"#{title.to_s.gsub('_gallery', '')}_photos"
|
71
|
+
}
|
72
|
+
end
|
24
73
|
settings = defaults.deep_merge(options)
|
25
74
|
cattr_accessor "#{title}_settings".to_sym
|
26
75
|
send("#{title}_settings=".to_sym, settings)
|
27
76
|
|
28
77
|
has_one title.to_sym, -> { where(:title => title.to_s) }, settings[:associations][:gallery]
|
29
|
-
|
30
|
-
|
31
|
-
:through => title.to_sym,
|
78
|
+
has_many settings[:association_names][:photos],
|
79
|
+
:through => :"#{title}",
|
32
80
|
:source => settings[:association_names][:photos],
|
33
81
|
:class_name => settings[:associations][:photos][:class_name]
|
82
|
+
accepts_nested_attributes_for settings[:association_names][:gallery],
|
83
|
+
settings[:nested_attributes][:gallery]
|
84
|
+
accepts_nested_attributes_for settings[:association_names][:photos],
|
85
|
+
settings[:nested_attributes][:photos]
|
86
|
+
|
87
|
+
after_initialize :build_galleries
|
34
88
|
|
35
|
-
after_initialize do
|
36
|
-
send("build_#{title.to_s}".to_sym) if send(title.to_sym).nil?
|
37
|
-
send(title.to_sym).send(:galleryable=, self)
|
38
|
-
end
|
39
89
|
include HasPolygallery::LocalInstanceMethods
|
40
90
|
end
|
41
91
|
|
42
92
|
def polygalleries
|
43
|
-
self.reflect_on_all_associations(:has_one)
|
93
|
+
self.reflect_on_all_associations(:has_one)
|
94
|
+
.select{|a| a.foreign_key == 'galleryable_id'}.map(&:name)
|
44
95
|
end
|
45
96
|
|
46
|
-
def has_polygallery?(title)
|
47
|
-
|
97
|
+
def has_polygallery?(title=nil)
|
98
|
+
return polygalleries.any? if title.nil?
|
99
|
+
polygalleries.include?(title)
|
48
100
|
end
|
49
101
|
end
|
50
102
|
|
51
103
|
module LocalInstanceMethods
|
52
104
|
def polygalleries
|
105
|
+
# TODO: use association reflections instead of direct class selection
|
53
106
|
Gallery.select('polygallery_galleries.title')
|
54
107
|
.where(:galleryable => self)
|
55
108
|
.group('polygallery_galleries.title')
|
56
109
|
.map(&:title)
|
57
110
|
end
|
58
111
|
|
59
|
-
def has_polygallery?(title)
|
112
|
+
def has_polygallery?(title=nil)
|
113
|
+
return polygalleries.any? if title.nil?
|
60
114
|
polygalleries.include?(title)
|
61
115
|
end
|
62
116
|
|
117
|
+
def build_galleries
|
118
|
+
return unless self.class.has_polygallery?
|
119
|
+
self.class.polygalleries.each do |pg|
|
120
|
+
gallery_association = send pg
|
121
|
+
next if gallery_association.present?
|
122
|
+
gallery_settings = send :"#{pg.to_s}_settings"
|
123
|
+
gallery_association ||= send :"build_#{pg.to_s}",
|
124
|
+
:polygallery_options => gallery_settings
|
125
|
+
gallery_association.galleryable ||= self
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def build_first_photos
|
130
|
+
build_galleries(&:build_first_photo)
|
131
|
+
return unless self.class.has_polygallery?
|
132
|
+
self.class.polygalleries.each {|pg| send(pg).build_first_photo }
|
133
|
+
end
|
63
134
|
end
|
64
135
|
end
|
65
136
|
end
|
@@ -1,87 +1,78 @@
|
|
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
|
-
}
|
32
4
|
|
33
5
|
included do
|
34
|
-
|
35
|
-
# klass = self.class_name.present? ? Kernel.const_get(self.class_name) : Gallery
|
36
|
-
# klass::DEFAULTS
|
37
|
-
# end
|
6
|
+
attr_accessor :polygallery_options
|
38
7
|
end
|
39
8
|
|
40
9
|
module ClassMethods
|
41
|
-
def has_polyphotos(title=
|
10
|
+
def has_polyphotos(title=nil, options={})
|
11
|
+
defaults = self.polygallery_settings
|
12
|
+
association_names = (options[:association_names].present? ?
|
13
|
+
options : defaults)[:association_names]
|
14
|
+
title ||= association_names[:photos].to_s
|
42
15
|
if title.is_a? Hash
|
43
16
|
options = title
|
44
|
-
title =
|
17
|
+
title = association_names[:photos].to_s
|
45
18
|
end
|
46
19
|
|
47
|
-
|
48
|
-
|
49
|
-
cattr_accessor :polygallery_settings
|
50
|
-
send(:polygallery_settings=, settings)
|
51
|
-
puts HasPolyphotos::DEFAULTS
|
52
|
-
has_many title.to_sym, settings[:associations][:photos]
|
53
|
-
accepts_nested_attributes_for title.to_sym, settings[:nested_attributes][:photos] # TODO: get the actual @settings somehow
|
20
|
+
settings = defaults.deep_merge options
|
21
|
+
|
54
22
|
after_initialize do
|
55
|
-
|
56
|
-
|
57
|
-
:galleryable_id => galleryable_id,
|
58
|
-
:galleryable_type => galleryable_type,
|
59
|
-
:"#{settings[:association_names][:gallery]}_title" => self.title
|
60
|
-
) unless send(title.to_sym).any?
|
23
|
+
@polygallery_settings = settings if settings == HasPolygallery::DEFAULTS
|
24
|
+
self.initialize_polygallery
|
61
25
|
end
|
62
|
-
|
26
|
+
|
63
27
|
include HasPolyphotos::LocalInstanceMethods
|
64
28
|
end
|
65
29
|
|
66
|
-
|
67
|
-
|
68
|
-
|
30
|
+
def polygallery_settings
|
31
|
+
@polygallery_settings || HasPolygallery::DEFAULTS
|
32
|
+
end
|
69
33
|
end
|
70
34
|
|
71
35
|
|
72
36
|
module LocalInstanceMethods
|
73
37
|
def set_nest(photo)
|
74
|
-
photo.
|
38
|
+
photo.send(:"#{title}=", self) if photo.send(:"#{title}").nil?
|
75
39
|
photo.galleryable_id ||= galleryable_id
|
76
40
|
photo.galleryable_type ||= galleryable_type
|
77
41
|
photo.gallery_title ||= title
|
78
42
|
end
|
79
43
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
44
|
+
# def polygallery_settings
|
45
|
+
# Kernel.const_get(self.galleryable_type).send :"#{self.title}_settings"
|
46
|
+
# end
|
47
|
+
|
48
|
+
def include_polygallery_settings(settings)
|
49
|
+
@polygallery_settings = settings
|
50
|
+
self.initialize_polygallery
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize_polygallery
|
54
|
+
settings = self.polygallery_settings
|
55
|
+
association_names = settings[:association_names]
|
56
|
+
self.class.has_many association_names[:photos],
|
57
|
+
settings[:associations][:photos].deep_merge({})
|
58
|
+
self.class.accepts_nested_attributes_for association_names[:photos],
|
59
|
+
settings[:nested_attributes][:photos]
|
83
60
|
end
|
84
61
|
|
62
|
+
def build_first_photo
|
63
|
+
settings = polygallery_settings
|
64
|
+
photo_association = send settings[:association_names][:photos]
|
65
|
+
photo_association.build(
|
66
|
+
:polygallery_options => settings,
|
67
|
+
:galleryable_id => galleryable_id,
|
68
|
+
:galleryable_type => galleryable_type,
|
69
|
+
:gallery_title => self.title
|
70
|
+
) unless photo_association.any?
|
71
|
+
end
|
72
|
+
|
73
|
+
def polygallery_settings
|
74
|
+
polygallery_options || @polygallery_settings || HasPolygallery::DEFAULTS
|
75
|
+
end
|
85
76
|
end
|
86
77
|
end
|
87
78
|
end
|