polygallery 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b10c17c8dd4f7ed052502b8dd890e82a04c4665c
4
- data.tar.gz: 7af3e71db31b091b5f1ed4feebd3dbe1ccb5db9a
3
+ metadata.gz: 8829251245b28dc2aad475352c43d7b87e53c421
4
+ data.tar.gz: 65d64fa087c79cb6b302adb49b467a6be196d705
5
5
  SHA512:
6
- metadata.gz: f71bae3a031023407dced43ca0316f3f96bdf8bf3f8f3df8624cbd368a6e89c35320eca0143522f4eaaca798a1f919e2bbb7d4388bde00946c1ba8bc03d2e04b
7
- data.tar.gz: e3d8ad0b667cbe225c7b37fc74017c3994638a46e7f3ed65fc79f483404a8820f9c463c84830eef7c1688f92bfaf6579874c908923a40b0db1feee5efdfcdde0
6
+ metadata.gz: db78604c051a6e545e94b1e39ff7aafa12479b35f976c6040a7f3205ee460ac048d819d42a5c5bd6ecc173e44ed9dccf288425d3b1ac73e78159ff7c0304e718
7
+ data.tar.gz: bbf0ea8af4cd065796f21c5e297f050668228f368e2d59df8ed36b941ec199b69a3b4ed8cb413d5e16f010c52f6efc45375acab5670e8b2d33a05f13fa8b533b
@@ -1,4 +1,5 @@
1
1
  (($)->
2
- $('.polygallery-cocoon-table').on 'cocoon:after-insert', (e, insertedItem)->
3
- $(insertedItem).find('input[type=file]').bootstrapFileInput()
4
- )(jQuery)
2
+ $(document).ready ->
3
+ $('.polygallery-cocoon-table').on 'cocoon:after-insert', (e, insertedItem)->
4
+ $(insertedItem).find('input[type=file]').bootstrapFileInput()
5
+ )(jQuery)
@@ -1,6 +1,5 @@
1
1
  module Polygallery
2
2
  class Photo < ActiveRecord::Base
3
- include ActsAsPolyphoto
4
3
  acts_as_polyphoto
5
4
  end
6
5
  end
@@ -1,23 +1,18 @@
1
- - photo_association_name = gallery.polygallery_settings[:association_names][:photos]
2
- = f.simple_fields_for gallery.title.to_sym do |ff|
3
- = ff.input_field :title, :as => :hidden, :value => gallery.title
4
- = ff.input_field :galleryable_id, :as => :hidden
5
- = ff.input_field :galleryable_type, :as => :hidden
1
+ - photo_association_name = f.object.polygallery_settings[:association_names][:photos]
2
+ = f.input_field :title, :as => :hidden, :value => f.object.title
3
+ = f.input_field :galleryable_id, :as => :hidden
4
+ = f.input_field :galleryable_type, :as => :hidden
6
5
 
7
- - if options[:label]
8
- %h3.lead
9
- = 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_association_name} .photo-receptacle", :association_insertion_method => 'append'}
10
- - if options[:label] == true
11
- = gallery.title.titleize
12
- - else
13
- = options[:label].titleize
14
- .polygallery-cocoon-table{:id => photo_association_name.to_s}
15
- %table.table.table-bordered.table-striped.table-condensed.polygallery-photos-table
16
- %thead
17
- %tr
18
- %th.text-center{:style => 'width:85px;'} Photo
19
- %th File
20
- %th.text-center Actions
21
- %tbody.photo-receptacle
22
- = ff.simple_fields_for :photos do |pf| # photo_association_name do |pf|
23
- = render 'polygallery/photos/simple_fields_for', :f => pf
6
+ %h3.lead
7
+ = link_to_add_association 'Add Photo', f, :photos, 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'}
8
+ = f.object.title.titleize
9
+ .polygallery-cocoon-table{:id => photo_association_name.to_s}
10
+ %table.table.table-bordered.table-striped.table-condensed.polygallery-photos-table
11
+ %thead
12
+ %tr
13
+ %th.text-center{:style => 'width:85px;'} Photo
14
+ %th File
15
+ %th.text-center Actions
16
+ %tbody.photo-receptacle
17
+ = f.simple_fields_for :photos do |pf| # photo_association_name do |pf|
18
+ = render 'polygallery/photos/simple_fields_for', f: pf
@@ -1,6 +1,8 @@
1
- %tr.nested-fields{:data => {:new => f.object.new_record?}}
1
+ %tr{class: "nested-fields #{f.object.new_record? ? 'new-polyphoto' : ''}",
2
+ data: { new: f.object.new_record? }}
2
3
  %td.text-center
3
4
  = f.input_field :gallery_title, :as => :hidden
5
+ = f.input_field :gallery_id, :as => :hidden
4
6
  = f.input_field :galleryable_id, :as => :hidden
5
7
  = f.input_field :galleryable_type, :as => :hidden
6
8
  = image_tag f.object.photo.file? ? f.object.photo.url(:thumb) : 'polygallery/thumbnail-missing.jpg', class: 'img-responsive'
data/config/routes.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  Polygallery::Engine.routes.draw do
2
2
  resources :photos
3
-
4
3
  resources :galleries
5
-
6
4
  end
@@ -0,0 +1,6 @@
1
+ require 'polygallery'
2
+
3
+ module Polygallery
4
+ module ActsAsPolygallery
5
+ end
6
+ end
@@ -1,10 +1,8 @@
1
+ require 'polygallery'
2
+
1
3
  module Polygallery
2
4
  module ActsAsPolyphoto
3
5
  extend ActiveSupport::Concern
4
-
5
- included do
6
- end
7
-
8
6
  module ClassMethods
9
7
  def acts_as_polyphoto(options={})
10
8
  defaults = self.polygallery_settings
@@ -16,7 +14,17 @@ module Polygallery
16
14
  init_attachment settings[:paperclip]
17
15
  init_associations settings
18
16
 
19
- before_validation :process_photo_to_upload
17
+ before_validation do
18
+ # self.polygallery_options = nil
19
+ # self.polygallery_options = self.polygallery_settings
20
+ # self.class.init_attachment self.polygallery_options
21
+ if gallery.present?
22
+ self.gallery_title = gallery.title if gallery_title.blank?
23
+ self.galleryable ||= gallery.galleryable
24
+ initialize_polyphoto
25
+ end
26
+ process_photo_to_upload
27
+ end
20
28
  # before_save {
21
29
  # # puts "Photo changes: #{self.changes.inspect}"
22
30
  # puts 'SAVING PHOTO!' }
@@ -30,7 +38,7 @@ module Polygallery
30
38
  end
31
39
 
32
40
  def polygallery_settings
33
- HasPolygallery::DEFAULTS
41
+ DEFAULT_SETTINGS
34
42
  end
35
43
 
36
44
  def init_attachment(paperclip_settings)
@@ -44,7 +52,7 @@ module Polygallery
44
52
  validates_attachment_presence(:photo) if validations[:presence]
45
53
  end
46
54
 
47
- def init_associations(settings=HasPolygallery::DEFAULTS)
55
+ def init_associations(settings=DEFAULT_SETTINGS)
48
56
  belongs_to settings[:association_names][:gallery],
49
57
  :class_name => settings[:associations][:gallery][:class_name],
50
58
  :foreign_key => :gallery_id
@@ -76,14 +84,14 @@ module Polygallery
76
84
  .send(:"#{self.gallery_title}_settings")
77
85
  end
78
86
  return s if s.present?
79
- # elsif respond_to?(:gallery) && gallery.present?
80
- # return gallery.polygallery_settings
81
- # elsif self.gallery_id.present?
82
- # g = Kernel.const_get(self.galleryable_type).find(self.gallery_id)
83
- # if g.present?
84
- # self.gallery_title = g.title
85
- # return self.polygallery_settings
86
- # end
87
+ elsif respond_to?(:gallery) && gallery.present?
88
+ return gallery.polygallery_settings
89
+ elsif self.gallery_id.present?
90
+ g = Polygallery::Gallery.find(self.gallery_id)
91
+ if g.present?
92
+ self.gallery_title = g.title
93
+ return self.polygallery_settings
94
+ end
87
95
  end
88
96
  self.class.polygallery_settings
89
97
  # if gallery_title.present? && galleryable_type.present?
@@ -94,7 +102,7 @@ module Polygallery
94
102
  # elsif self.gallery.present? && gallery.polygallery_settings.present?
95
103
  # self.gallery.polygallery_settings
96
104
  # else
97
- # HasPolygallery::DEFAULTS
105
+ # DEFAULT_SETTINGS
98
106
  # end
99
107
  end
100
108
 
@@ -103,13 +111,29 @@ module Polygallery
103
111
  end
104
112
 
105
113
  def process_photo_to_upload
114
+ # As crazy as this looks, it's necessary to assign paperclip's
115
+ # dynamic styles through an association. It would be great if we
116
+ # could find a better way, though...
117
+ #
118
+ # This part runs the second try.
119
+ if photo_updated_at_changed? && gallery.present? &&
120
+ photo_to_upload.present? && File.exists?(photo_to_upload)
121
+ # puts 'Running the swaparoo!'
122
+ File.open(photo_to_upload, 'rb') {|h| self.photo = h }
123
+ # self.photo_to_upload = nil
124
+ end
125
+ # This part runs the first try.
106
126
  if self.photo.present? && self.photo_to_upload.nil?
107
- if self.new_record? || self.photo_file_name_changed?
108
- self.photo_to_upload = self.photo.staged_path
109
- self.photo = nil
127
+ # if self.new_record? || self.photo_file_name_changed?
128
+ if self.photo.staged?
129
+ # puts "#{photo_file_name} is staged!"
130
+ if File.exists? self.photo.staged_path
131
+ # puts "Setting photo to upload to #{photo_file_name}"
132
+ self.photo_to_upload = self.photo.staged_path
133
+ # self.photo = nil
134
+ end
110
135
  end
111
136
  end
112
- self.photo = File.open(photo_to_upload) if photo_to_upload.present?
113
137
  end
114
138
 
115
139
  def init_attachment
@@ -19,7 +19,7 @@ module Polygallery
19
19
  attrs = table_id; table_id = 'photos' end
20
20
  attrs ||= build :polygallery_photo
21
21
  trs = polyphoto_trs(table_id); last_tr = trs.last
22
- unless trs.length == 1 && last_tr.find('input[id$="_photo"]').value.blank?
22
+ unless last_tr[:class].include?('new-polyphoto') && last_tr.find('input[id$="_photo"]').value.blank?
23
23
  page.execute_script "$('#{add_polyphoto_btn_selector table_id}').click();"
24
24
  last_tr = polyphoto_trs(table_id).last
25
25
  end
@@ -0,0 +1,13 @@
1
+ require 'polygallery'
2
+ require 'polygallery/strong_params_helper'
3
+
4
+ module Polygallery
5
+ module ControllerHelpers
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include StrongParamsHelper
10
+ end
11
+
12
+ end
13
+ end
@@ -1,9 +1,38 @@
1
+ require 'polygallery'
2
+ require 'polygallery/controller_helpers'
3
+ require 'polygallery/model_helpers'
4
+ require 'polygallery/view_helpers'
5
+ require 'polygallery/simple_form_helper'
6
+ require 'polygallery/glue'
7
+
1
8
  module Polygallery
2
9
  class Engine < ::Rails::Engine
3
10
  isolate_namespace Polygallery
11
+
12
+ initializer 'polygallery.assets' do
13
+ Rails.application.config.assets.precompile +=
14
+ %w( polygallery/thumbnail-missing.jpg )
15
+ end
4
16
  initializer 'polygallery_engine.action_controller' do |app|
5
17
  ActiveSupport.on_load :action_controller do
6
-
18
+ ActionController::Base.send :include, ControllerHelpers
19
+ end
20
+ end
21
+ initializer 'polygallery.model_helpers' do
22
+ ActiveSupport.on_load :active_record do
23
+ ActiveRecord::Base.send :include, ModelHelpers
24
+ ActiveRecord::Base.send :include, Polygallery::Glue
25
+ end
26
+ end
27
+ initializer "polygallery.view_helpers" do
28
+ ActiveSupport.on_load :action_view do
29
+ ActionView::Base.send :include, ViewHelpers
30
+ if defined? SimpleForm
31
+ ActionView::Base.send :include, SimpleFormHelper
32
+ SimpleForm::FormBuilder.send :define_method, 'simple_fields_for_polygallery' do |*args, &block|
33
+ template.simple_fields_for_polygallery self, *args, &block
34
+ end
35
+ end
7
36
  end
8
37
  end
9
38
  initializer :append_migrations do |app|
@@ -7,6 +7,7 @@ FactoryGirl.define do
7
7
 
8
8
  factory :polygallery_photo, :class => Polygallery::Photo do
9
9
  caption { [nil, MFaker::BaconIpsum.paragraph].sample }
10
- photo { File.new get_random_photo }
10
+ photo { File.new get_random_photo }
11
+ # photo_to_upload { get_random_photo }
11
12
  end
12
13
  end
@@ -1,46 +1,8 @@
1
+ require 'polygallery'
2
+
1
3
  module Polygallery
2
4
  module HasPolygallery
3
5
  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
- :foreign_key => :gallery_id
17
- }
18
- },
19
- :association_names => {
20
- :gallery => :gallery,
21
- :photos => :photos
22
- },
23
- :nested_attributes => {
24
- :gallery => { :reject_if => :all_blank },
25
- :photos => {
26
- :allow_destroy => true,
27
- :reject_if => proc {|attributes|
28
- !attributes.key?('id') && attributes['photo'].nil? } }
29
- },
30
- :validates => {},
31
- :paperclip => {
32
- :styles => {:medium => '300x300#', :thumb => '100x100#'},
33
- :default_url => 'polygallery/thumbnail-missing.jpg'
34
- },
35
- :paperclip_validations => {
36
- :content_type => /\Aimage\/.*\Z/,
37
- :presence => false
38
- }
39
- }
40
-
41
- included do
42
- end
43
-
44
6
  module ClassMethods
45
7
  def has_polygallery(title='gallery', options={})
46
8
  if title.is_a? Hash
@@ -48,19 +10,18 @@ module Polygallery
48
10
  title = 'gallery'
49
11
  end
50
12
 
51
- defaults = HasPolygallery::DEFAULTS
13
+ defaults = DEFAULT_SETTINGS
52
14
  if options[:association_names].nil? && title.to_s != 'gallery'
53
15
  options[:association_names] = {
54
16
  :gallery => :"#{title}",
55
- :photos => :"#{title.to_s.gsub('_gallery', '')}_photos"
56
- }
17
+ :photos => :"#{title.to_s.gsub('_gallery', '')}_photos" }
57
18
  end
58
19
  settings = defaults.deep_merge(options)
59
20
  cattr_accessor "#{title}_settings".to_sym
60
21
  send("#{title}_settings=".to_sym, settings)
61
22
  attr_accessor :"#{title}_attributes", :galleries_built
62
23
 
63
- has_one title.to_sym, -> { where(:title => title.to_s) }, settings[:associations][:gallery]
24
+ has_one title.to_sym, -> { where(title: title.to_s) }, settings[:associations][:gallery]
64
25
  has_many settings[:association_names][:photos],
65
26
  :through => :"#{title}",
66
27
  :source => :photos, # settings[:association_names][:photos],
@@ -74,8 +35,8 @@ module Polygallery
74
35
  # puts "GA: #{self.gallery_attributes.inspect}"
75
36
  if self.gallery_attributes.nil?
76
37
  # puts 'BUILDING FIRST PHOTOS ON INIT!'
38
+ build_gallery_associations
77
39
  build_first_photos
78
- # build_gallery_associations
79
40
  end
80
41
  end
81
42
  # puts instance.inspect
@@ -213,4 +174,4 @@ module Polygallery
213
174
  end
214
175
  end
215
176
 
216
- ActiveRecord::Base.send :include, Polygallery::HasPolygallery
177
+ # ActiveRecord::Base.send :include, Polygallery::HasPolygallery
@@ -1,10 +1,8 @@
1
+ require 'polygallery'
2
+
1
3
  module Polygallery
2
4
  module HasPolyphotos
3
5
  extend ActiveSupport::Concern
4
-
5
- included do
6
- end
7
-
8
6
  module ClassMethods
9
7
  def has_polyphotos(title=nil, options={})
10
8
  attr_accessor :polygallery_options
@@ -20,13 +18,16 @@ module Polygallery
20
18
  attr_accessor :photos_attributes, :photos_built
21
19
 
22
20
  settings = defaults.deep_merge options
23
- init_associations settings
21
+ # init_associations settings
22
+ belongs_to :galleryable, polymorphic: true
23
+ # photos_name = settings[:association_names][:photos]
24
+ has_many :photos, settings[:associations][:photos].symbolize_keys
24
25
 
25
26
  after_initialize do
26
27
  self.polygallery_options ||= self.polygallery_settings
27
28
  self.initialize_polygallery
28
29
  end
29
- after_initialize :build_polygallery_photos, :if => :new_record?
30
+ after_initialize :build_polygallery_photos, :if => :new_record?
30
31
  before_validation :set_nested_attributes_to_correct_gallery
31
32
  before_validation :build_polygallery_photos, :unless => :photos_built? # , :on => :update
32
33
  before_validation :prune_empty_photos
@@ -35,10 +36,10 @@ module Polygallery
35
36
  end
36
37
 
37
38
  def polygallery_settings
38
- HasPolygallery::DEFAULTS
39
+ DEFAULT_SETTINGS
39
40
  end
40
41
 
41
- def init_associations(settings=HasPolygallery::DEFAULTS)
42
+ def init_associations(settings=DEFAULT_SETTINGS)
42
43
  belongs_to :galleryable, :polymorphic => true
43
44
  photos_name = settings[:association_names][:photos]
44
45
  has_many :photos, settings[:associations][:photos].symbolize_keys
@@ -77,8 +78,6 @@ module Polygallery
77
78
  photo_association.build(
78
79
  :polygallery_options => self.polygallery_settings,
79
80
  :galleryable => self.galleryable,
80
- :galleryable_id => self.galleryable_id,
81
- :galleryable_type => self.galleryable_type,
82
81
  :gallery_title => self.title ) unless photo_association.any?
83
82
  end
84
83
 
@@ -102,11 +101,11 @@ module Polygallery
102
101
  Object.const_get polygallery_photos_classname end
103
102
 
104
103
  def set_nested_attributes_to_correct_gallery
105
- # if self.photos_attributes.present? &&
106
- # self.polygallery_photos_name.to_s != 'photos'
107
- # self.send :"#{polygallery_photos_name.to_s}_attributes=", self.photos_attributes
108
- # self.photos_attributes = nil
109
- # end
104
+ if self.photos_attributes.present? &&
105
+ self.polygallery_photos_name.to_s != 'photos'
106
+ # self.send :"#{polygallery_photos_name.to_s}_attributes=", self.photos_attributes
107
+ # self.photos_attributes = nil
108
+ end
110
109
  end
111
110
 
112
111
  def build_polygallery_photos
@@ -149,10 +148,10 @@ module Polygallery
149
148
  def prune_empty_photos
150
149
  # puts "#{title} is pruning empty photos..."
151
150
  polygallery_photos.each {|pp|
152
- if pp.new_record? && !pp.photo.file?
153
- # TODO: find a way not to generate these photos in the first place!
151
+ if pp.new_record? && !pp.photo.file? && pp.photo_to_upload.nil?
154
152
  # puts 'Marking photo for destruction'
155
153
  pp.mark_for_destruction
154
+ polygallery_photos.delete pp
156
155
  end }
157
156
  end
158
157
 
@@ -163,8 +162,15 @@ module Polygallery
163
162
  photos.first || Photo.new
164
163
  end
165
164
 
165
+ def method_missing(m, *args, &block)
166
+ if m == :photos
167
+ self.initialize_polygallery
168
+ return send(m, *args, &block) if self.respond_to? m
169
+ Photo.where('1 = 0')
170
+ else super end
171
+ end
166
172
  end
167
173
  end
168
174
  end
169
175
 
170
- ActiveRecord::Base.send :include, Polygallery::HasPolyphotos
176
+ # ActiveRecord::Base.send :include, Polygallery::HasPolyphotos
@@ -0,0 +1,14 @@
1
+ require 'polygallery'
2
+ require 'polygallery/has_polygallery'
3
+ require 'polygallery/has_polyphotos'
4
+ require 'polygallery/acts_as_polyphoto'
5
+
6
+ module Polygallery
7
+ module ModelHelpers
8
+ extend ActiveSupport::Concern
9
+
10
+ include HasPolygallery
11
+ include HasPolyphotos
12
+ include ActsAsPolyphoto
13
+ end
14
+ end
@@ -1,32 +1,18 @@
1
- require 'polygallery/view_helpers'
1
+ require 'polygallery'
2
2
  require 'polygallery/glue'
3
3
 
4
4
  module Polygallery
5
5
  require 'rails'
6
-
7
6
  class Railtie < Rails::Railtie
8
- # initializer "polygallery.configure_rails_initialization" do |app|
9
- # app.middleware.use Railtie::
10
- # end
11
7
  initializer "polygallery.insert_into_active_record" do |app|
12
8
  ActiveSupport.on_load :active_record do
13
9
  Polygallery::Railtie.insert
14
10
  end
15
-
16
11
  if app.config.respond_to?(:polygallery_defaults)
17
12
  Polygallery::Gallery.default_options.merge!(app.config.polygallery_defaults)
18
13
  end
19
14
  end
20
- initializer "polygallery.view_helpers" do
21
- ActionView::Base.send :include, ViewHelpers
22
- end
23
- initializer 'polygallery.assets' do
24
- Rails.application.config.assets.precompile +=
25
- %w( polygallery/thumbnail-missing.jpg )
26
- end
27
- end
28
15
 
29
- class Railtie
30
16
  def self.insert
31
17
  if defined?(ActiveRecord)
32
18
  ActiveRecord::Base.send(:include, Polygallery::Glue)
@@ -0,0 +1,19 @@
1
+ require 'polygallery'
2
+
3
+ module Polygallery
4
+ module SimpleFormHelper
5
+
6
+ def self.simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
7
+ ( '<div class="polygallery-fields">' <<
8
+ fb.simple_fields_for(title, *args, &block) << '</div>' ).html_safe
9
+ end
10
+ def simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
11
+ new_block = block_given? ? block : ->(fb2) {
12
+ render partial: 'polygallery/galleries/simple_fields_for',
13
+ locals: { f: fb2 } }
14
+ Polygallery::SimpleFormHelper.simple_fields_for_polygallery(
15
+ fb, title, *args, &new_block)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'polygallery'
2
+
3
+ module Polygallery
4
+ module StrongParamsHelper
5
+ def self.polygallery_params(title=:gallery, photos_title=:photos)
6
+ {:"#{title}_attributes" => [:id, :title, :galleryable_id, :galleryable_type,
7
+ :_destroy, polyphoto_params(photos_title) ] }
8
+ end
9
+ def self.polyphoto_params(title=:photos)
10
+ {:"#{title}_attributes" => [:id, :photo, :title, :caption, :gallery_title,
11
+ :gallery_id,
12
+ :galleryable_id, :galleryable_type, :_destroy] }
13
+ end
14
+ def polygallery_params(title=:gallery, photos_title=:photos)
15
+ Polygallery::StrongParamsHelper.polygallery_params title, photos_title end
16
+ def polyphoto_params(title=:photos)
17
+ Polygallery::StrongParamsHelper.polyphoto_params title
18
+ end
19
+
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Polygallery
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -8,14 +8,5 @@ module Polygallery
8
8
  render :partial => 'polygallery/galleries/fields_for', :locals => {:f => f, :gallery => gallery, :options => options}
9
9
  end
10
10
 
11
- def simple_fields_for_polygallery(title, f, options={})
12
- options = {
13
- :label => true,
14
- :input_html => {}
15
- }.merge(options)
16
- gallery = f.object.send(title)
17
- render :partial => 'polygallery/galleries/simple_fields_for', :locals => {:f => f, :gallery => gallery, :options => options}
18
- end
19
-
20
11
  end
21
12
  end
data/lib/polygallery.rb CHANGED
@@ -1,8 +1,41 @@
1
- require "polygallery/engine"
2
- require "polygallery/has_polygallery"
3
- require "polygallery/has_polyphotos"
4
- require "polygallery/paperclip_integration"
5
- require "polygallery/railtie" if defined? Rails
1
+ require 'polygallery/engine'
2
+ require 'polygallery/paperclip_integration' # <-- Try removing this monstrosity
3
+ # require 'polygallery/railtie' if defined? Rails
6
4
 
7
5
  module Polygallery
6
+ DEFAULT_SETTINGS = {
7
+ associations: {
8
+ gallery: {
9
+ class_name: '::Polygallery::Gallery',
10
+ as: :galleryable,
11
+ dependent: :destroy
12
+ },
13
+ photos: {
14
+ class_name: '::Polygallery::Photo',
15
+ # before_add: :set_nest,
16
+ dependent: :destroy,
17
+ foreign_key: :gallery_id
18
+ }
19
+ },
20
+ association_names: {
21
+ gallery: :gallery,
22
+ photos: :photos
23
+ },
24
+ nested_attributes: {
25
+ gallery: { reject_if: :all_blank },
26
+ photos: {
27
+ allow_destroy: true,
28
+ reject_if: proc {|attributes|
29
+ !attributes.key?('id') && attributes['photo'].nil? } }
30
+ },
31
+ validates: {},
32
+ paperclip: {
33
+ styles: {medium: '300x300#', thumb: '100x100#'},
34
+ default_url: 'polygallery/thumbnail-missing.jpg'
35
+ },
36
+ paperclip_validations: {
37
+ content_type: /\Aimage\/.*\Z/,
38
+ presence: false
39
+ }
40
+ }
8
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polygallery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: byebug
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: paperclip
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -272,22 +286,17 @@ files:
272
286
  - MIT-LICENSE
273
287
  - README.rdoc
274
288
  - Rakefile
275
- - app/assets/javascripts/polygallery/application.js
276
- - app/assets/javascripts/polygallery/galleries.js
277
289
  - app/assets/javascripts/polygallery/init.js
278
- - app/assets/javascripts/polygallery/photos.js
279
290
  - app/assets/javascripts/polygallery/polygallery.js.coffee
280
291
  - app/assets/stylesheets/polygallery/application.css
281
292
  - app/assets/stylesheets/polygallery/galleries.css
282
293
  - app/assets/stylesheets/polygallery/photos.css
283
- - app/controllers/concerns/polygallery/strong_params.rb
284
294
  - app/controllers/polygallery/application_controller.rb
285
295
  - app/controllers/polygallery/galleries_controller.rb
286
296
  - app/controllers/polygallery/photos_controller.rb
287
297
  - app/helpers/polygallery/application_helper.rb
288
298
  - app/helpers/polygallery/galleries_helper.rb
289
299
  - app/helpers/polygallery/photos_helper.rb
290
- - app/models/concerns/polygallery/acts_as_polyphoto.rb
291
300
  - app/models/concerns/polygallery/customized_gallery.rb
292
301
  - app/models/concerns/polygallery/customized_photo.rb
293
302
  - app/models/polygallery/gallery.rb
@@ -305,7 +314,10 @@ files:
305
314
  - lib/generators/polygallery/install/templates/add_gallery_title.rb
306
315
  - lib/generators/polygallery/install/templates/polygallery_migration.rb
307
316
  - lib/polygallery.rb
317
+ - lib/polygallery/acts_as_polygallery.rb
318
+ - lib/polygallery/acts_as_polyphoto.rb
308
319
  - lib/polygallery/capybara_helpers.rb
320
+ - lib/polygallery/controller_helpers.rb
309
321
  - lib/polygallery/engine.rb
310
322
  - lib/polygallery/factories.rb
311
323
  - lib/polygallery/factories/polygallery/galleries.rb
@@ -313,8 +325,11 @@ files:
313
325
  - lib/polygallery/glue.rb
314
326
  - lib/polygallery/has_polygallery.rb
315
327
  - lib/polygallery/has_polyphotos.rb
328
+ - lib/polygallery/model_helpers.rb
316
329
  - lib/polygallery/paperclip_integration.rb
317
330
  - lib/polygallery/railtie.rb
331
+ - lib/polygallery/simple_form_helper.rb
332
+ - lib/polygallery/strong_params_helper.rb
318
333
  - lib/polygallery/validators.rb
319
334
  - lib/polygallery/validators/polygallery_presence_validator.rb
320
335
  - lib/polygallery/version.rb
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,19 +0,0 @@
1
- module Polygallery::StrongParams
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- end
6
-
7
- def self.polygallery_params(association='photos')
8
- [:id, :title, :galleryable_id, :galleryable_type,
9
- :_destroy, {:photos_attributes => polyphoto_params(association) } ]
10
- end
11
- def self.polyphoto_params(association='photos')
12
- [:id, :photo, :title, :caption, :gallery_title,
13
- :galleryable_id, :galleryable_type, :_destroy]
14
- end
15
- def polygallery_params(association='photos')
16
- self.class.polygallery_params association end
17
- def polyphoto_params(association='photos')
18
- self.class.polyphoto_params association end
19
- end