Class: PostAttachment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/post_attachment.rb

Constant Summary collapse

@@image_content_types =
['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configured_stylesObject



17
18
19
20
# File 'app/models/post_attachment.rb', line 17

def configured_styles
  styles = Radiant::Config["assets.additional_thumbnails"].gsub(/\s+/,'').split(',') if Radiant::Config["assets.additional_thumbnails"]
  styles.collect{|s| s.split('=')}.inject({}) {|ha, (k, v)| ha[k.to_sym] = v; ha}
end

.image?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/models/post_attachment.rb', line 9

def image?(content_type)
  image_content_types.include?(content_type)
end

.thumbnail_namesObject



22
23
24
# File 'app/models/post_attachment.rb', line 22

def thumbnail_names
  thumbnail_sizes.keys
end

.thumbnail_sizesObject



13
14
15
# File 'app/models/post_attachment.rb', line 13

def thumbnail_sizes
  { :icon => ['24x24#', :png], :thumbnail => ['100x100>', :png] }.merge(configured_styles)
end

Instance Method Details

#basenameObject



58
59
60
# File 'app/models/post_attachment.rb', line 58

def basename
  File.basename(filename, ".*") if filename
end

#extensionObject



62
63
64
# File 'app/models/post_attachment.rb', line 62

def extension
  filename.split('.').last.downcase if filename
end

#filenameObject



54
55
56
# File 'app/models/post_attachment.rb', line 54

def filename
  file_file_name
end

#iconObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/post_attachment.rb', line 70

def icon
  iconpath = Radiant::Config.table_exists? && Radiant::Config['forum.icon_path'] ? Radiant::Config['forum.icon_path'] : '/images/forum/icons'
  if image?
    file.url(:icon)
  else
    icon = File.join(RAILS_ROOT, 'public', iconpath, "#{extension}.png")
    if File.exists? icon
      "#{iconpath}/#{extension}.png"
    else
      "#{iconpath}/attachment.png"
    end
  end
end

#image?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/post_attachment.rb', line 50

def image?
  self.class.image?(file_content_type)
end

#thumbnailObject



66
67
68
# File 'app/models/post_attachment.rb', line 66

def thumbnail
  file.url(:thumbnail) if image?
end