polygallery 0.1.4 → 0.1.6

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: 748c58237c3287c39ed71c22b4d610f9930d16fe
4
- data.tar.gz: 4679777b8785fb32c0e997c6083c441dffa80ba9
3
+ metadata.gz: d422469c1636c39daec91fdcc84c67df1972d4ea
4
+ data.tar.gz: 7a7322c270678788dab88181f1981423364d4540
5
5
  SHA512:
6
- metadata.gz: 778e7320a67042cd19d166f52c824002790aa3141061609069af9d1f2970993d3cef86623640a1b611a98df0f6b67b7019e65f652742afb4db525c8a0e138cb1
7
- data.tar.gz: c2d0c55787f5f5e3f2a60f83b28ab953d16e093cf89f743361f2e1da3074a6219c965e8d2e0c426b073877e06a3e2cb1d1ab546cfbbe106dfbccc6e08a667b39
6
+ metadata.gz: 11abda37d7563201ff480938f6b91737861edb72051fcc0489f2cd79f5b59cc77d8ca367a99d8b794d5246eb7339b29379937cb1f690e7f8a35c71ea44063108
7
+ data.tar.gz: da620e32ddb14c4225571e8c5d06d62f5d67ee9080fdcbed793d8952099269b62f7939f4bbdd97779c4083771712cfda1ae0dde028305e96086cf7ccc7c7b9fe
@@ -38,7 +38,7 @@ module Polygallery
38
38
  :validates => {},
39
39
  :paperclip => {
40
40
  :styles => {:medium => '300x300#', :thumb => '100x100#'},
41
- :default_url => ActionController::Base.helpers.image_path('polygallery/thumbnail-missing.png')
41
+ :default_url => 'polygallery/thumbnail-missing.jpg'
42
42
  },
43
43
  :paperclip_validations => {
44
44
  :content_type => /\Aimage\/.*\Z/,
@@ -94,9 +94,9 @@ module Polygallery
94
94
  .select{|a| a.foreign_key == 'galleryable_id'}.map(&:name)
95
95
  end
96
96
 
97
- def has_polygallery?(title=nil)
98
- return polygalleries.any? if title.nil?
99
- polygalleries.include?(title)
97
+ def has_polygallery?(gallery_title=nil)
98
+ return polygalleries.any? if gallery_title.nil?
99
+ polygalleries.include?(gallery_title)
100
100
  end
101
101
  end
102
102
 
@@ -109,9 +109,9 @@ module Polygallery
109
109
  .map(&:title)
110
110
  end
111
111
 
112
- def has_polygallery?(title=nil)
113
- return polygalleries.any? if title.nil?
114
- polygalleries.include?(title)
112
+ def has_polygallery?(gallery_title=nil)
113
+ return polygalleries.any? if gallery_title.nil?
114
+ polygalleries.include?(gallery_title)
115
115
  end
116
116
 
117
117
  def build_galleries
@@ -120,17 +120,30 @@ module Polygallery
120
120
  gallery_association = send pg
121
121
  next if gallery_association.present?
122
122
  gallery_settings = send :"#{pg.to_s}_settings"
123
- gallery_association ||= send :"build_#{pg.to_s}",
124
- :polygallery_options => gallery_settings
123
+ gallery_association = send(:"#{pg.to_s}=", send(:"build_#{pg.to_s}",
124
+ :polygallery_options => gallery_settings)) if gallery_association.nil?
125
125
  gallery_association.galleryable ||= self
126
126
  end
127
127
  end
128
128
 
129
129
  def build_first_photos
130
- build_galleries(&:build_first_photo)
131
130
  return unless self.class.has_polygallery?
132
131
  self.class.polygalleries.each {|pg| send(pg).build_first_photo }
133
132
  end
133
+
134
+ def first_photo
135
+ return unless self.class.has_polygallery?
136
+ first_p = nil
137
+ self.class.polygalleries.each do |pg|
138
+ gallery_settings = send :"#{pg.to_s}_settings"
139
+ ptos = send(gallery_settings[:association_names][:photos])
140
+ .select{|p| p.photo.file? }
141
+ next if ptos.empty?
142
+ first_p = ptos.first.photo
143
+ break
144
+ end
145
+ first_p || Photo.new.photo
146
+ end
134
147
  end
135
148
  end
136
149
  end
@@ -3,11 +3,12 @@ module Polygallery
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- attr_accessor :polygallery_options
7
6
  end
8
7
 
9
8
  module ClassMethods
10
9
  def has_polyphotos(title=nil, options={})
10
+ attr_accessor :polygallery_options
11
+
11
12
  defaults = self.polygallery_settings
12
13
  association_names = (options[:association_names].present? ?
13
14
  options : defaults)[:association_names]
@@ -46,7 +47,7 @@ module Polygallery
46
47
  # end
47
48
 
48
49
  def include_polygallery_settings(settings)
49
- @polygallery_settings = settings
50
+ @polygallery_settings = self.polygallery_options = settings
50
51
  self.initialize_polygallery
51
52
  end
52
53
 
@@ -1,3 +1,3 @@
1
1
  module Polygallery
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end