Sha256: d62a164198db475123429f23f954d36ce010e8a9d174b7bd4c6d6ee853f8d688

Contents?: true

Size: 1.01 KB

Versions: 22

Compression:

Stored size: 1.01 KB

Contents

module Alchemy
  class EssencePicture < ActiveRecord::Base

    attr_accessible(
      :caption,
      :title,
      :alt_tag,
      :link,
      :link_class_name,
      :link_title,
      :css_class,
      :link_target,
      :crop_from,
      :crop_size,
      :render_size,
      :picture_id
    )

    acts_as_essence(
      :ingredient_column => :picture,
      :preview_text_method => :name
    )

    belongs_to :picture
    before_save :fix_crop_values
    before_save :replace_newlines

  private

    def fix_crop_values
      %w(crop_from crop_size).each do |crop_value|
        write_attribute crop_value, normalize_crop_value(crop_value)
      end
    end

    def normalize_crop_value(crop_value)
      self.send(crop_value).to_s.split('x').map { |n| normalize_number(n) }.join('x')
    end

    def normalize_number(number)
      number = number.to_f.round
      number < 0 ? 0 : number
    end

    def replace_newlines
      return nil if caption.nil?
      caption.gsub!(/(\r\n|\r|\n)/, "<br/>")
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
alchemy_cms-2.6.3 app/models/alchemy/essence_picture.rb
alchemy_cms-2.6.2.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.6.2 app/models/alchemy/essence_picture.rb
alchemy_cms-2.6.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.6.0 app/models/alchemy/essence_picture.rb
alchemy_cms-2.6.0.rc5 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.3.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.3 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.2.2 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.2.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.2 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.0 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.0.rc3 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.0.b9 app/models/alchemy/essence_picture.rb
alchemy_cms-2.4.1 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.0.b5 app/models/alchemy/essence_picture.rb
alchemy_cms-2.5.0.b2 app/models/alchemy/essence_picture.rb
alchemy_cms-2.4.0 app/models/alchemy/essence_picture.rb
alchemy_cms-2.4.rc4 app/models/alchemy/essence_picture.rb