Class: PostAttachment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PostAttachment
- 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
- .configured_styles ⇒ Object
- .image?(content_type) ⇒ Boolean
- .thumbnail_names ⇒ Object
- .thumbnail_sizes ⇒ Object
Instance Method Summary collapse
- #basename ⇒ Object
- #extension ⇒ Object
- #filename ⇒ Object
- #icon ⇒ Object
- #image? ⇒ Boolean
- #thumbnail ⇒ Object
Class Method Details
.configured_styles ⇒ Object
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
9 10 11 |
# File 'app/models/post_attachment.rb', line 9 def image?(content_type) image_content_types.include?(content_type) end |
.thumbnail_names ⇒ Object
22 23 24 |
# File 'app/models/post_attachment.rb', line 22 def thumbnail_names thumbnail_sizes.keys end |
.thumbnail_sizes ⇒ Object
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
#basename ⇒ Object
58 59 60 |
# File 'app/models/post_attachment.rb', line 58 def basename File.basename(filename, ".*") if filename end |
#extension ⇒ Object
62 63 64 |
# File 'app/models/post_attachment.rb', line 62 def extension filename.split('.').last.downcase if filename end |
#filename ⇒ Object
54 55 56 |
# File 'app/models/post_attachment.rb', line 54 def filename file_file_name end |
#icon ⇒ Object
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
50 51 52 |
# File 'app/models/post_attachment.rb', line 50 def image? self.class.image?(file_content_type) end |
#thumbnail ⇒ Object
66 67 68 |
# File 'app/models/post_attachment.rb', line 66 def thumbnail file.url(:thumbnail) if image? end |