Class: Runo::Img

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

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 Runo::Error::Forbidden unless permit? :read

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