Class: Alchemy::EssencePicture

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Picture::Transformations
Defined in:
app/models/alchemy/essence_picture.rb

Instance Method Summary collapse

Methods included from Picture::Transformations

#can_be_cropped_to, #crop, #crop_size?, #default_mask, #image_size, #landscape_format?, #portrait_format?, #render_size?, #resize, #sizes_from_string, #square_format?, #thumbnail_size

Instance Method Details

#cropping_maskObject

A Hash of coordinates suitable for the graphical image cropper.



75
76
77
78
79
80
81
# File 'app/models/alchemy/essence_picture.rb', line 75

def cropping_mask
  return if crop_from.blank? || crop_size.blank?
  crop_from = point_from_string(read_attribute(:crop_from))
  crop_size = sizes_from_string(read_attribute(:crop_size))

  point_and_mask_to_points(crop_from, crop_size)
end

#picture_url(options = {}) ⇒ Object

The url to show the picture.

Takes all values like name and crop sizes (crop_from, crop_size from the build in graphical image cropper) and also adds the security token.

You typically want to set the size the picture should be resized to.

Example:

essence_picture.picture_url(size: '200x300', crop: true, format: 'gif')
# '/pictures/1/show/200x300/crop/cats.gif?sh=765rfghj'

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • size (String)

    The size the picture should be resized to.

  • format (String)

    The format the picture should be rendered in. Defaults to the image_output_format from the Alchemy::Config.

  • crop (Boolean)

    If set to true the picture will be cropped to fit the size value.



57
58
59
60
61
# File 'app/models/alchemy/essence_picture.rb', line 57

def picture_url(options = {})
  return if picture.nil?
  # routes.show_picture_path(picture_params(options))
  Dragonfly.app(:alchemy_pictures).remote_url_for content.essence.picture.image_file.send(:uid)
end

#preview_text(max = 30) ⇒ Object

The name of the picture used as preview text in element editor views.

Parameters:

  • max (Integer) (defaults to: 30)

    The maximum length of the text returned.



68
69
70
71
# File 'app/models/alchemy/essence_picture.rb', line 68

def preview_text(max = 30)
  return "" if picture.nil?
  picture.name.to_s[0..max-1]
end

#serialized_ingredientObject

Returns a serialized ingredient value for json api



84
85
86
# File 'app/models/alchemy/essence_picture.rb', line 84

def serialized_ingredient
  picture_url(content.settings)
end