refinerycms-image_rotators 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ class Image < ActiveRecord::Base
2
+
3
+ has_many :image_rotator_images, :dependent => :destroy
4
+
5
+ # What is the max image size a user can upload
6
+ MAX_SIZE_IN_MB = 20
7
+
8
+ image_accessor :image
9
+
10
+ validates :image, :presence => { :message => ::I18n.t('image_specify_for_upload') },
11
+ :length => { :maximum => MAX_SIZE_IN_MB.megabytes,
12
+ :message => ::I18n.t('image_should_be_smaller_than_max_image_size',
13
+ :max_image_size => MAX_SIZE_IN_MB.megabytes) }
14
+ validates_property :mime_type, :of => :image, :in => %w(image/jpeg image/png image/gif),
15
+ :message => ::I18n.t('image_must_be_these_formats')
16
+
17
+ # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
18
+ acts_as_indexed :fields => [:title]
19
+
20
+ # when a dialog pops up with images, how many images per page should there be
21
+ PAGES_PER_DIALOG = 18
22
+
23
+ # when a dialog pops up with images, but that dialog has image resize options
24
+ # how many images per page should there be
25
+ PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS = 12
26
+
27
+ # when listing images out in the admin area, how many images should show per page
28
+ PAGES_PER_ADMIN_INDEX = 20
29
+
30
+ delegate :size, :mime_type, :url, :width, :height, :to => :image
31
+
32
+ class << self
33
+ # How many images per page should be displayed?
34
+ def per_page(dialog = false, has_size_options = false)
35
+ if dialog
36
+ unless has_size_options
37
+ PAGES_PER_DIALOG
38
+ else
39
+ PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS
40
+ end
41
+ else
42
+ PAGES_PER_ADMIN_INDEX
43
+ end
44
+ end
45
+ end
46
+
47
+ # Get a thumbnail job object given a geometry.
48
+ def thumbnail(geometry = nil)
49
+ if geometry.is_a?(Symbol)
50
+ if (sizes = RefinerySetting.find_or_set(:image_thumbnails, {})) and sizes.keys.include?(geometry)
51
+ geometry = sizes[geometry].presence
52
+ end
53
+ end
54
+
55
+ if geometry.present? && !geometry.is_a?(Symbol)
56
+ self.image.thumb(geometry)
57
+ else
58
+ self.image
59
+ end
60
+ end
61
+
62
+ # Returns a titleized version of the filename
63
+ # my_file.jpg returns My File
64
+ def title
65
+ CGI::unescape(self.image_name).gsub(/\.\w+$/, '').titleize
66
+ end
67
+
68
+ end
@@ -1,6 +1,6 @@
1
1
  class ImageRotator < ActiveRecord::Base
2
2
 
3
- has_many :images, :class_name => 'ImageRotatorImage'
3
+ has_many :images, :class_name => 'ImageRotatorImage', :dependent => :destroy
4
4
 
5
5
  validates :title, :presence => true
6
6
  validates :height, :presence => true
@@ -1,5 +1,5 @@
1
1
  class ImageRotatorImage < ActiveRecord::Base
2
-
2
+
3
3
  belongs_to :image_rotator
4
4
  belongs_to :image
5
5
 
@@ -1,7 +1,7 @@
1
1
  module Refinery
2
2
  module ImageRotators
3
3
  def self.version
4
- %{0.1.2}
4
+ %{0.1.3}
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-image_rotators
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jacob Swanner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-07 00:00:00 -05:00
18
+ date: 2011-03-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,6 +30,7 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - app/controllers/admin/image_rotator_images_controller.rb
32
32
  - app/controllers/admin/image_rotators_controller.rb
33
+ - app/models/image.rb
33
34
  - app/models/image_rotator.rb
34
35
  - app/models/image_rotator_image.rb
35
36
  - app/views/admin/image_rotator_images/_form.html.erb