Sha256: f02fbc21852485ae19954b194315baaeaa91ec8bc12b551ac42360b02e538fda

Contents?: true

Size: 1.36 KB

Versions: 16

Compression:

Stored size: 1.36 KB

Contents

class Image < ActiveRecord::Base

  has_many :pages

  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :path_prefix => 'public/system/images',
                 :processor => 'Rmagick',
                 :thumbnails => ((((thumbnails = RefinerySetting.find_or_set(:image_thumbnails, {})).is_a?(Hash) ? thumbnails : (RefinerySetting[:image_thumbnails] = {}))) rescue {}),
                 :max_size => 5.megabytes

  acts_as_indexed :fields => [:title]

  def validate
   errors.add_to_base("You must choose a file to upload") unless self.filename

   unless self.filename.nil?
     [:size].each do |attr_name|
       enum = attachment_options[attr_name]

       errors.add_to_base("Files should be smaller than 50 MB in size") unless enum.nil? || enum.include?(send(attr_name))
     end
   end

  end

  def title
    self.filename.gsub(/\.\w+$/, '').titleize
  end

  def self.per_page(dialog = false)
    size = (dialog ? 18 : 20)
  end

  def self.last_page(images, dialog=false)
    page = unless images.size <= self.per_page(dialog)
      (images.size / self.per_page(dialog).to_f).ceil
    else
      nil # this must be nil, it can't be 0 as there apparently isn't a 0th page.
    end
  end

  def self.thumbnails
    find(:all, :conditions => "parent_id not null")
  end

  def self.originals
    find_all_by_parent_id(nil)
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
refinerycms-0.9.5.29 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.28 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.27 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.26 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.25 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.24 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.23 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.22 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.21 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.20 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.19 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.18 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.17 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.16 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.15 vendor/plugins/images/app/models/image.rb
refinerycms-0.9.5.14 vendor/plugins/images/app/models/image.rb