Class: Bike::Img

Inherits:
File show all
Defined in:
lib/scalar/img.rb

Constant Summary collapse

DEFAULT_META =
{
  :width   => 120,
  :height  => 120,
  :options => ['png', 'jpg', 'jpeg', 'gif', 'tiff', 'bmp'],
}

Instance Attribute Summary

Attributes inherited from Field

#action, #result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from File

#body, #meta_path, #meta_persistent_name, #meta_persistent_sd, #meta_tmp_path

Methods inherited from Field

#[], #[]=, #create, #default_action, #delete, #empty?, #find_ancestor, #get, h, #inspect, instance, #item, #load, #load_default, #meta_admins, #meta_client, #meta_folder, #meta_full_name, #meta_group, #meta_name, #meta_owner, #meta_owners, #meta_roles, #meta_sd, #meta_short_name, #pending?, #permit?, #post, #update, #val, #valid?, #workflow

Methods included from I18n

_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=

Constructor Details

#initialize(meta = {}) ⇒ Img

Returns a new instance of Img.



23
24
25
26
# File 'lib/scalar/img.rb', line 23

def initialize(meta = {})
  meta[:crop] = true if meta[:tokens] && meta[:tokens].include?('crop')
  super
end

Class Method Details

.quick_magick?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/scalar/img.rb', line 19

def self.quick_magick?
  Object.const_defined? :QuickMagick
end

Instance Method Details

#commit(type = :temp) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/scalar/img.rb', line 45

def commit(type = :temp)
  super
  if type == :temp && @action == :delete
    @thumbnail = nil
  elsif type == :persistent && ps = my[:persistent_sd]
    case @action
      when :create, :update, nil
        ps.storage.store(
          "#{my[:persistent_name]}_small",
          @thumbnail,
          val['basename'][/\.([\w\.]+)$/, 1] || 'bin'
        ) if @thumbnail && valid?
    end
  end
end

#errorsObject



37
38
39
40
41
42
43
# File 'lib/scalar/img.rb', line 37

def errors
  if @error_thumbnail
    [_('wrong file type: should be %{types}') % {:types => my[:options].join('/')}]
  else
    super
  end
end

#thumbnailObject



28
29
30
31
32
33
34
35
# File 'lib/scalar/img.rb', line 28

def thumbnail
  raise Bike::Error::Forbidden unless permit? :read

  if ps = my[:persistent_sd]
    @thumbnail ||= ps.storage.val "#{my[:persistent_name]}_small"
  end
  @thumbnail || body
end